File size: 871 Bytes
94e649c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()

@app.get("/")
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