https://github.com/fahadulshadhin/sentiment_analysis_api
Sentiment Analysis API
https://github.com/fahadulshadhin/sentiment_analysis_api
django django-rest-framework python-3
Last synced: 10 months ago
JSON representation
Sentiment Analysis API
- Host: GitHub
- URL: https://github.com/fahadulshadhin/sentiment_analysis_api
- Owner: FahadulShadhin
- Created: 2023-06-16T12:59:40.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-21T16:59:37.000Z (almost 3 years ago)
- Last Synced: 2025-07-22T22:37:42.405Z (11 months ago)
- Topics: django, django-rest-framework, python-3
- Language: Python
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sentiment Analysis API
This API accepts a text input and returns the sentiment analysis result using a pre-trained ML model.
## Used Pre Trained Model:
[https://huggingface.co/finiteautomata/bertweet-base-sentiment-analysis](https://huggingface.co/finiteautomata/bertweet-base-sentiment-analysis)
### Installation:
- Transformers:
```bash
pip install transformers
```
- Transformers and Pytorch:
```bash
pip install 'transformers[torch]'
```
- Transformers and Flax:
```bash
pip install 'transformers[flax]'
```
### Usage:
```Python
from transformers import pipeline
model = pipeline("sentiment-analysis", model="finiteautomata/bertweet-base-sentiment-analysis")
pred = model('I am happy today!')
```
```Python
print(pred)
>> [{'label': 'POS','score': 0.99250328540802}]
```
---
## Endpoint:
| Method | URL | Description |
| :----- | :------------- | :--------------------------------------------------------------------------- |
| POST | `/api/analyze` | Return the sentiment result of the request text as positive/neutral/negative |
## Example:
### Request:
```json
{
"text": "I am so happy!"
}
```
### Response:
```json
{
"status": "success",
"data": {
"text": "I am so happy!",
"sentiment": "positive"
}
}
```
## Project Setup:
### Install Dependencies:
```bash
pip install -r requirements.txt
```
### Make Migrations:
```bash
python manage.py makemigrations
```
```bash
python manage.py migrate
```
### Run server:
```bash
python manage.py runserver
```
### Test the API:
```
http://127.0.0.1:8000/api/analyze/
```
## Project Structure:
```
.
├── api # main app for sentiment API
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── serializers.py
│ ├── tests.py
│ ├── urls.py
│ ├── utils.py # pre-trained model used here
│ └── views.py
├── manage.py
└── sentiment_analysis # root directory of the project
├── __init__.py
├── asgi.py
├── settings.py
├── urls.py
└── wsgi.py
```