Skip to content

raess1593/AI-sentiment-classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Sentiment Radar

An end-to-end NLP web app that classifies product reviews as positive or negative in real time using a scikit-learn pipeline, MLflow tracking, a FastAPI backend, and a modern vanilla frontend.

Frontend preview


✨ Features

  • NLP pipeline β€” text cleaning, TF-IDF vectorization, and Logistic Regression for binary sentiment classification
  • Experiment tracking β€” MLflow logs parameters, metrics, and model artifacts for each run
  • REST API β€” FastAPI backend with /predict and /health endpoints
  • Modern UI β€” responsive dark interface built with plain HTML, CSS, and JavaScript
  • Docker ready β€” single-container deployment with a Render-friendly PORT setup
  • Render ready β€” easy cloud deployment with a stable public URL

πŸ›  Tech stack

Layer Technology
Model scikit-learn Β· LogisticRegression Β· TF-IDF
Tracking MLflow
API FastAPI Β· Uvicorn
Frontend Vanilla HTML Β· CSS Β· JavaScript
Container Docker
Deploy Render

πŸ“ Project structure

sentiment-radar/
β”œβ”€β”€ assets/
β”‚   └── website.png           # Frontend screenshot used in this README
β”œβ”€β”€ data/                      # Local dataset and SQLite database files
β”œβ”€β”€ mlruns/                    # MLflow run artifacts
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ api.py                 # FastAPI app and prediction endpoints
β”‚   β”œβ”€β”€ config.py              # Paths and environment configuration
β”‚   β”œβ”€β”€ db.py                  # SQLAlchemy models and SQLite engine
β”‚   β”œβ”€β”€ seed_db.py             # Dataset seeding helper
β”‚   β”œβ”€β”€ train.py               # Training pipeline + MLflow logging
β”‚   └── static/
β”‚       β”œβ”€β”€ index.html         # Frontend entry point
β”‚       β”œβ”€β”€ styles.css         # UI styles
β”‚       └── app.js             # Frontend logic
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ requirements.txt
└── README.md

πŸš€ Quick start

Option 1: Run with Docker

docker build -t sentiment-radar .
docker run -p 10000:10000 sentiment-radar

Open:

  • http://localhost:10000

Option 2: Run locally without Docker

pip install -r requirements.txt

Then start the API:

set PYTHONPATH=src
uvicorn api:app --host 0.0.0.0 --port 8000 --app-dir src

Open:

  • http://localhost:8000

If you open the frontend with Live Server, keep the API running separately on port 8000 or 10000.


πŸ§ͺ Model workflow

  1. Reviews are stored in the local SQLite database.
  2. src/train.py loads the data and trains a text classification pipeline.
  3. MLflow logs the experiment run and model artifact.
  4. src/api.py loads the latest trained model and serves predictions through the API.

Training the model

set PYTHONPATH=src
python src/train.py

🌐 Deploy on Render

  1. Push the repository to GitHub.
  2. Go to render.com and create a New Web Service.
  3. Connect your GitHub repository.
  4. Select Docker as the environment.
  5. Deploy the service.
  6. Render will assign a public URL like https://your-app.onrender.com.

The container is configured to respect the PORT environment variable, which is the safest setup for Render.


πŸ“‘ API endpoints

Method Endpoint Description
GET / Serves the frontend
GET /health Returns API and model status
POST /predict Returns the predicted sentiment

Example /predict request

{
  "text": "I absolutely love this phone. The screen is sharp and the battery lasts all day."
}

Example response

{
  "sentiment": "Positive",
  "confidence": 0.97
}

πŸ–Ό Frontend preview

The UI is intentionally minimal, modern, and responsive. It includes:

  • a clear hero section
  • a live prediction card
  • sample review buttons
  • confidence visualization
  • green/red animated feedback based on the prediction

πŸ‘€ Author

@raess1593

About

πŸ€– Sentiment Radar is an end-to-end machine learning web application that analyzes product reviews in real time and predicts whether the sentiment is positive or negative using a trained NLP pipeline, MLflow experiment tracking, a FastAPI backend, and a modern responsive frontend.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors