Deploying a Machine Learning model to production
Deploying a Machine Learning model to production

Deploying a Machine Learning model to production

In a previous article I demonstrated how to build a User Interface for a machine Learning model using Django ML UI. In this article I will deploy the model to Heroku. You can find the Django ML UI package here:

What is Heroku?

Heroku is a Platform as a Service (PaaS) that allows developers to deploy, manage and scale applications. It supports a variety of programming languages including Ruby, Node.js and Python among others.

Deploying with GitHub

There are a few ways to deploy to Heroku. In this article we are going to configure the app on the local folder, push it to GitHub, pull it into Heroku, do a bit of config on that end and then deploy i.e. the Github method.

Step 1: Config on local machine.

First we're going to install Gunicorn, a Python Web Server Gateway Interface HTTP server and Whitenoise which will handle the static files:

pip install gunicorn

pip install whitenoise        

Next we are going to create a Procfile, this is a Heroku specific thing. Run this on the terminal.

touch Procfile        

Inside the Procfile add the following:

web: gunicorn <name_of_your_app>.wsgi --log-file -        

The name of my app is "config" so my Procfile will look like this:

web: gunicorn config.wsgi --log-file -        

Finally we're going to pip freeze the requirement file so that Heroku can run the requirements for our project.

pip freeze > requirements.txt        

Step 2: Push to GitHub

On the terminal, run the following to push your changes to Github:

git add .

git commit -m "commit"

git push        

Step 3: Heroku

Create a Heroku account, unfortunately they just discontinued their free tire but I think their Eco option is worth a try. On Heroko create a new app and give it a name (this will appear on the web address if you do not have a custom domain)

No alt text provided for this image
Create a nw app
No alt text provided for this image
give your app a unique name

At this point you also need to add the host-name of your new app to the settings.py file:

ALLOWED_HOSTS = ['127.0.0.1', 'django-ml-ui-titanic.herokuapp.com']        

Go to settings (on Heroku) and add a build pack. This is a Python app so I will select Python:

No alt text provided for this image
Select the Heroku Python build pack

Next go to Deploy, click on Connect to GitHub:

No alt text provided for this image
Accessing GitHub on Heroku


Then you will be prompted to grant Heroku access to your Github repos. Grant the access and connect to your repo. You should see something like this:

No alt text provided for this image
Accessing GitHub on Heroku

Now click Deploy Branch and in a moment your app should be ready. You should get confirmation as follows:

No alt text provided for this image
Deployment Confirmation

You should be able to now view the app and share it. The app deployed in this article looks like this:

No alt text provided for this image
Deployed app


Conclusion

This articles illustrates how to deploy a UI built with the Django-machine-learning-user-interface library to Heroku. Deploying machine learning models involves a lot more than getting the application to work and having a good UI does not guarantee project success but it sure beats excel files.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了