This API provides endpoints for sentiment analysis for the following sources:
- Web page URLs
- Uploaded documents of file types
.txtand.csv - Directly provided sentences
The different sentiment types are:
| Sentiment Type | Polarity Value (p) |
|---|---|
| Postive | p > 0 |
| Negative | p < 0 |
| Neutral | p = 0 |
It uses:
- Flask: for the web framework
- TextBlob: for sentiment analysis
- NewsPaper: for downloading articles from the web
pip install nltk, flask, newspaper3k, textblobNote: This API is hosted here. You can use this link to test the endpoints as an alternative to local setup.
- Clone this repository
git clone https://github.com/Mimi97-aqua/sentiment_analysis.git
cd <repo-dir>- Create and activate virtual environment
python -m venv .venv
source .venv/Scripts/activate # On Windows OS- Install required packages
pip install -r requirements.txt
- Setup the upload folder
-
The upload folder is used for temporarily storing uploaded documents. The files in this folder are deleted after processing is over in order to free up space.
-
Ensure the
app/tmpdirectory exists or modify theupload_folderpath in the code to a directory of your choice.
- Start the Flask application
To achieve this, run main.py
- Endpoints
Base endpoint: /api
-
GET
/- Returns a welcome message.
-
GET
/web- Query paramter:
url(string) - Description: Analyzes the sentiment from the text of the provided webpage URL
- Response:
{ "status": "success", "sentiment": "positive" // or "negative" or "neutral" } - Query paramter:
-
POST
/doc- Form data:
file(file) - Description: Analyzes sentiment from the text of the uploaded document.
- Response:
{ "status": "success", "sentiment": "positive" // or "negative" or "neutral" } - Form data:
-
GET
/sentence- Query parameter:
sentence(string) - Description: Analyzes the sentiment from a provided sentence
- Response:
{ "status": "success", "sentiment": "positive" // or "negative" or "neutral" }
- Query parameter:
This API responds with appropriate error messages and status codes for issues such as missing parameters or invalid file types.
- Fork this repository and clone your fork.
- Create a new branch for your feature or bug fix.
- Submit a pull request with a clear description of your changes.