Deploy Machine Learning Model to Heroku
After building an example app, we deployed the app on heroku and it was a wonderful experience that I just had to share the few steps here for everyone to use.
Let me first give you the brief introduction of these app in a layman way. Basically this app gives you the prediction you will get the admission or not, based upon the user inputs . Inputs are like: GRE Score, Toefl Score, University Rating, Sop Score, Lor Score, CGPA and Research(Yes or No).
Tech stack: Python, Flask, Heroku
To successfully deploy a Machine Learning model with Flask and Heroku. You will need some files in your Machine Learning application:
- An app.py file
- Procfile (no extension)
- Pickle file
- Requirements.txt file
Prerequisite: First you need to install Heroku CLI. Once it installed, follow these steps.
When you have done with your development part you need to first check that application is working perfectly or not on your local server. If App is working fine then you have to follow these steps:
Create a Procfile
Heroku needs Profile in your app root directory. So create a Procfile( Without any extension) and save it with given below command. Given command in Procfile is used by Heroku app on startup.
Gunicorn(Green Unicorn) is a WSGI HTTP server that is used to run python based web applications.
It contains all the dependencies for my flask app.
Initialize git and add all files
# Initialize git repo
Git add command Initialize a empty a git repo in working directory.
# add all changes from working directory to git
git add .
Now git add command add all files to git repo from working directory. Its tells the git add all the changes in next commit.
# commit all changes
git commit -m "first commit with your message"
Git commit command capture the snapshot of your project as a version of your project.
Deploy to Heroku
For deployment, create a free account at https://www.heroku.com/ . After successfully login you can create an app using heroku create command with you terminal.
Now git remote command gives us two url’s for fetch and for push.
Now final command
git push heroku master, this will push all your files to heroku cloud and installed all dependencies for us.
Finally my app is deployed on the heroku and live now.
Open https://nameless-wildwood-42104.herokuapp.com/ in your browser.
You will get the result like this:
Thanks for Reading 🙏
Happy Learning Happy Coding😃
Feel free to leave a comment or share this post. Follow me for future posts….
If you like this article you may enjoy other articles too.
Understanding of Linear Regression Model
Linear regression is one the most well known algorithm in statistics and machine learning. In this article we are going…
Python: Lambda, Map, Filter and Reduce functions
In Python, normal functions are defined using def keyword followed by function name. For example:
Decorators in Python is an advanced topic. Before we dive into Python Decorator we need to understand the concepts of…
Python classes and objects
Python is a object oriented programming language. In python mostly everything is an object with its…