Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎭 AI Sentiment Analyzer

A full-stack web application for real-time and batch sentiment analysis. Built with React + Vite frontend and a Flask backend, integrated with Hugging Face Transformers, Scikit-learn, and a heuristic rule-based model.

πŸ“Œ Features

πŸ”Ή Frontend (React + Vite)

Responsive, modern UI (textarea, charts, file upload)

Real-time single review analysis with delay/debounce

Batch CSV upload and analysis (counts, keywords, charts)

Model selector (Hugging Face / Scikit-learn / Heuristic)

πŸ”Ή Backend (Flask)

RESTful API with /api/health, /api/predict, /api/batch, /api/debug

Hugging Face cardiffnlp/twitter-roberta-base-sentiment-latest

Scikit-learn: TF-IDF + Logistic Regression (toy dataset)

Heuristic rules + keyword triggers for fallback/edge cases

Batch CSV parsing with keyword summary & counts

πŸ”Ή Models

Hugging Face: Pre-trained transformer (POS/NEU/NEG)

Scikit-learn: Lightweight ML baseline

Heuristic: Simple keyword-based rules with overrides

βš™οΈ Installation & Run 1️⃣ Backend (Flask) cd backend python3 -m venv .venv1 source .venv1/bin/activate

Install dependencies

pip install -r requirements.txt

Run server

export API_TOKEN=dev-token python3 app.py

Runs at β†’ http://127.0.0.1:5000

2️⃣ Frontend (React + Vite) cd frontend npm install npm run dev

Runs at β†’ http://127.0.0.1:5173

πŸ”— API Endpoints Health curl http://127.0.0.1:5000/api/health

β†’ {"status":"ok"}

Predict curl -X POST http://127.0.0.1:5000/api/predict
-H "Authorization: Bearer dev-token"
-H "Content-Type: application/json"
-H "X-Model: hf"
-d '{"text":"I love this!"}'

Batch printf 'text\nLove it\nWorst phone\nOkay product\n' > reviews.csv

curl -X POST "http://127.0.0.1:5000/api/batch?col=text"
-H "Authorization: Bearer dev-token"
-H "X-Model: sk"
-F "file=@reviews.csv"

πŸ“Š Screenshots

image image

🧠 Models

Hugging Face cardiffnlp/twitter-roberta-base-sentiment-latest β†’ Pre-trained 3-class transformer

Scikit-learn TF-IDF + Logistic Regression β†’ Trained on toy dataset (30 samples)

Heuristic Rule-based triggers (love, hate, okay, etc.) β†’ Fast fallback model

πŸš€ Future Improvements

Hybrid model: Hugging Face embeddings + Scikit-learn classifier

Train and save/load real Scikit-learn models (joblib)

Loading spinners & error toasts in frontend

Docker + AWS deployment for public demo

Multi-language sentiment support

πŸ“‚ Project Structure ai-sentiment-analyzer/ β”œβ”€β”€ backend/ # Flask API + models β”‚ β”œβ”€β”€ app.py β”‚ β”œβ”€β”€ requirements.txt β”‚ └── ... β”œβ”€β”€ frontend/ # React + Vite UI β”‚ β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ package.json β”‚ └── ... └── README.md

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages