Spaces:
Sleeping
Sleeping
Download app.py from anushka3306/sentiment-api: direct link, hf CLI and curl.
- Browser
- Download file 437 Bytes
-
https://huggingface.co/spaces/anushka3306/sentiment-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/anushka3306/sentiment-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/anushka3306/sentiment-api/resolve/main/app.py
437 Bytes
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from transformers import pipeline | |
| app = FastAPI() | |
| classifier = pipeline("sentiment-analysis") | |
| class TextRequest(BaseModel): | |
| text: str | |
| async def predict(request: TextRequest): | |
| result = classifier(request.text)[0] | |
| return {"label": result["label"], "score": result["score"]} | |
| async def health(): | |
| return {"status": "ok"} |