NATURAL LANGUAGE PROCESSING
DEPLOYMENT
03/07/2025
Deploying ML-NLP Models
Deployment usually is the last step in any NLP Project Pipeline, to be able to
integrate your NLP model to a web application is quite an important task. There
are many popular frameworks that can be used to do this task such as Flask ,
FastApi, heroku, Streamlit and Django. Django is usually used for large scale
application and takes quite a bit of time to set up .
Flask , FastAPI are usually your go-to for quickly deploying of your model on a
web app
03/07/2025
Flask
Flask is WSGI- [web server
gateway interface ] application, a
web framework written in python
for ML models deployment
03/07/2025
Model deployment
03/07/2025
FAST API
It is becoming quite popular, so much so that companies like
Netflix and Uber are using it, it is used to develop RESTful APIs in
python
03/07/2025
FastAPI vs Flask:
1. FastAPI is way faster than Flask, not just that it’s also one of the
fastest python modules out there.
2. Unlike Flask, FastAPI provides an easier implementation for Data
Validation to define the specific data type of the data you send.
3. Automatic Docs to call and test your API(Swagger UI and Redoc).
4. FastAPI comes with built-in support for Asyncio, GraphQL and
Websockets.
03/07/2025
Libraries installation
Installing flask , FastAPI, Tensorflow, keras and uvicorn server:
Installing FastAPI is the same as any other python module, but along with FastAPI you
also need to install uvicorn to work as a server. You can install these libraries of them
using the following command:-
pip install fastapi uvicorn
pip install tensorflow
pip install flask
pip install nltk
03/07/2025
Creating Basic API using FastAPI
Before creating our ML model lets start by creating a basic API
that’s going to return us a simple message.
03/07/2025
Tiny code
# Importing Necessary modules
from fastapi import FastAPI
import uvicorn
# Declaring our FastAPI instance
app = FastAPI()
# Defining path operation for root endpoint
@app.get('/')
def main():
return {'message': 'Welcome to the bootcamp!'}
# Defining path operation for /name endpoint
@app.get('/{name}')
def hello_name(name : str):
# Defining a function that takes only string as input and output the
# following message.
return {'message': f'Welcome to the bootcamp!, {name}'}
03/07/2025
Test it…
uvicorn basic-app:app --
reload
03/07/2025
The Chatbot -FLASK Project
In this Python web-based project ,we are going to build a chatbot
using deep learning and flask techniques. The chatbot will be
trained on the dataset which contains categories (intents),
pattern and responses. We use a special artificial neural network
(ANN) to classify which category the user’s message belongs to
and then we will give a random response from the list of
responses.
03/07/2025
The steps
1. Import and load the data file
2. Preprocess data
3. split the data into training and test
4. Build the ANN model using keras
5. Predict the outcomes
6. Deploy the model in the Flask app
03/07/2025
Files
03/07/2025
The file structure
1. data.json – The data file which has predefined patterns and responses.
2. trainning.py – In this Python file, we wrote a script to build the model and train
our chatbot.
3. Texts.pkl – This is a pickle file in which we store the words Python object using
Nltk that contains a list of our vocabulary.
4. Labels.pkl – The classes pickle file contains the list of categories(Labels).
5. model.h5 – This is the trained model that contains information about the model
and has weights of the neurons.
6. app.py – This is the flask Python script in which we implemented web-based GUI
for our chatbot. Users can easily interact with the bot.
6th International Research Confere 03/07/2025
nce
Outputs
03/07/2025
Streamlit Library
Streamlit allows us to create apps for our machine-learning
project with simple Python scripts. Hot reloading is also
supported, so our app can be updated live while we edit and save
our file. Streamlit API allows us to create an app in a few lines of
code (as we'll see below). Declaring a variable is the same thing
as adding a widget. We don't need to create a backend, handle
HTTP requests or define different routes. It's easy to set up and
maintain.
03/07/2025
Django
Django is a web application framework written in Python
programming language. It is based on MVT (Model View Template)
design pattern. The Django is very demanding due to its rapid
development feature. It takes less time to build application after
collecting client requirement.
03/07/2025
Django Popularity
1. Django is widely accepted and used by various well-known sites
such as:
2. Instagram
3. Mozilla
4. Disqus
5. Pinterest
6. Bitbucket
7. The Washington Times
03/07/2025
Features of Django
1. Rapid Development
2. Secure
3. Scalable
4. Fully loaded
5. Versatile
6. Open Source
7. Vast and Supported Community
03/07/2025
Django Installation
To install Django, first visit to django official site
(https://www.djangoproject.com) and download django by
clicking on the download section.
Django requires pip to start installation. Pip is a package
manager system which is used to install and manage packages
written in python. For Python 3.4 and higher versions pip3 is
used to manage packages.
pip3 install django==2.0.3
03/07/2025
Django Project
To create a Django project, we can use the following
command. projectname is the name of Django application.
$ django-admin startproject projectname
Django Project Example
Here, we are creating a project djangpapp in the current
directory.
$ django-admin startproject djangpapp
03/07/2025
Django project
03/07/2025
Running Django project
03/07/2025
Web- Django
03/07/2025