Skip to content

ammar321an/text-classification-nlp-training-flask-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📘 Template for Text Classification NLP (Flask + TensorFlow)

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.


🧱 Prerequisites

✅ Python Installed (Version 3.12 or Below)

TensorFlow may not support very new Python versions.

Recommended Python versions:

  • 3.10
  • 3.11
  • 3.12

Download Python:
https://www.python.org/downloads/


📥 Installation Guide (Windows & macOS)

Follow these steps after cloning the repository from GitHub.


1️⃣ Clone the Repository

git clone <your-repo-url>
cd text-classification-nlp-training-flask-framework

2️⃣ Open Project in VS Code

code .

3️⃣ Create Virtual Environment

Windows:

python -m venv venv

macOS:

python3 -m venv venv

4️⃣ Activate the Virtual Environment

Windows:

venv\Scripts\activate

macOS:

source venv/bin/activate

You should now see the environment name:

(venv)

5️⃣ Install Dependencies

This project uses requirements.txt.

Windows:

pip install -r requirements.txt

macOS:

pip3 install -r requirements.txt

Note: Some systems use python / python3 or pip / pip3. Use what works on your machine.

6️⃣ Run the Flask Application

Windows:

python app.py

macOS:

python3 app.py

Once running, Flask will show something like:

 * Running on http://127.0.0.1:5000

7️⃣ Open the Application in a Browser

Open:

http://127.0.0.1:5000

You will now see the sentiment UI.


🧪 Testing the Sentiment Analysis Model

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.


🔄 Using Your Own Model (COMPULSORY)

If you have trained your own sentiment analysis model, you can easily replace the existing model files.

Steps to Replace the Model:

  1. Place your model files in the root folder of the project

  2. Replace these files:

    • sentiment_rnn_model.h5 - Your trained TensorFlow/Keras model
    • tokenizer.pkl - Your fitted tokenizer (pickled)
  3. Ensure your model:

    • Uses the same input format (tokenized sequences)
    • Outputs predictions in the same format
    • Is compatible with TensorFlow/Keras
  4. 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.)


📝 Troubleshooting (Optional only if facing any error)

Virtual Environment Not Activating (Windows)

If permission error appears:

Set-ExecutionPolicy Unrestricted

Run PowerShell as Administrator.

TensorFlow Errors

Make sure Python ≤ 3.12.

If issues persist:

pip install --upgrade pip
pip install tensorflow

Flask Not Starting

Check missing packages:

pip list

Ensure Flask, TensorFlow, NumPy are installed.


🎉 You're Ready for Presentation

Once:

  • The app runs
  • No installation errors
  • Sentiment prediction works

You are ready to present the NLP project.

About

Use for training purposes only

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published