Streamlit UI

How to use Streamlit Sharing to deploy your Streamlit Apps

Posted by

Deploy your Machine Learning Web App using Streamlit Sharing

In my previous articles, I have talked about building a Github Web Scraper and KNN classification model from scratch and using Streamlit for the UI.

What’s the point of building a UI if you can not show it to others.

Enter Streamlit Sharing!

Streamlit sharing is a service provided by Streamlit to easily deploy your app. Below I will walk over the steps in the deployment process.

Get Access to Streamlit Sharing

Streamlit Sharing is currently in its beta mode and you need to join the waiting list to get access to it. It usually takes a few days to get access, I got access within 72 hours. Go to their website and sign up

Screenshot of the page where you sign up

Within a few days, you should get an email granting you access.

Create a text file with the necessary libraries

Create a requirements.txt file with the dependencies. Below is the command to create the file

pip freeze > requirements.txt

Make sure your virtual environment is activated before you type the above command

Upload the files to GitHub

Create a PUBLIC repository on GitHub and upload the .py files and the requirements.txt file.

Screenshot of my Github Repo

I will be deploying the following repo

Sign in to Streamlit Sharing

Go to the following website and sign in using your GitHub account.

Screenshot 1 of https://share.streamlit.io/

Authorize Streamlit and give it access to your Github Repos.

Create a new app

Screenshot 2 of https://share.streamlit.io/

Click on New App

Screenshot 3 of https://share.streamlit.io/

Select your repository and branch. In my case, it’s the master branch of the repo named ‘rahulbanerjee26/KNN-Streamlit’

The main file path should contain the path to your app.py file or the .py file which has the code for the Streamlit UI. If your app.py file is inside a folder named ‘app’, the path will be ‘app/app.py’. Ensure you provide the correct path. Once you have filled in the correct information, click on Deploy.

Now just sit back and relax ☺️

Once Deployment is complete, you will get a success message and be able to see a demo of your app.

Screenshot of successful deployment

Any updates made to the repo will automatically redeploy the app and your changes will be viewable in a few minutes, assuming there are no errors of course.

You can find my deployed app here