Spaces:
Runtime error
Runtime error
metadata
title: Sentiment Analysis API
emoji: 😊
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit
Sentiment Analysis API
A FastAPI-based sentiment analysis service that predicts sentiment (positive/negative) from text input.
Features
- Sentiment Prediction: Get integer predictions (0 for negative, 1 for positive)
- Probability Scores: Get prediction probabilities for both classes
- Batch Processing: Analyze multiple texts at once
- Interactive API: Swagger UI documentation available at
/docs
API Endpoints
/predict
- Method: POST
- Input: JSON with
textfield - Output: Prediction, confidence score, and sentiment label
/predict_proba
- Method: POST
- Input: JSON with
textfield - Output: Probability array, prediction, and sentiment label
/batch_predict
- Method: POST
- Input: Array of text strings
- Output: Results for all input texts
Usage Example
import requests
# Single prediction
response = requests.post(
"https://your-space-url/predict",
json={"text": "I love this movie!"}
)
print(response.json())
# Output: {"prediction": 1, "confidence": 0.95, "sentiment": "positive"}
# Probability prediction
response = requests.post(
"https://your-space-url/predict_proba",
json={"text": "This is terrible"}
)
print(response.json())
# Output: {"probabilities": [0.85, 0.15], "prediction": 0, "sentiment": "negative"}
Local Development
- Install dependencies:
pip install -r requirements.txt - Run the app:
python app.py - Visit
http://localhost:7860/docsfor interactive API documentation