Spaces:
Sleeping
Sleeping
File size: 802 Bytes
492754f | 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 34 | 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")
@app.get("/")
def home():
return {"message": "BBC Document Classification API is running"}
@app.get("/health")
def health():
return {"status": "healthy"}
@app.post("/predict", response_model=PredictionResponse)
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)
} |