Upload folder using huggingface_hub
Browse files12 unmodified lines13141516171819124 unmodified lines14414514614714814915057 unmodified lines20820921021121221321410 unmodified lines22522622712 unmodified linesfrom contextlib import asynccontextmanagerfrom pathlib import Pathfrom fastapi import FastAPI, HTTPException, Request, statusfrom fastapi.responses import JSONResponsefrom api import db, settings124 unmodified lines@app.post("/predict", response_model=PredictionResponse, tags=["scoring"])async def predict(payload: PredictionRequest, request: Request) -> PredictionResponse:raw_inputs = payload.model_dump()sk_id = raw_inputs.pop("SK_ID_CURR")57 unmodified linesplumbing_ms = max(0, latency_ms - feature_assembly_ms - inference_ms)else:plumbing_ms = Nonelog_prediction(sk_id_curr=sk_id,client_known=client_known,raw_input=raw_inputs,10 unmodified linesstatus_code=status_code,error_message=error_message,)12 unmodified lines13141516171819124 unmodified lines14414514614714814915015115215315457 unmodified lines21221321421521621721810 unmodified lines22923023123223323423523623723823924024124212 unmodified linesfrom contextlib import asynccontextmanagerfrom pathlib import Pathfrom fastapi import BackgroundTasks, FastAPI, HTTPException, Request, statusfrom fastapi.responses import JSONResponsefrom api import db, settings124 unmodified lines@app.post("/predict", response_model=PredictionResponse, tags=["scoring"])async def predict(payload: PredictionRequest,request: Request,background_tasks: BackgroundTasks,) -> PredictionResponse:raw_inputs = payload.model_dump()sk_id = raw_inputs.pop("SK_ID_CURR")57 unmodified linesplumbing_ms = max(0, latency_ms - feature_assembly_ms - inference_ms)else:plumbing_ms = Nonelog_kwargs: dict[str, object | None] = dict(sk_id_curr=sk_id,client_known=client_known,raw_input=raw_inputs,10 unmodified linesstatus_code=status_code,error_message=error_message,)# Success: defer the Supabase round-trip until AFTER the response# is sent, so the client never waits on ~350 ms of DB log overhead.# Failure: log synchronously — BackgroundTasks scheduled on a route# are attached to its Response, and the exception-handler chain# builds its own Response, silently dropping pending tasks. Losing# observability on errors would be a worse trade-off than the# one-shot latency hit paid by failing requests.if status_code < 400:background_tasks.add_task(log_prediction, **log_kwargs)else:log_prediction(**log_kwargs)
api/main.py+18-3