Spaces:
Sleeping
Sleeping
Download app.py from hugsatya/sentiment-api: direct link, hf CLI and curl.
- Browser
- Download file 530 Bytes
-
https://huggingface.co/spaces/hugsatya/sentiment-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/hugsatya/sentiment-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/hugsatya/sentiment-api/resolve/main/app.py
530 Bytes
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from transformers import pipeline | |
| app = FastAPI() | |
| # Load pretrained sentiment model | |
| classifier = pipeline("sentiment-analysis") | |
| # Input format | |
| class TextRequest(BaseModel): | |
| text: str | |
| async def root(): | |
| return {"message": "Sentiment API is running"} | |
| async def predict(request: TextRequest): | |
| result = classifier(request.text)[0] | |
| return { | |
| "label": result["label"], | |
| "score": float(result["score"]) | |
| } |