Spaces:
Runtime error
Runtime error
File size: 1,728 Bytes
bcfd653 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
---
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 `text` field
- **Output**: Prediction, confidence score, and sentiment label
### `/predict_proba`
- **Method**: POST
- **Input**: JSON with `text` field
- **Output**: Probability array, prediction, and sentiment label
### `/batch_predict`
- **Method**: POST
- **Input**: Array of text strings
- **Output**: Results for all input texts
## Usage Example
```python
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
1. Install dependencies: `pip install -r requirements.txt`
2. Run the app: `python app.py`
3. Visit `http://localhost:7860/docs` for interactive API documentation
|