This repository provides a Flask web application for sentiment analysis using an NLP text classification model. It includes setup instructions for both Windows and macOS.
TensorFlow may not support very new Python versions.
Recommended Python versions:
- 3.10
- 3.11
- 3.12
Download Python:
https://www.python.org/downloads/
Follow these steps after cloning the repository from GitHub.
git clone <your-repo-url>
cd text-classification-nlp-training-flask-frameworkcode .Windows:
python -m venv venvmacOS:
python3 -m venv venvWindows:
venv\Scripts\activatemacOS:
source venv/bin/activateYou should now see the environment name:
(venv)
This project uses requirements.txt.
Windows:
pip install -r requirements.txtmacOS:
pip3 install -r requirements.txtNote: Some systems use
python/python3orpip/pip3. Use what works on your machine.
Windows:
python app.pymacOS:
python3 app.pyOnce running, Flask will show something like:
* Running on http://127.0.0.1:5000
Open:
http://127.0.0.1:5000
You will now see the sentiment UI.
Try entering text such as:
- I love this product!
- This is terrible.
- It's okay, nothing special.
The model should return categories like:
- Positive
- Neutral
- Negative
If predictions appear correctly, your setup is complete.
If you have trained your own sentiment analysis model, you can easily replace the existing model files.
-
Place your model files in the root folder of the project
-
Replace these files:
sentiment_rnn_model.h5- Your trained TensorFlow/Keras modeltokenizer.pkl- Your fitted tokenizer (pickled)
-
Ensure your model:
- Uses the same input format (tokenized sequences)
- Outputs predictions in the same format
- Is compatible with TensorFlow/Keras
-
Restart the Flask application to load the new model
Note: Make sure your custom model and tokenizer were trained with compatible parameters (sequence length, vocabulary size, etc.)
If permission error appears:
Set-ExecutionPolicy UnrestrictedRun PowerShell as Administrator.
Make sure Python ≤ 3.12.
If issues persist:
pip install --upgrade pip
pip install tensorflowCheck missing packages:
pip listEnsure Flask, TensorFlow, NumPy are installed.
Once:
- The app runs
- No installation errors
- Sentiment prediction works
You are ready to present the NLP project.