A powerful Flask-based API that performs sentiment analysis on course reviews. This tool uses a machine learning model trained on 1.4 million reviews to predict sentiment (Positive/Negative), extract meaningful keywords, and provide detailed analytics. It features a sleek, modern frontend for easy testing and robust API endpoints for integration with other applications.
Live Demo: https://course-review-sentiment-api.onrender.com
- High-Accuracy Predictions: Utilizes a Decision Tree model trained on a massive dataset, achieving a 98.7% test accuracy.
- Advanced NLP Processing: Employs Natural Language Processing (NLP) for intelligent text parsing, cleaning, and lemmatization.
- Intelligent Keyword Extraction: Identifies the most relevant keywords for each review and provides an aggregated list of top positive and negative keywords.
- In-Depth Analytics: Delivers a comprehensive dashboard showing total reviews, sentiment distribution, and the dominant sentiment.
- Dual-Mode Interface:
- Interactive UI: A simple, modern frontend for direct text input or file uploads (
.csv
,.txt
). - Developer API: Clean, accessible API endpoints for seamless integration into other projects.
- Interactive UI: A simple, modern frontend for direct text input or file uploads (
- Glassmorphic Design: A stunning dark theme with a grainy texture and orangish-red accents for a modern user experience.
- Backend: Python, Flask
- Machine Learning: Scikit-learn
- NLP: NLTK (Natural Language Toolkit)
- Data Handling: Pandas, NumPy
- Frontend: HTML5, CSS3, JavaScript
- Deployment: Render
Follow these instructions to get a local copy up and running for development and testing purposes.
- Python 3.8+
- pip (Python package installer)
-
Clone the repository:
git clone [https://github.com/dhruv-deb/course-review-sentiment-API.git](https://github.com/dhruv-deb/course-review-sentiment-API.git) cd course-review-sentiment-API
-
Create and activate a virtual environment:
- Windows:
python -m venv venv .\venv\Scripts\activate
- macOS / Linux:
python3 -m venv venv source venv/bin/activate
- Windows:
-
Install the required dependencies:
pip install -r requirements.txt
-
Download NLTK Data: The application is configured to download the necessary NLTK packages on the first run.
-
Run the Flask application:
python app.py
The application will be available at
http://127.0.0.1:5000
.
The API provides two main endpoints for programmatic access.
- Endpoint:
/api/analyze-text
- Method:
POST
- Body: Raw JSON
Example Request (cURL):
curl -X POST -H "Content-Type: application/json" \
-d '{"text": "This course was absolutely fantastic!"}' \
[http://127.0.0.1:5000/api/analyze-text](http://127.0.0.1:5000/api/analyze-text)
Example Response:
{
"text": "This course was absolutely fantastic!",
"sentiment": "Positive",
"confidence_label": 1.0,
"keywords": {
"positive": ["fantastic", "course"],
"negative": []
}
}
- Endpoint:
/api/analyze-file
- Method:
POST
- Body:
multipart/form-data
Example Request (cURL):
curl -X POST -F "file=@/path/to/your/reviews.csv" [http://127.0.0.1:5000/api/analyze-file](http://127.0.0.1:5000/api/analyze-file)
Example Response:
{
"filename": "reviews.csv",
"sentiment_results": [
{
"text": "Great content and clear explanations.",
"keywords": ["great", "content", "clear"],
"label": "Positive"
},
{
"text": "The instructor was boring and hard to follow.",
"keywords": ["boring", "hard"],
"label": "Negative"
}
],
"aggregate_sentiment": {
"total": 2,
"count": { "Positive": 1, "Negative": 1 },
"percent": { "Positive": "50.0%", "Negative": "50.0%" },
"most_common": "Positive"
},
"keywords_analysis": {
"top_positive_keywords": ["great", "content", "clear"],
"top_negative_keywords": ["boring", "hard"]
}
}
course-review-sentiment-API/
├── model/ # Contains the serialized ML model and vectorizers
│ ├── model_destree.pkl
│ ├── countVectorizer.pkl
│ └── scaler.pkl
├── nltk_data/ # Contains the nltk_data
├── static/ # CSS and other static assets
│ └── style.css
├── notebook/ # Contains the jupyter notebook with for training reference
│ └── Data_Exploration_&_Modelling.ipynb
├── templates/ # HTML templates for the frontend
│ └── index.html
├── app.py # Main Flask application file
├── utils.py # NLP processing and helper functions
├── requirements.txt # Project dependencies
└── README.md # This file
- Dhruv Deb - dhruv-deb