File size: 855 Bytes
1d0bd99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 typing import Dict

from fastapi import Depends, FastAPI, HTTPException, Query
from pydantic import BaseModel

from .classifier.model import Model, get_model

app = FastAPI()


class SentimentResponse(BaseModel):
    probabilities: Dict[str, float]
    sentiment: str
    confidence: float


@app.get("/")
def read_root():
    return {"TrueFoundry": "Internship Project"}


@app.post("/predict", response_model=SentimentResponse)
def predict(review:str = Query(None, title="Airline Review", decription="Enter the review for airline"), model: Model = Depends(get_model)):
    if type(review) != str:
        raise HTTPException(status_code=404, detail="Bad request")
    sentiment, confidence, probabilities = model.predict(review)
    return SentimentResponse(
        sentiment=sentiment, confidence=confidence, probabilities=probabilities
    )