Spaces:
No application file
No application file
Download main.py from hazardous/sentiment-analysis: direct link, hf CLI and curl.
- Browser
- Download file 871 Bytes
-
https://huggingface.co/spaces/hazardous/sentiment-analysis/resolve/main/main.py
- Command line
-
hf download hf://spaces/hazardous/sentiment-analysis/main.py
-
curl -L -o main.py https://huggingface.co/spaces/hazardous/sentiment-analysis/resolve/main/main.py
871 Bytes
| from fastapi import FastAPI | |
| from fastapi.openapi.utils import get_openapi | |
| from pydantic import BaseModel | |
| from classifier import Classifier | |
| class SentimentText(BaseModel): | |
| text: str | |
| app = FastAPI() | |
| def root(request: SentimentText): | |
| classfier = Classifier() | |
| prediction = classfier.classify(request.text) | |
| return {"sentiment": prediction} | |
| def endpoint_openapi(): | |
| if app.openapi_schema: | |
| return app.openapi_schema | |
| openapi_schema = get_openapi( | |
| title="Sentiment Analysis", | |
| version="2.5.0", | |
| description="This is the OpenAPI schema for the app", | |
| routes=app.routes, | |
| ) | |
| openapi_schema["info"]["x-logo"] = { | |
| "url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" | |
| } | |
| app.openapi_schema = openapi_schema | |
| return app.openapi_schema | |
| app.openapi = endpoint_openapi |