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:

  1. Procfile (no extension)
  2. Pickle file
  3. 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.

Create Requirements.txt

It contains all the dependencies for my flask app.

Initialize git and add all files

# Initialize git repo
git init

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….

--

--

Software Developer | Machine Learning Enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store