File size: 716 Bytes
7ab594e
 
 
 
 
f584171
 
 
 
7ab594e
 
 
 
 
 
 
f584171
7ab594e
0a8d481
f584171
 
7ab594e
 
 
 
 
 
f584171
 
 
7ab594e
 
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
from fastapi import FastAPI
from pydantic import BaseModel
from fastapi.responses import RedirectResponse
from fastapi.staticfiles import StaticFiles

from inference import predict_emotions

app = FastAPI()

# app.add_middleware(
#     CORSMiddleware,
#     allow_origins=allowed_hosts,
#     allow_credentials=True,
#     allow_methods=["*"],
#     allow_headers=["*"],
# )

app.mount("/static", StaticFiles(directory='static', html=True))


@app.get('/')
async def redirect_to_static_index():
    return RedirectResponse(url='/static/index.html')


class EmotionRequest(BaseModel):
    text: str


@app.post('/predict_emotion')
async def predict(request: EmotionRequest):
    return predict_emotions(request.text)