A complete end-to-end sentiment analysis system powered by a fine-tuned Transformer model. This app analyzes English text and classifies it as positive, negative, or neutral using a real-time web interface. It includes:
- HuggingFace Transformer fine-tuning
- FastAPI backend for inference
- Streamlit frontend with animated UI
- Dockerized deployment
-
Fine-tuned
cardiffnlp/twitter-roberta-base-sentiment-lateston 3-label data -
Real-time predictions via FastAPI (
/predict) -
Streamlit UI with:
- Emoji-based label
- Confidence bar animation
- Flip-in effect on sentiment change
-
Fully containerized with Docker Compose
Sentiment_Analysis_AI/
├── backend/
│ ├── app.py # FastAPI app
│ ├── model.py # Model loading logic
│ ├── model/ # Fine-tuned model saved here
│ └── __init__.py
├── ui.py # Streamlit frontend
├── finetune.py # Fine-tuning script
├── run_all.py # Local launcher script
├── Dockerfile.backend
├── Dockerfile.frontend
├── docker-compose.yml
├── requirements.txt
└── README.md
- Python 3.10+
- Docker & Docker Compose (if containerized)
pip install -r requirements.txtuvicorn backend.app:app --reload --port 8000streamlit run ui.pyThen go to http://localhost:8501.
docker-compose up --build- UI: http://localhost:8501
- API Docs: http://localhost:8000/docs
Train a custom sentiment classifier:
python finetune.py \
--data data/files/train_converted.jsonl \
--epochs 3 \
--lr 3e-5Outputs saved in backend/model/
curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{"text": "This product is awesome!"}'Response:
{
"label": "positive",
"score": 0.9823
}| Issue | Fix |
|---|---|
| ConnectionError in UI | Use http://backend:8000 inside Docker, not localhost |
| Docker timeout | Use --default-timeout=300 in Dockerfile |
| CORS/XSRF warning | Safe to ignore unless deploying cross-domain |
Sanjay Ravichander Junior Machine Learning & Deep Learning Engineer
MIT