An AI-powered web application that analyses restaurant reviews and predicts whether the sentiment is positive or negative, complete with confidence scores and witty chef responses.
| Feature | Description |
|---|---|
| Sentiment Analysis | Multinomial Naive Bayes classifier trained on 1 000 restaurant reviews |
| Confidence Score | Probability-based confidence meter for every prediction |
| Voice Input | Speak your review using the browser's Speech Recognition API |
| Modern UI | Dark glassmorphism design with micro-animations (no Bootstrap) |
| FastAPI Backend | High-performance async Python backend |
| Docker Ready | Multi-stage Dockerfile for one-command deployment |
| Security | Non-root Docker user, env-based config, input validation |
+-------------------------------+ POST /api/predict +-----------------------------+
| React Frontend | <-------------------> | FastAPI Backend |
| (Vite + JSX) | JSON | (Uvicorn) |
| | | |
| - Client Validation | | - TF-IDF Vectoriser |
| - Voice Input | | - MNB Classifier |
| - Animated Results | | - Error Handling |
+-------------------------------+ +-----------------------------+
For full model documentation including architecture rationale, hyperparameter details, evaluation metrics, limitations, and future improvements, see MODEL.md.
- Algorithm: Multinomial Naive Bayes (alpha=0.2)
- Features: TF-IDF Vectoriser with auto-selected vocabulary size
- Preprocessing: Text cleaning, contraction expansion, stop-word removal, lemmatisation
- Metrics: Accuracy ~77-79%, ROC-AUC ~0.84-0.86
- Python 3.11+
- Node.js 18+
- pip
git clone https://github.com/Ishwarpatra/Restaurant-Reviews-Sentiment-Analysis-Deployment.git
cd Restaurant-Reviews-Sentiment-Analysis-Deployment
pip install -r requirements.txtpython "Restaurant Reviews Sentiment Analyser - Deployment.py"This will:
- Run vocabulary size analysis
- Train the final model with optimal features
- Print full evaluation metrics
- Save
cv-transform.pklandrestaurant-sentiment-mnb-model.pkl
python data_validation.pypython hyperparameter_tuning.pyRuns GridSearchCV with cross-validation over alpha and max_features.
cd client
npm install
npm run build
cd ..python main.pyOpen http://localhost:5000 in your browser.
| Variable | Default | Description |
|---|---|---|
DEBUG |
false |
Enable debug mode & CORS wildcard |
PORT |
5000 |
Server port |
ALLOWED_ORIGINS |
http://localhost:5173 |
Comma-separated CORS origins |
# Build the image
docker build -t restaurant-sentiment .
# Run the container
docker run -p 5000:5000 -e DEBUG=false restaurant-sentimentWorks on any cloud provider -- AWS ECS, Azure Container Instances, GCP Cloud Run, DigitalOcean, etc.
# Install test dependencies (already in requirements.txt)
pip install pytest pytest-asyncio pytest-cov httpx
# Run all tests
pytest
# Run with coverage report
pytest --cov=. --cov-report=term-missing
# Run a specific test file
pytest tests/test_api.py -v├── main.py # FastAPI backend (API + static file serving)
├── preprocess.py # Text preprocessing module
├── data_validation.py # Dataset quality checks
├── hyperparameter_tuning.py # GridSearchCV tuning script
├── Restaurant Reviews Sentiment
│ Analyser - Deployment.py # Training & evaluation script
├── Restaurant_Reviews.tsv # Dataset (1 000 reviews)
├── restaurant-sentiment-mnb-model.pkl # Trained classifier
├── cv-transform.pkl # Fitted TF-IDF vectoriser
├── requirements.txt # Python dependencies
├── environment.yml # Conda environment definition
├── Dockerfile # Multi-stage Docker build
├── Procfile # Heroku / PaaS entrypoint
├── render.yaml # Render.com deployment config
├── MODEL.md # Model architecture documentation
├── CONTRIBUTING.md # Contribution guidelines
├── tests/ # Test suite (pytest)
│ ├── conftest.py # Shared fixtures
│ ├── test_preprocess.py # Preprocessing tests
│ ├── test_api.py # API endpoint tests
│ └── test_data_validation.py # Data validation tests
├── models/ # Versioned model artefacts
│ └── README.md # Versioning instructions
├── client/ # React frontend (Vite)
│ ├── index.html
│ ├── package.json
│ ├── vite.config.js
│ └── src/
│ ├── main.jsx
│ ├── App.jsx
│ ├── index.css
│ └── components/
│ ├── Navbar.jsx
│ └── Footer.jsx
└── README.md
- No
debug=Truein production -- Debug mode is toggled via theDEBUGenv var (defaults tofalse) - CORS -- Only allows configured origins in production; wildcard only in debug mode
- Input Validation -- Server-side via Pydantic validators + client-side JS validation
- Docker -- Runs as non-root
appuser - Dependencies -- Pinned to latest stable versions
See CONTRIBUTING.md for setup instructions, coding standards, testing guidelines, and PR process.
| Method | Command |
|---|---|
| pip | pip install -r requirements.txt |
| conda | conda env create -f environment.yml |
| Docker | docker build -t restaurant-sentiment . |
Model versioning is done via the models/ directory. See models/README.md for conventions.
MIT (c) Ishwarpatra
Star this repo if it helped you!
