Deploy Machine Learning Model using Flask to Heroku — Beginners(Part 3)

Joan Ngugi
Analytics Vidhya
Published in
3 min readFeb 9, 2021

--

This tutorial is part 3 and the final part of the guide on how to deploy Machine Learn Models using Flask to Heroku via GitHub.

  • The first part was a refresher on a logistic regression model on JupyterNotebook.
  • The second part was on how to structure your flask application and embed your machine learning model in it, as well as uploading the application on GitHub.
  • Our final part will be a guide on how to deploy your flask application from GitHub to Heroku.

Step 1: Creating a New App

From your Heroku dashboard click on New and then Create new app as shown below.

Enter your new app name and save changes by clicking on the Create app button.

Step 2: Connecting to GitHub

From the new create app on the Deploy section ,choose GitHub as your deployment method. You will need to allow Heroku to access GitHub when prompted. Once you have successfully connected to GitHub search for your repo-name and click connect on that repo.

Step3 : Deployment

On the manual deployment section, choose your branch, in this case our branch is the main branch, then click on Deploy Branch. This process could take up between 2 and 10 minutes depending on your internet speed. If your app was successfully deployed you will see a View button. In my case, View button takes me to https://joan-diabetes-predictor.herokuapp.com/

If the View button gives you the following error, don’t panic :)

Something could have gone wrong. In most cases it’s usually one of the following:

  1. Package versions not matching with those in Heroku. You can always downgrade.
  2. Missing Gunicorn package in your requirements.txt file.
  3. Missing out the Procfile, or wrong spelling of the file name. Confirm the command in it is also okay.

The View logs section will guide you on your error. When you fix your code, redeploy your branch once again.

That is the final part of the guide on how to create and deploy a machine learning model on Heroku using Flask via GitHub. Happy Coding !

--

--

Joan Ngugi
Analytics Vidhya

Big Data & Analytics, Data Science, Machine Learning, Data Engineering | ngugijoan.com