Serving (FastAPI)
Despliegue realtime con FastAPI y opción batch. Integración fácil con API Gateway.
server.py – ejemplo simple de serving con FastAPI
from fastapi import FastAPI
import joblib
import pandas as pd
from xgboost import DMatrix
app = FastAPI()
model = joblib.load("models/production/model.pkl")
@app.post("/predict")
def predict(payload: dict):
X = pd.DataFrame([payload["data"]])
d = DMatrix(X)
pred = model.predict(d)
return {"prediction": float(pred[0])}