Deploy NLP (Natural Language Processing) based Flask Application on Heroku Server.
- 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: 127.0.0.1). Something like below:
- You have Linux System and for your reference, all screen-shots/experiments shown in this article are performed on machine with following 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
ii) Activate Account: Check your mail and click on the activation link received from firstname.lastname@example.org
iii) Log In: Visit Link https://www.heroku.com/ and you should receive following screen after successful Log In
B) Install Heroku CLI (command line interface)
Follow below commands
sudo apt install snapd
sudo snap install --classic heroku
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 commandssudo 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
## 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
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
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
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/.
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 !!