Deploying a machine learning web app built using Streamlit on Heroku involves a few steps. Here's a general overview of the process:
Create a Heroku account: If you don't already have one, create a Heroku account at https://signup.heroku.com/.
Install the Heroku CLI: The Heroku Command Line Interface (CLI) allows you to manage your Heroku applications directly from the terminal. You can download and install the Heroku CLI from the official website: https://devcenter.heroku.com/articles/heroku-cli.
Create a new Heroku app: Use the Heroku CLI to create a new app on Heroku. Navigate to your project directory in the terminal and type the following command:
heroku create
Replace <app-name>
with a unique name for your app. This command will create a new app on Heroku and add a new Git remote to your project.
requirements.txt
file to know which Python packages to install. You can create this file using the following command:
pip freeze > requirements.txt
Make sure to run this command in your project directory.
Procfile
is a text file that tells Heroku what command to run to start your web app. Create a new file called Procfile
in your project directory and add the following line:
web: sh setup.sh && streamlit run app.py
This command runs a setup.sh
script (if it exists) and then starts the Streamlit app.
setup.sh
file to install the necessary dependencies. For example, if you're using a custom model file, you can add the following command to your setup.sh
file:
mkdir -p ~/.streamlit/ echo "\ [general]\n\ email = \"your-email@domain.com\"\n\ " > ~/.streamlit/credentials.toml echo "\ [server]\n\ headless = true\n\ enableCORS=false\n\ " > ~/.streamlit/config.toml
This creates a directory for Streamlit configuration files and sets some default values.
git add . git commit -m "Initial commit"
git push heroku master
This will deploy your app to Heroku. Once the deployment is complete, you can open your app in a web browser using the following command:
heroku open
Congratulations, you have successfully deployed your machine learning web app built using Streamlit on Heroku!