File size: 495 Bytes
2bbbb9f
 
85d35cd
 
2bbbb9f
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from ..models.nlp_model import classify_text  # Relative import


router = APIRouter()

class SMSInput(BaseModel):
    text: str

@router.post("/predict")
async def predict_sms(input: SMSInput):
    try:
        prediction = classify_text(input.text)
        return {"text": input.text, "prediction": prediction}
    except Exception as e:
        raise HTTPException(status_code=500, detail="Model prediction error.")