--- 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