Home NewsX Deploy Streamlit on Azure Web App

Deploy Streamlit on Azure Web App

by info.odysseyx@gmail.com
0 comment 11 views


Streamlit is an open source app framework that allows you to create data-driven web applications with minimal coding. It’s especially popular for machine learning and AI-related projects because it allows developers to easily create interactive dashboards directly from Python scripts.

this tutorial Walks you through the process of deploying a Streamlit application locally and to an Azure web app, including considerations for memory usage during deployment.

index:

  • Hosted in a development environment
  • Hosted on Azure Web App
  • Module and memory usage
  • References

Hosted in a development environment

To run a Streamlit application in your local development environment, follow these steps:

Step 1:

Open an empty folder using VSCode. Launch a terminal and enter the following command to create a Python virtual environment and switch the current session to this environment.

theringe_0-1729576369858.png

windows

python -m venv .venv
.\.venv\Scripts\Activate.ps1

linux

python -m venv .venv
source .venv/Scripts/activate

Step 2:

Enter the pip command to install streamlit and create a file called “app.py”. Run another command to start the local server hosting your project. You can then visit the project page in your browser. http://127.0.0.1:8501.

# Install Streamlit
pip install streamlit
# Launch server after app.py has been created
python -m streamlit run app.py

theringe_1-1729576675213.png

Hosted on Azure Web App

To deploy a Streamlit application to Azure Web App, follow these general steps:

Step 1:

Create a Linux Python web app on Azure.

theringe_2-1729576741593.png

Step 2:

Using VSCode, add two files: “streamlit.sh” and “.deployment” to the root directory of your project.

theringe_3-1729576884470.png

streamlit.sh

pip install streamlit
python -m streamlit run app.py --server.port 8000 --server.address 0.0.0.0

.deployment

[config]
SCM_DO_BUILD_DURING_DEPLOYMENT=false

Step 3:

Using VSCode, deploy the root directory of your project into the Python app you just created.

theringe_4-1729576910432.png

Step 4:

Find your Python app in Azure, modify the launch command as follows, and then restart the app:

theringe_5-1729576975091.png

bash /home/site/wwwroot/streamlit.sh

theringe_6-1729577014659.png

Step 5:

Make sure your project is running correctly.

theringe_7-1729577027613.png

Module and memory usage

Streamlit itself is a simple pip command (pip install streamlit) has several dependencies related to AI and machine learning libraries. These dependencies can consume significant amounts of memory, especially during the deployment process and when running Streamlit applications.

If your application process terminates unexpectedly or throws exit code 137, this usually indicates that your web app is running low on available memory. In these cases, we recommend upgrading to a higher SKU with more memory to ensure smooth deployment and operation.

theringe_10-1729577178248.png

Examples include:

theringe_8-1729577102189.png

theringe_9-1729577124744.png

References

Azure Linux web app and http server – Microsoft Community Hub

Deploy Mkdocs Pages to Azure Web App – Microsoft Community Hub

Install Streamlit using the command line – Streamlit Docs

Troubleshooting Python function apps in Azure Functions | microsoft run

python – Azure function exit code: 137 | Please review requirements.txt





Source link

You may also like

Leave a Comment

Our Company

Welcome to OdysseyX, your one-stop destination for the latest news and opportunities across various domains.

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

Laest News

@2024 – All Right Reserved. Designed and Developed by OdysseyX