Skip to content

Commit

Permalink
add streamlit cloud approach to deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
dayesouza committed Nov 7, 2024
1 parent ae372ea commit ff47d0c
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 22 deletions.
127 changes: 114 additions & 13 deletions DEPLOYING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,89 @@
# Deploying the app

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.

## Optional requirement for Streamlit Cloud

- A forked GitHub repository:
- Fork the repository to create your own instance with custom modifications. Ensure you keep your repository updated with the main repository to incorporate new code.
- You need to have a [github account](https://github.com)
- Alternatively, you can use the main repository directly, which will automatically receive updates.

## 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}` or `[microsoft/intelligence-toolkit](https://github.com/microsoft/intelligence-toolkit)`
- **Branch:** `master`
- **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:

- *Minimum disk space*: 8GB
Expand Down Expand Up @@ -87,7 +171,7 @@ You can modify the code and deploy the container, or use our default container h

`<az_webapp_name>.azurewebsites.net`

## AWS
# AWS

Wait for step 1 to be set as complete before starting step 2. The whole process will take up to 20 minutes.

Expand All @@ -105,26 +189,43 @@ Wait for step 1 to be set as complete before starting step 2. The whole process

Once step 2 it's complete, in the output tab, you'll see the deployed URL.

**Note: This code doesn't have auth, so this URL will be open to the internet.**

## Environment configuration

`MODE: CLOUD` to hide Settings page so users can't change configuration that would affect other users experiences.
To effectively manage user access and configuration settings in your app's deployment environment, here are some key parameters and steps for setting up your environment configuration. This guide covers how to handle these settings in Streamlit Cloud, Azure, and AWS deployments.

## Environment Configuration

- **Hiding the Settings Page**

Use `HIDE_SETTINGS: TRUE` to conceal the Settings page. This prevents users from altering configurations that could impact the experience for other users.

- **OpenAI API Key**

Set `OPENAI_API_KEY="your-key"` to ensure secure access to OpenAI services. This key allows interaction with OpenAI's API while keeping it confidential.

- **Authentication**

Enable `AUTH_ENABLED: TRUE` to restrict app access to authorized users with credentials defined in a `.secrets.toml` file under the `.streamlit` directory:

```toml
[passwords]
user_test = "user123"
...
```

`AUTH_ENABLED: TRUE` if you would like to limit access into the app by user and password defined in a .secrets.toml file inside .streamlit:
### Inserting the `secrets.toml` file into Web App Deployments (Azure or AWS)

```
[passwords]
user_test = "user123"
...
```
When deploying your app on Azure or AWS, you may need to configure user credentials as environment variables. Here's how you can accomplish this:

Inserting secrets.toml file to the web app:
- **User Credentials Environment Variable**

Add a value of user=password separating each user by `;` to your web app environment.
Add credentials in the format `user=password`, separated by semicolons (`;`), to your web app's environment variables:

`USER_CREDENTIALS="user1=pass1;user2=pass2"`
```plaintext
USER_CREDENTIALS="user1=pass1;user2=pass2"
```

This setup ensures secure handling of user authentication and sensitive configurations across different deployment platforms. By using these configurations, you can maintain control over user access and protect essential settings.



5 changes: 2 additions & 3 deletions app/Home.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import os.path

import streamlit as st

import app.util.mermaid as mermaid
from app.components.app_loader import load_multipage_app
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))
Expand Down
11 changes: 5 additions & 6 deletions app/components/app_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
#
import os

import components.app_mode as am
import components.app_user as au
import streamlit as st
from components.app_auth import check_password, load_passwords
from javascript.styles import add_styles
from streamlit.source_util import (
_on_pages_changed,
get_pages,
)

import app.components.app_mode as am
import app.components.app_user as au
from app.components.app_auth import check_password, load_passwords
from app.javascript.styles import add_styles


def load_multipage_app(sv=None):
if os.getenv("AUTH_ENABLED") == "TRUE":
load_passwords()
check_password()
if os.getenv("MODE") == "CLOUD":
if os.getenv("HIDE_SETTINGS") == "TRUE":
current_pages = get_pages("Home.py")

for key, value in current_pages.items():
Expand Down

0 comments on commit ff47d0c

Please sign in to comment.