6 Simple Steps to Deploy NLP based Flask Application on Heroku

Image 1: NLP Application hosted on Heroku Server

1. Objective

Deploy NLP (Natural Language Processing) based Flask Application on Heroku Server.

2. Assumption

  • Git is installed on your system
  • Your NLP based Flask Application is already ready to use and you are able to run on your local system (localhost — Refer URL bar in screen-shot: Something like below:
Image 2: Flask application on local system
  • You have Linux System and for your reference, all screen-shots/experiments shown in this article are performed on machine with following specification
Image 3: System specification

3. Step by Step process

Lets start and see in simple steps how to deploy Flask application on Heroku Server.

A) Account on Heroku App

Follow 3 steps to have account on heroku

i) Create Account: Visit Link https://signup.heroku.com/ and fill all details

Image 4: Creating account on heroku

ii) Activate Account: Check your mail and click on the activation link received from noreply@heroku.com

Image 5: Account Activation Mail from Heroku

iii) Log In: Visit Link https://www.heroku.com/ and you should receive following screen after successful Log In

Image 6: Successful Log In to Heroku

B) Install Heroku CLI (command line interface)

Follow below commands

sudo apt install snapd
sudo snap install --classic heroku
Image 7: Heroku Installation

Assuming, your current working directory in terminal is root directory of flask application, execute following command for login to heroku via CLI.

heroku login -i
## If you get issue, heroku: command not found, Follow below commands
sudo vi /etc/environment
## If you not able to find :/snap/bin in /etc/environment file, add it, save;close;execute below command and finally should look like Image 8
## Saving and activate environment
source /etc/environment && export PATH
Image 8: Setting up environment for Heroku
## Again try for heroku login via CLI
heroku login -i
## If it asks for login credentials (Image 9), it means heroku CLI installation is successful
Image 9: Heroku Login via CLI successful

C) Create heroku application

## Current working directory in terminal should be root directory of flask application
source /etc/environment && export PATH
## create application with app name: "aakash-word-booster" - Image 10heroku create aakash-word-booster
Image 10: Application creation

D) Setup files required to deploy NLP based Flask Application

i) Procfile: Create file with name “procfile” at root directory location of your flask app. Write below line in file and here api is name of python file contain flask application with flask name app (app = Flask(__name__)).

web: gunicorn api:app

ii) requirements.txt: It contains all libraries with version required to run your flask application on heroku server. You can expand list based on your application.


iii) nltk.txt: To download nltk_data on heroku, need to create nltk.txt at same root directory location of flask application and write nltk package name based on your requirement.


E) Deploy Flask Application on Heroku

## Initialization of git
git init
## attaching git to heroku application name - Image 11
heroku git:remote -a aakash-word-booster
## Use below command to validate above attaching command, it should display exactly - Image 12
git remote -v
## git adding complete flask application to it
git add .
## commit your flask application - Image 13
git commit -m "first heroku commit"
## Push your application to heroku - Image 14
git push heroku master
Image 11: Attacing git to heroku application
Image 12: Validation of git attach to heroku
Image 13: Output after git commit
Image 14: Output after git push

F) Test heroku application

Go to your browser and paste link (deployed to Heroku) mentioned in Image 14 i.e. visit link: https://aakash-word-booster.herokuapp.com/.

4. References

  1. https://aakash-word-booster.herokuapp.com/
  2. https://stackoverflow.com/questions/13965823/resource-corpora-wordnet-not-found-on-heroku
  3. https://help.heroku.com/4NOFQ22L/how-do-i-use-nltk-with-python-on-heroku
  4. https://medium.com/@gitaumoses4/deploying-a-flask-application-on-heroku-e509e5c76524
  5. https://devcenter.heroku.com/articles/heroku-cli#download-and-install
  6. https://stackoverflow.com/questions/12795498/heroku-command-not-found
  7. https://stackabuse.com/deploying-a-flask-application-to-heroku/

Hurray !! You learned how to deploy NLP based Flask Application on Heroku.

Please clap if article helps you and share with your friends as well.

Happy Learning !!




Senior Data Scientist @ Fractal Analytics

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Honest Backtest : Moving Average Distance Index and RSI Trading Strategy

The Mathematics behind Radar Charts

How can data science help create a sustainable future?

How Sarah Mestiri Transitioned from a Software Engineer to a Data Scientist

How to Implement the WHOLE Data Science Process

What happened in 2017 and what to look forward to in 2018 at VCGI

Why is BBM 11 the best? A data-driven analysis of Two Friends’ mixes

Is Data Science A Real Science?

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
Aakash Goel

Aakash Goel

Senior Data Scientist @ Fractal Analytics

More from Medium

Perform Sentiment Analysis and Classification on Text in Python

String Manipulation [Python]

How to Make a Rule-based Chatbot in Python Using Flask

GIFs For All Your Chat Messages! Power-Up Your Appwrite Applications Using Python and NLP