A full-stack web application that analyzes the sentiment of user-submitted reviews or comments (e.g., from Amazon or Twitter) and classifies them as Positive, Neutral, or Negative. Built using Python (Flask) for the backend and React for the frontend.
- Train and save a logistic regression model using scikit-learn
- REST API built with Flask to serve real-time predictions
- React frontend for user input and displaying sentiment results
- CORS-enabled communication between frontend and backend
- Frontend: React, Axios
- Backend: Python, Flask, scikit-learn, joblib, Flask-CORS
- Model: Logistic Regression with TF-IDF vectorizer
- Tools: Postman (for API testing), VS Code (for dev)
sentiment-analyzer/
├── backend/
│ ├── app.py # Flask app with /predict API
│ ├── model/
│ │ ├── train_model.py # Model training script
│ │ ├── sentiment_model.pkl # Saved ML model
│ │ └── sentiment_data.csv # CSV with labeled text data
│ └── requirements.txt # Python dependencies
├── frontend/
│ └── sentiment-ui/ # React app
└── README.md
cd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
cd model
python train_model.py # Trains and saves model
cd ..
python app.py # Starts Flask server at http://127.0.0.1:5000cd frontend
npx create-react-app sentiment-ui
cd sentiment-ui
npm install axios
npm start # Starts frontend at http://localhost:3000- Open the app at
http://localhost:3000 - Enter a review like:
"This is the best product I’ve ever used!" - Click "Analyze Sentiment"
- Output:
Sentiment: POSITIVE
- Upgrade to Hugging Face Transformers (DistilBERT) for better accuracy
- Add charts for sentiment analysis stats
- Enable batch predictions
- Dockerize and deploy to Render or Railway
- Add CI/CD with GitHub Actions
This project is open-source and free to use under the MIT license.