Spaces:
Sleeping
Sleeping
| import joblib | |
| import numpy as np | |
| from fastapi import FastAPI | |
| from src.api.schemas import PredictionRequest, PredictionResponse | |
| app = FastAPI( | |
| title="BBC Document Classification API", | |
| version="1.0.0" | |
| ) | |
| model = joblib.load("models/best_model.pkl") | |
| def home(): | |
| return {"message": "BBC Document Classification API is running"} | |
| def health(): | |
| return {"status": "healthy"} | |
| def predict(request: PredictionRequest): | |
| prediction = model.predict([request.text])[0] | |
| decision_scores = model.decision_function([request.text]) | |
| confidence_score = float(np.max(decision_scores)) | |
| return { | |
| "predicted_class": prediction, | |
| "confidence_score": round(confidence_score, 4) | |
| } |