×

Deploy the Streamlit Application

Deploy Streamlit Feature

Let’s see how we can deploy our streamlit application on the internet to showcase our work. The article discusses the two methods to deploy the streamlit application into the Web —

  • First, using Streamlit Cloud.
  • Second, using Heroku.

Streamlit Cloud

The Streamlit cloud service is essentially a free hosting platform on which developers can run their Streamlit-built machine learning software. End-users can access applications hosted on the service via a browser.

Streamlit Cloud was previously Streamlit Sharing.

Streamlit Sharing Is Now Streamlit Cloud

The catch is that Streamlit Sharing is only open to open-source applications whose code is publicly available on GitHub. But, Streamlit Cloud allows only to deploy three apps in its free version.

It’s very simple to deploy an app on Streamlit Cloud. Follow these easy steps:

  • Create a Git repository and Upload all the files related to the application onto Github.
  • Create one additional file named requirements.txt. Requirements.txt will contain the name and version of the modules used in the python script of the application.

Use pip freeze command to see the installed modules and their version in your system.

Requirements Txt
  • Visit Stleamlit cloud.
  • Select the plan and create an account in the Streamlit Cloud.
  • Login into your Streamlit cloud and provide the Github Repo name of your Streamlit application.

Heroku

Heroku is a cloud service platform whose popularity has grown in recent years. Heroku is so easy to use that it’s a top choice for many development projects. To deploy the Streamlit application using Heroku, we have the following requirements.

Software Requirements

Files Requirements

  • requirements.txt : Requirements.txt will contain the name and version of the modules used in the python script of the application.
  • setup.sh file: This is a shell file, and we need to add the following shell command inside the file. Copy-paste the code below into the file:
mkdir -p ~/.streamlit/
echo "\
[server]\n\
headless = true\n\
port = $PORT\n\
enableCORS = false\n\
\n\
" > ~/.streamlit/config.toml
  • procfile: The Procfile is used to execute the setup.sh and then call streamlit run to run the application. Procfile contains:
web: sh setup.sh && streamlit run app.py

app.py is the python file for our application.

The “web” means that it’s a web app. The Procfile specifies the commands to run the app on Heroku.

The Procedure

  • Create a Git repository.
git init
  • Now, log in to Heroku. Login in to Heroku with following command.
heroku login

You’ll be asked to press any button and then you’ll be redirected to the Heroku’s login screen in your default web browser. Enter your credential in the website.

  • Finally, we can deploy our application to Heroku, with following command:
heroku create <app_name>
  • Lastly, push the files into Git Repo.
git add . 
git commit -m "commit message" 
git push heroku master

As we perform the push in our git repo, Heroku will return the URL for our streamlit application.