Skip to content

Commit

Permalink
add azure deploy to marketplace files (#83)
Browse files Browse the repository at this point in the history
* add terraform files

* fix gitignore and files

* terraform script

* fix terraform script

* fix terraform script

* fix terraform script

* fix terraform script

* fix terraform script

* fix terraform script

* fix main tf

* fix main tf

* fix main tf

* fix main tf

* fix main tf

* fix main tf

* fix main tf

* fix main tf

* fix main tf

* fix sh

* fix main tf

* fix main tf

* fix main tf

* fix main tf

* fix main tf

* fix main tf

* add example bicep

* fix bicep

* add latest templates ARM

* add openai instructions

* add app reg on readme

* fix

* add warning for version update

* fix authDisabled and plan

* fix

* fix version

* add tf file back

* fix gitgnore

* fix

* fix embedding default

* change default models

* fix template
  • Loading branch information
dayesouza authored Dec 10, 2024
1 parent d666a16 commit 0ca4b5a
Show file tree
Hide file tree
Showing 13 changed files with 549 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ app/wkhtmltox/*.exe
**/studio_tests/
.venv

**/dist/*
**/dist/*
68 changes: 0 additions & 68 deletions DEPLOYING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,19 @@

Deploying your app effectively is crucial for making it accessible to users. We present three robust options that cater to different requirements and preferences, whether you're looking for simplicity, scalability, or specific infrastructure.

- **Using Streamlit Cloud:** Ideal for those who prefer a straightforward and cost-effective deployment solution. Streamlit Cloud is perfect for quickly deploying Streamlit apps with minimal setup and no need for managing infrastructure.

- **Using Azure:** A powerful option for those who are already integrated into the Microsoft ecosystem or need advanced cloud services. Azure offers robust performance, scalability, and a suite of tools that are beneficial for apps requiring Microsoft-specific integrations or high availability.

- **Using AWS:** Known for its versatility and comprehensive cloud solutions, AWS is suitable for developers seeking a highly scalable and flexible deployment environment. It is apt for those with diverse app requirements and offers a range of services, from simple hosting to complex machine learning models.

Each of these options has its own strengths, and your choice will depend on the specific needs and constraints of your project. The following sections provide detailed guides on deploying your app using each of these platforms.


# Requirements for the app

To deploy your app, you will need:

1. An active OpenAI account ([create here](https://platform.openai.com/login)).
2. An OpenAI API key ([create here](https://platform.openai.com/account/api-keys)).

# Streamlit Cloud
This guide will walk you through deploying our app that uses [Streamlit](https://streamlit.io/), a Python package for building web apps. You can host your Streamlit apps for free with [Streamlit Community Cloud](https://streamlit.io/cloud).

## Security:

Streamlit prioritizes security by hosting data in secure cloud facilities and using encryption for data protection. Permission management follows GitHub rules, and regular vulnerability scans ensure the platform remains secure and up to date.

[Read more](https://docs.streamlit.io/deploy/streamlit-community-cloud/get-started/trust-and-security)

## Resource Limits

While Streamlit Community Cloud is free to use, it has resource limits that apply to all users. Exceeding these limits may result in throttling or app nonfunctionality. As of February 2024, the approximate limits are:

- **CPU:** 0.078 cores minimum, 2 cores maximum
- **Memory:** 690MB minimum, 2.7GB maximum
- **Storage:** No minimum, 50GB maximum

For optimal performance, especially with high concurrent usage, a higher allocation of CPU and memory may be beneficial.

[Read more](https://docs.streamlit.io/deploy/streamlit-community-cloud/manage-your-app#app-resources-and-limits)


## Increased Resources for NGOs

If you're part of an NGO, you might be eligible for increased resources by applying [here](https://info.snowflake.com/streamlit-resource-increase-request.html). Eligible apps often serve educational institutions, are part of open-source projects, or provide societal benefits. For-profit companies are generally not eligible.

## Requirement for Streamlit Cloud

- A [github account](https://github.com)
- A Forked GitHub repository:
- Fork [github.com/intelligence-toolkit](https://github.com/microsoft/intelligence-toolkit)
- Ensure you keep your repository updated with the main repository to incorporate new code and bug fixes.


## Deployment Steps

1. **Streamlit Setup:**
- [Create or sign in to your Streamlit account](https://share.streamlit.io/signup).
- Click on `Create an app` in the top right corner.
- Choose to deploy a public app from GitHub and configure it with the following:

- **Repository:** `{your_forked_one}`
- **Branch:** `main`
- **Main file path:** `app/Home.py`
- **App URL (optional):** Customize the URL for accessing your app.

2. **Advanced Settings:**
- Add the following secrets:
```plaintext
OPENAI_API_KEY="your-key"
HIDE_SETTINGS="TRUE" # Hides settings page to prevent changes affecting all users.
AUTH_ENABLED="TRUE" # Allows access only to authorized users.
[passwords]
"username" = "user_pwd"
"username2" = "user_pwd2"
...
```
3. **Deploy:**
- After setting up, click deploy. The deployment process takes a few minutes, and your app will be ready for access.
# Azure

#### Recommended configuration:
Expand Down
4 changes: 2 additions & 2 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ You can configure your OpenAI access when running the app via `Settings page`, o

#### Default values:
```
OPENAI_API_MODEL="gpt-4o"
OPENAI_API_MODEL="gpt-4o-mini"
OPENAI_TYPE="OpenAI" ## Other option available: Azure OpenAI
AZURE_AUTH_TYPE="Azure Key" # if OPENAI_TYPE==Azure OpenAI
DEFAULT_EMBEDDING_MODEL = "text-embedding-ada-002"
DEFAULT_EMBEDDING_MODEL = "text-embedding-3-small"
```

### OpenAI
Expand Down
60 changes: 60 additions & 0 deletions OPENAI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# OpenAI or Azure OpenAI Instance
Before you can deploy the application, you need to have an OpenAI or Azure OpenAI instance. This instance will provide the AI capabilities required by the application. Below are the steps to create an OpenAI or Azure OpenAI instance.

## Creating an OpenAI Instance
See pricing details [here](https://openai.com/api/pricing/)
1. **Sign Up for OpenAI**:
- Go to the [OpenAI website](https://platform.openai.com/login/).
- Login or sign in (you can use your ChatGPT account)
- You will need a phone number to confirm your account.

2. **Create the project**
- Click on Create a new project.
- Give it an identifiable name and click create.

3. **Add billing details**
- On the top bar on the right, click on your profile.
- Click on `Billing` on the left panel.
- Add your payment details.

4. **Get API Key**:
- On the top bar on the right, click on your profile.
- Click on `API keys` on the left panel.
- Click on `+ Create new secret key` on the top right.
- Give it an identifiable name and select the project you created.
- Click `Create secret key`.
- Copy your key and store it safely. It won't show again and if lost you'll need to create a new one.
- Use these to configure your access when deploying intelligence-toolkit app or using the `Settings` page.




## Creating an Azure OpenAI Instance
See pricing details [here](https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/)

1. **Log in to the Azure portal**:
- Go to the [Azure portal](https://portal.azure.com).
- If you don't have an account, click on "Create one" and follow the steps to set up your account.

2. **Create the resource**:
- Click on "Create a resource" and search for "Azure OpenAI".
- Select "Azure OpenAI Service" and click "Create".
- Fill in the required details (subscription, resource group, region, etc.).
- Click next until the Review + submit step.
- If validation passes, click create.

3. **Deploy the models**:
- Go to the resource page.
- Click on `Go to Azure AI Foundry portal`
- Click on `Deployments` on the left panel.
- Create the AI model
- Click on `Deploy model` and `Deploy base model`.
- Choose `gpt-4o-mini` then `Confirm` and `Deploy`
- Create the embedding model
- Click on `Deploy model` and `Deploy base model`.
- Choose `text-embedding-3-small` then `Confirm` and `Deploy`

4. **Get the Azure OpenAI key**:
- In the resource page on Azure portal, go to "Keys and Endpoint" section.
- Copy one of the keys (KEY 1 or KEY 2) and Endpoint URL.
- Use these to configure your access when deploying intelligence-toolkit app or using the `Settings` page.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,19 @@ All use of Intelligence Toolkit should be consistent with this documentation. In

## Getting Started

You can start using the Intelligence Toolkit as either a web application (with a tool called Docker) or a Python package (via PyPI). Choose one of the options below based on your needs.
You can start using the Intelligence Toolkit as either a web application (in Azure or locally with a tool called Docker) or a Python package (via PyPI). Choose one of the options below based on your needs.

**Option 1: Using Intelligence Toolkit in Azure**
### NGOs

Non-profit organizations can apply for an annual Azure credit grant of $2,000, which can be used to set up and run an instance of the intelligence-toolkit app for your organization.

[Read more about eligibility and registration here](https://www.microsoft.com/en-us/nonprofits/azure)

[See instructions](./deploy/azure/README.md) on how to.

**Option 1: Using Intelligence Toolkit as a Web Application (via Docker)**

**Option 2: Using Intelligence Toolkit as a Web Application (via Docker)**

To use the Intelligence Toolkit as a web application, you can download and run it using Docker.

Expand Down Expand Up @@ -187,7 +197,7 @@ You can access the `Settings` page on the left sidebar when running the applicat
- For Azure OpenAI, you will need an active Azure account ([create here](https://portal.azure.com/)), endpoint, key and version for the AI Service ([create here](https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/OpenAI)).


**Option 2: Using Intelligence Toolkit as a Python Package (via PyPI)**
**Option 3: Using Intelligence Toolkit as a Python Package (via PyPI)**

If you prefer to use Intelligence Toolkit as a Python package, install it directly from PyPI:

Expand All @@ -206,12 +216,6 @@ If you have any questions or need further assistance, you can reach out to the p

<hr>

### NGOs

Non-profit organizations can apply for an annual Azure credit grant of $2,000, which can be used to set up and run an instance of the intelligence-toolkit app for your organization.

[Read more about eligibility and registration here](https://www.microsoft.com/en-us/nonprofits/azure)

## Trademarks

- This project may contain trademarks or logos for projects, products, or services.
Expand Down
17 changes: 16 additions & 1 deletion app/Home.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
# Copyright (c) 2024 Microsoft Corporation. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project.
#
import importlib.metadata
import inspect
import os
import os.path

import requests
import streamlit as st
import util.mermaid as mermaid
from components.app_loader import load_multipage_app

filename = inspect.getframeinfo(inspect.currentframe()).filename
path = os.path.dirname(os.path.abspath(filename))


def get_readme_and_mermaid():
file_path = os.path.join(path, "README.md")
if not os.path.exists(file_path):
Expand Down Expand Up @@ -60,6 +61,20 @@ def main():
page_title="Intelligence Toolkit | Home",
)

version = importlib.metadata.version("intelligence-toolkit")
st.sidebar.markdown(f"Version: {version}")

url = "https://raw.githubusercontent.com/microsoft/intelligence-toolkit/refs/heads/main/pyproject.toml"
response = requests.get(url)
if response.status_code == 200:
lines = response.text.splitlines()
if len(lines) >= 3 and lines[2].startswith("version ="):
file_version = lines[2].split("=")[1].strip().strip('"')
if file_version > version:
st.sidebar.warning(
f"There is a new version of Intelligence Toolkit available: {file_version}. Please update your installation."
)

load_multipage_app()
transparency_faq, mermaid_text = get_readme_and_mermaid()

Expand Down
6 changes: 3 additions & 3 deletions app/util/ui_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,17 +810,17 @@ def check_ai_configuration(enforce_structured_output=False):
st.warning("Please set your OpenAI model in the Settings page.")

list_enforce_structured_output = [
"gpt-4o",
"gpt-4o-2024-08-06",
"gpt-4o-mini",
"gpt-4o-mini-2024-07-18",
"gpt-4o",
"gpt-4o-2024-08-06",
]
if (
enforce_structured_output
and ai_configuration.model not in list_enforce_structured_output
):
st.warning(
"Your current OpenAI model does not support this workflow. Please use the Settings page to use `gpt-4o` or `gpt-4o-mini` as OpenAI Deployment Name."
"Your current OpenAI model does not support this workflow. Please use the Settings page to use `gpt-4o-mini` or `gpt-4o` as OpenAI Deployment Name."
)


Expand Down
81 changes: 81 additions & 0 deletions deploy/azure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Deploying the App Using Azure Marketplace
This guide will help you deploy your application using Azure Marketplace, even if you're not a technical expert.

### Prerequisites
Before you start, make sure you have the following:

1. **Azure Subscription**: An active Azure subscription.
1. **OpenAI or Azure OpenAI instance**: This will provide the AI capabilities required by the application. If you don't have one, you can find [instructions here](../../OPENAI.md)
2. **Azure Account**: At minimum `Contributor` role assignment to deploy the resources in your Azure subscription.

### Steps to Deploy the App

It is recommended that you use Entra ID for authentication.

#### Creating an app registration for website authentication

- Open your web browser and go to [Microsoft Entra admin center](https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade)
- On the left panel click on `Applications` then `App registrations`
- Click on `+ New registration`.
- **Give it an identifiable name**
- **Supported account types**:
- Accounts in this organizational directory only (Microsoft only - Single tenant)
- **Redirect URI**:
- Select `Web` as platform and in the URL insert the following URL, being `[webAppName]` the name you'll give to the app on the next steps:
- `https://[webAppName].azurewebsites.net/.auth/login/aad/callback`
- Click on `Register`
- Copy the value of `Application (client) ID` to be used when creating the app in the next steps.

#### Deploy
See details on pricing [here](https://azure.microsoft.com/en-us/pricing/details/app-service/linux/) (We default to `Premium v3 P0v3` Plan)

1. **Go to Azure Marketplace**:
- Open your web browser and go to [Azure portal](https://portal.azure.com), search in the top bar for `Marketplace`.
- If you're not logged in, you may need to log in to your Azure account.
- Use the search bar to find the `Intelligence Toolkit` application.

2. **Select the Application**:
- Click on the application from the search results to open its details page.

3. **Click "Create"**:
- Click the "Create" button with Plan `Web App` selected to start the deployment process.

4. **Configure Deployment Settings**:
- You will be redirected to the [Azure portal](https://portal.azure.com) to set up the deployment.
- Fill in the required information:
- **Subscription**: Choose your Azure subscription.
- **Resource Group**: Select an existing group or create a new one.
- **Region**: Choose the region where you want to deploy the app (the closer to y ou, the better).
- **Web App Name**: Enter a unique name for your web app.
- This will create the URl you'll access:
`webappname`.azurewebsites.net
- **Service Principal Type**:
- To create a new authentication app, leave as `Create New`
- Click change Selection to change its name or leave it as the default.
- **AI Settings**:
- This will configure how the app will access an AI instance.
- **AI Type**:
- OpenAI or Azure OpenAI
- **Use Managed Identity**:
- Check this if type is Azure OpenAI and you don't have a key, but the user accessing the app have permission to it.
- **Endpoint**:
- If Azure OpenAI, insert the endpoint for it.
- **Key**:
- Only if Managed Identity is not checked, insert your OpenAI or Azure OpenAI key here.
- **Tags** (Optional): Add any tags you want to use to organize your resources.

5. **Review and Create**:
- Review the settings you entered to make sure everything is correct.
- Click the "Review + create" button to validate the settings.
- Once validation is complete, click the "Create" button to start the deployment.

6. **Monitor Deployment**:
- The deployment process will begin, and you can watch its progress in the Azure portal.
- When the deployment is finished, you will get a notification.

7. **Access the Deployed Application**:
- Go to the resource group where the application was deployed.
- Find the web application resource and click on it to open its details page.
- It takes a few minutes for the application to be ready. Wait about 5-10 and then use the provided URL (`webappname`.azurewebsites.net) to access your deployed application.

By following these steps, you can successfully deploy your application using Azure Marketplace.
Loading

0 comments on commit 0ca4b5a

Please sign in to comment.