Base URL: http://localhost:8000/api
POST /sentiment/analyze/
Analyzes the sentiment of a review text.
Request Body:
{
"review_text": "সিনেমাটা অসাধারণ ছিল!"
}Response:
{
"id": 1,
"sentiment": "Positive",
"confidence": 85.5,
"word_importance": [
{"word": "অসাধারণ", "score": 0.456},
{"word": "ছিল", "score": 0.123}
],
"colored_html": [
{
"word": "সিনেমাটা",
"score": 0.045,
"color": "rgba(200, 200, 200, 0.2)",
"effect": "neutral"
},
{
"word": "অসাধারণ",
"score": 0.456,
"color": "rgba(0, 200, 0, 0.7)",
"effect": "positive"
}
]
}Status Codes:
200 OK- Success400 Bad Request- Invalid input500 Internal Server Error- Analysis failed
GET /sentiment/history/
Returns the last 20 sentiment analyses.
Response:
[
{
"id": 1,
"review_text": "সিনেমাটা অসাধারণ ছিল!",
"sentiment": "Positive",
"confidence": 85.5,
"word_importance": [...],
"created_at": "2024-01-15T10:30:00Z"
}
]GET /sentiment/
Returns all sentiment analyses (paginated).
Response:
{
"count": 50,
"next": "http://localhost:8000/api/sentiment/?page=2",
"previous": null,
"results": [...]
}GET /sentiment/{id}/
Returns a specific analysis by ID.
Response:
{
"id": 1,
"review_text": "সিনেমাটা অসাধারণ ছিল!",
"sentiment": "Positive",
"confidence": 85.5,
"word_importance": [...],
"created_at": "2024-01-15T10:30:00Z"
}# Analyze sentiment
curl -X POST http://localhost:8000/api/sentiment/analyze/ \
-H "Content-Type: application/json" \
-d '{"review_text": "সিনেমাটা অসাধারণ ছিল!"}'
# Get history
curl http://localhost:8000/api/sentiment/history/// Analyze sentiment
const response = await fetch('http://localhost:8000/api/sentiment/analyze/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
review_text: 'সিনেমাটা অসাধারণ ছিল!'
})
});
const data = await response.json();
console.log(data);import requests
# Analyze sentiment
response = requests.post(
'http://localhost:8000/api/sentiment/analyze/',
json={'review_text': 'সিনেমাটা অসাধারণ ছিল!'}
)
print(response.json())
# Get history
response = requests.get('http://localhost:8000/api/sentiment/history/')
print(response.json())| Field | Type | Description |
|---|---|---|
id |
integer | Unique identifier |
review_text |
string | Original review text |
sentiment |
string | "Positive", "Negative", or "Neutral" |
confidence |
float | Confidence score (0-100) |
word_importance |
array | List of important words with scores |
colored_html |
array | Word-by-word visualization data |
created_at |
datetime | Timestamp of analysis |
| Field | Type | Description |
|---|---|---|
word |
string | The word |
score |
float | Importance score (-1 to 1) |
Positive score = makes sentiment more positive Negative score = makes sentiment more negative
| Field | Type | Description |
|---|---|---|
word |
string | The word |
score |
float | Importance score |
color |
string | RGBA color for visualization |
effect |
string | "positive", "negative", or "neutral" |
{
"review_text": ["This field is required."]
}{
"error": "Model loading failed"
}Currently no rate limiting. For production, consider adding:
- Django REST Framework throttling
- Redis-based rate limiting
- API key authentication
CORS is enabled for:
http://localhost:3000http://127.0.0.1:3000
To add more origins, edit backend/config/settings.py:
CORS_ALLOWED_ORIGINS = [
"http://localhost:3000",
"http://your-domain.com",
]