A production-ready, deployable sentiment analysis system with ML backend, REST API, and React frontend.
SentimentAI is a full-stack sentiment analysis application that classifies text as Positive, Negative, or Neutral and additionally detects 8 emotions (joy, anger, sadness, fear, surprise, disgust, trust, anticipation) with confidence scores and keyword extraction.
| Layer | Technology |
|---|---|
| Backend API | FastAPI (Python) |
| ML Model | Hybrid Lexicon + Rule Engine |
| Frontend | React 18 + Recharts |
| Containerization | Docker + Docker Compose |
| CI/CD | GitHub Actions |
| Deployment | Render.com / Fly.io / Railway |
sentiment-analyzer/
βββ backend/
β βββ main.py # FastAPI application & routes
β βββ requirements.txt
βββ model/
β βββ predictor.py # ML prediction engine
βββ frontend/
β βββ src/
β β βββ App.jsx # Router & layout
β β βββ pages/
β β β βββ Analyze.jsx # Single text analysis
β β β βββ BatchAnalyze.jsx # Bulk analysis
β β β βββ Dashboard.jsx # Charts & metrics
β β βββ components/
β β β βββ ResultCard.jsx
β β β βββ HistoryPanel.jsx
β β βββ utils/api.js # API client
β βββ Dockerfile
β βββ package.json
βββ tests/
β βββ test_api.py # 17 unit + integration tests
βββ .github/workflows/ci.yml # GitHub Actions
βββ Dockerfile # Backend Docker image
βββ docker-compose.yml # Full stack orchestration
βββ render.yaml # Render.com deployment
βββ fly.toml # Fly.io deployment
# Clone & install backend
git clone https://github.com/yourname/sentiment-analyzer
cd sentiment-analyzer
pip install -r backend/requirements.txt
# Start backend
uvicorn backend.main:app --reload --port 8000
# In a new terminal β start frontend
cd frontend
npm install --legacy-peer-deps
npm startdocker-compose up --build- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Docs: http://localhost:8000/api/docs
Analyze a single text.
Request:
{
"text": "I absolutely love this product!",
"include_details": true
}Response:
{
"text": "I absolutely love this product!",
"sentiment": "Positive",
"confidence": 0.912,
"scores": { "positive": 0.87, "negative": 0.06, "neutral": 0.07 },
"emotions": { "joy": 1.0, "anticipation": 0.5 },
"keywords": ["love"],
"processing_time_ms": 2.1,
"timestamp": "2024-01-15T10:30:00"
}Analyze up to 50 texts at once.
Request:
{ "texts": ["I love this!", "This is terrible.", "Okay I guess."] }Service health check.
Usage statistics.
The prediction engine uses a hybrid approach:
- Tokenization β lowercasing, punctuation normalization
- Lexicon scoring β 100+ positive/negative words with sentiment weights
- Negation handling β detects NOT/NEVER patterns and inverts scores
- Intensifier amplification β "very", "extremely" etc. boost scores by 1.2β1.5Γ
- Sigmoid normalization β maps raw scores to [0,1] probability distributions
- Emotion detection β matches against 8 emotion lexicons
- Keyword extraction β identifies top sentiment-bearing terms
Upgrade path: Replace predictor.py's predict() with HuggingFace cardiffnlp/twitter-roberta-base-sentiment for state-of-the-art accuracy with zero API changes.
# Run full test suite (17 tests)
pytest tests/ -v
# With coverage
pytest tests/ --cov=backend --cov=model --cov-report=htmlTest categories:
TestPredictorβ 8 model unit tests (positive/negative/neutral/negation/intensifier)TestAPIβ 9 integration tests (all endpoints, validation, batch)
- Push to GitHub
- Go to render.com β New β Blueprint
- Connect your repo β Render will auto-detect
render.yaml - Set
REACT_APP_API_URLin frontend env to your backend URL
# Install flyctl
curl -L https://fly.io/install.sh | sh
# Deploy backend
fly launch
fly deploy
# Set env
fly secrets set ENV=production# Install Railway CLI
npm install -g @railway/cli
railway login
railway new
railway up- β Single text sentiment analysis with confidence scores
- β Batch analysis (up to 50 texts) with CSV export
- β 8-category emotion detection
- β Sentiment keyword extraction
- β Real-time dashboard with charts (Recharts)
- β Request history panel
- β
Interactive API docs (Swagger UI at
/api/docs) - β 17 automated tests (unit + integration)
- β Docker + Docker Compose support
- β GitHub Actions CI/CD pipeline
- β One-click deploy configs for Render, Fly.io, Railway
- β Sub-5ms response times
- β CORS-enabled for any frontend origin
Sentiment analysis is critical for businesses to understand customer feedback at scale. Manual analysis of thousands of reviews or social posts is infeasible.
Hybrid lexicon-based approach chosen for: zero training data requirement, interpretable decisions, sub-millisecond inference, and free deployment. Rule-based negation and intensifier handling addresses key weaknesses of pure bag-of-words models.
- 17/17 automated tests passing
- Correct classification of positive, negative, and neutral examples
- Proper negation inversion ("not good" β Negative)
- Emotion detection across 8 Plutchik-model categories
- Replace lexicon engine with fine-tuned RoBERTa transformer
- Add user authentication + persistent history
- Multilingual support
- Browser extension for real-time page analysis
- Taboada, M. et al. (2011). Lexicon-based methods for sentiment analysis. Computational Linguistics.
- Plutchik, R. (1980). A general psychoevolutionary theory of emotion. Academic Press.
- Hutto, C. & Gilbert, E. (2014). VADER: A parsimonious rule-based model for sentiment analysis. ICWSM.
- Liu, B. (2012). Sentiment analysis and opinion mining. Synthesis Lectures on HLT.