File size: 459 Bytes
d1e319b
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from fastapi import APIRouter
from schema.schemas import PredictionInput, PredictionOutput
from service.classifier import load_model, predict

router = APIRouter(prefix="/predict", tags=["Prediction"])

# Load the model once
model, vectorizer = load_model()

@router.post("/", response_model=PredictionOutput)
def make_prediction(input_data: PredictionInput):
    prediction = predict(input_data.text, model, vectorizer)
    return {"prediction": prediction}