π 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
pip install -r requirements.txt
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
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
π§ 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