In the last article, we created a RandomForest Regression model that can be used to predict Airbnb apartment prices. The next natural step after creating a machine learning model is to share the results as well as the model with the users. Here is the link to my app on Heroku.
Let’s look at some of the quick steps on how to deploy a model on Heroku.
Streamlit is an open source tool for building and deploying data application. It makes sharing of prototypes and analysis results very easy. To get started, follow the documentation here.
The first step is to create a git repository in your working directory. The working directory could have the following files:
Create a Procfile in your working directory add the following code
web: sh setup.sh && streamlit run <app.py>
Create a set.sh file and add the following code
To track all the files, add them to git using git add . and then use git commit -m ‘commit message’ to commit the changes.
If you don’t have an account yet, go to Heroku and create one. It’s free for limited number of apps as well as storage. Follow the documentation guide to setup a Command Line Interface(CLI) that makes it easy to manage apps from the terminal.
Once setup, login into heroku using
heroku login
This will open a browser window to login into your account.
Use the following code to create an ap. This will assign a random name by default which you can change later.
heroku create
To commit changes, use
git push heroku master
This will prepare all the files for deployment and compresses any large files in your working directory. If all goes well, you should see deployed successfully in your terminal.
Your app is up and running. Run the following code to ensure that you app has enough bandwith.
heroku ps:scale web=1
To view you app, type heroku open
To rename the app, use heroku apps:rename new_app_name. If you are using the repository for more than one app, use heroku apps:rename –app old_name new_name
Note:
That’s it! Happy Learning.