""" XGBoost Busy Detector — HF Space App (FastAPI) Wraps the EndpointHandler in a FastAPI server for HF Spaces deployment. """ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from pydantic import BaseModel from typing import Dict, Optional app = FastAPI(title="XGBoost Busy Detector", version="1.0.0") app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Load handler on startup from handler import EndpointHandler handler = EndpointHandler(path=".") class PredictRequest(BaseModel): inputs: Dict # { "audio_features": {...}, "text_features": {...} } @app.get("/") async def root(): return { "service": "XGBoost Busy Detector", "version": "1.0.0", "endpoints": ["/predict", "/health"], } @app.get("/health") async def health(): return {"status": "healthy", "model_loaded": handler.model is not None} @app.post("/predict") async def predict(request: PredictRequest): """Run XGBoost inference with evidence accumulation scoring.""" result = handler({"inputs": request.inputs}) return result if __name__ == "__main__": import uvicorn import os port = int(os.environ.get("PORT", 7860)) uvicorn.run(app, host="0.0.0.0", port=port)