fbpx
Deploying a Text Classification Model in Python Deploying a Text Classification Model in Python
This article is the last of a series in which I cover the whole process of developing a machine learning project. If you... Deploying a Text Classification Model in Python

Considerations before the deployment

The data

Source

Source

The features

The environment

The user experience


Creation of a Dash web application

Deployment with Heroku

# after signing in to Heroku and opening the anaconda prompt
# we create a new folder
mkdir dash-app-lnclass cd dash-app-lnclass# initialize the folder with git
git init</span></pre> After that, we create an environment file (<em class="lu">environment.yml</em>) in which we will indicate the dependencies we are going to need:  <pre class="lj lk ll lm ln mf mg dp"><span id="f171" class="gi gj gu bj mh b cb mi mj r mk" data-selectable-paragraph="">name: dash_app_lnclass #Environment name dependencies:   - python=3.6   - pip:     - dash     - dash-renderer     - dash-core-components     - dash-html-components     - dash-table     - plotly     - gunicorn # for app deployment     - nltk     - scikit-learn     - beautifulsoup4     - requests     - pandas     - numpy     - lxml</span></pre> And activate the environment:  <pre class="lj lk ll lm ln mf mg dp"><span id="b0ae" class="gi gj gu bj mh b cb mi mj r mk" data-selectable-paragraph=""> conda env create
activate dash_app_lnclass</span></pre> Then, we initialize the folder with <em class="lu">app.py, requirements.txt </em>and a <em class="lu">Procfile:</em>  <pre class="lj lk ll lm ln mf mg dp"><span id="5597" class="gi gj gu bj mh b cb mi mj r mk" data-selectable-paragraph=""># the procfile must contain the following line of code web: gunicorn app:server  </span><span id="7e9f" class="gi gj gu bj mh b cb ml mm mn mo mp mj r mk" data-selectable-paragraph=""># to create the requirements.txt file, we run the following: pip freeze > requirements.txt
heroku create lnclass # change my-dash-app to a unique name git add . # add all files to git
git commit -m 'Comment' git push heroku master # deploy code to heroku
$ heroku ps:scale web=1  # run the app with a 1 heroku "dyno"

Final thoughts

Miguel Fernández Zafra

Miguel Fernández Zafra

Passionate about Finance and Data Science, and looking forward to combining these two worlds so as to take advantage of what technology can bring to us.

1