A sample demonstrating how to deploy a streamlit-chatbot (LLM-powered) User Interface in Azure for demo purposes. This sample is in python and uses Streamlit + Azure Container Registry (ACR) + Azure Web App to deploy a chat interface.
- Azure CLI install instructions here
- Azure web app
- Azure Container Registry
- https://docs.streamlit.io/knowledge-base/tutorials/build-conversational-apps
- https://towardsdatascience.com/deploying-a-streamlit-web-app-with-azure-app-service-1f09a2159743
.
├── Dockerfile
├── README.md
├── environment.yml
└── streamlit_app
├── config.yaml
├── images
├── llm_bot.py
├── main.py
└── requirements.txt
- This sample can be run locally (without the need for containerization) or as a Docker container. To deploy to Azure, we build the container remotely using ACR and deploy using Web app.
- The streamlit app is defined in a folder
streamlit_app/
main.py
is the main access point and contains the front-endllm_bot.py
contains the chatbot response logic.config.yml
containes all configurations such as title, logos etc.
Dockerfile
andenvironment.yml
define how the container should be built
The sample can be run locally OR deployed to Azure web app as a Docker container.
-
To run the streamlit app locally:
- In a terminal
streamlit run ./streamlit_app/main.py --server.port 8000
- open a web browser at
localhost:8000
- In a terminal
-
To deploy to Azure web app as a Docker container
- Optional if already setup: Create the ACR and web-app services. Note: any of the
<ACR-name>, <RG-name>, etc. are arbitrarily defined
- Ensure you are creating your services on the correct subscription
az account list --output table
to list all subscriptions available to youaz account show --output table
to show which subscription is currently set toaz account set --subscription "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
to set a subsrciption using a subscription-id
- Create a container registry
az acr create --name <ACR-NAME> --resource-group <RG-NAME> --sku basic --admin-enabled true
- Create a web app service plan
az appservice plan create --resource-group <RG-NAME> --name <APP-SERVICE-PLAN-NAME> --location eastus --is-linux --sku B1
(note: B1 sku is needed for websockets - required by streamlit)
- Ensure you are creating your services on the correct subscription
- Build the docker container remotely (this will upload and build the container in your ACR service)
az acr build --registry <ACR-NAME> --resource-group <RG-NAME> --image bot .
- Create a web app using the built container
az webapp create --resource-group <RG-NAME> --plan <APP-SERVICE-PLAN-NAME> --name <BOT-WEBAPP-NAME> -i <ACR-NAME>.azurecr.io/bot:latest
- Configure your web app to listen to port 8000 and set a longer container_start_time_limit
az webapp config appsettings set --resource-group <RG-NAME> --name <BOT-WEBAPP-NAME> --settings WEBSITES_PORT=8000 WEBSITES_CONTAINER_START_TIME_LIMIT=1800
- Open a browser at
<BOT-WEBAPP-NAME>.azurewebsites.net
(note: it may take a few minutes to load the first time the container is started)
- Optional if already setup: Create the ACR and web-app services. Note: any of the
-
Optional: Build and run Docker container locally (requires docker installed locally)
- build the docker container
docker build -t bot:v1 .
- run the docker container locally
docker run --rm -p 8000:8000 bot:v1
- open a web browser and type
localhost:8000
- build the docker container
In order to redeploy the bot, all you need to do is rebuild a container on ACR, and recreate the web app (you can reuse the same webapp previously created)
- Re-Build the docker container remotely (this will upload and build the container in your ACR service)
az acr build --registry <ACR-NAME> --resource-group <RG-NAME> --image bot .
- Re-create a web app
az webapp create -g <RG-NAME> -p <APP-SERVICE-PLAN-NAME> -n <BOT-WEBAPP-NAME> -i <ACR-NAME>.azurecr.io/bot:latest
- Container logs can be handy fro troubleshooting, link on how to access these in the web app on portal.azure.com (look for
log stream on the left
)