deploy steamlit to heroku

Deploy Streamlit App To Heroku

How to deploy Streamlit App On Heroku?

Creating a Web App for Machine Learning Model using Streamlit is cool. Streamlit is the Python library that is used to create sharable Web Applications in just a few steps. In the previous article, we built a Machine model in Streamlit. To make this more interesting, deploy the Streamlit app to Heroku.

Create your account on Heroku, before proceeding further it’s free.

A Step-by-Step Guide to Deploy Streamlit App on Heroku

1. Create Virtual Environment

Suppose you have created your web app using the latest version of Python Flask. Your web application is running well in this version which is good. After a few months, a new version of Flask might release. In the worst-case scenario, there might be chances your application might not run for the latest release of Flask. Here is where the virtual environment comes into play. Once you create your web application using a virtual environment, no matter what new release comes, your application will run perfectly fine.

Open your new project directory and run the following commands:

virtualenv env
source env/bin/activate

2. requirements.txt file

Import all the required modules with help of pip. pip is a play Store for Python modules. After installing the required libraries run the pip freeze command to browse the installed modules in a virtual environment. Create a new file named requirements.txt and insert all required modules in this file.

touch requirements.txt
pip freeze > requirements.txt

3. Create

In the previous article, we built medical charges prediction Machine Learning model.

You can check this article, and add supported files required to build Machine Learning models.

4. Config

setup. sh file is used for Heroku to recognize that you are using the Streamlit library to deploy your project.

mkdir -p ~/.streamlit/
echo "\
headless = true\n\
port = $PORT\n\
enableCORS = false\n\
" > ~/.streamlit/config.toml

5. Git Commands to deploy Streamlit app to Heroku

The last step is to push your app on GitHub and then deploy it to Heroku. You need to have a GIT host account i.e., GitHub or BitBucket, or GitLab account. Once you have completed your project push all the changes to the GIT host provider.

Create a Repository on GitHub and clone the repo on your local computer.

git clone
cd machine_learning_using_streamlit/

Once you are inside the project directory add all your project files here.

git add *

The project files are staged and are waiting to be committed.

git commit -m "to heroku"

The working tree is clean you can push all the committed files to remote repo i.e., GitHub.

git push

Once all the changes are done on the remote repo. Let’s move to the last phase to deploy our app.

Login to your Heroku app and create a new app by providing a unique name.

heroku login
// once you are login, create new app
heroku create mlstremapp

Uff! let us proceed with the last command. Push all the changes to Heroku.

git push heroku main

We are done. Congratulations.


Hurray, we finally deployed🚀 our Streamlit app on Heroku:🙂. In this way, it becomes super simple to make a Machine Learning model shareable.

If you have many graph plots in your app then it will take a huge time to open the app.

Also Check: How to Deploy Flask App On Heroku

Source Code: Check GitHub.


If you like our content support us: Buy Me A CoffeeKo-Fi

1 thought on “Deploy Streamlit App To Heroku”

  1. Pingback: Build Machine Learning Model Using Streamlit

Comments are closed.