Spaces:
Running
Running
File size: 1,002 Bytes
effed4a | 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 | from __future__ import annotations
from fastapi import FastAPI, HTTPException
from schemas import HealthResponse, PredictRequest, PredictResponse
from service import ChronosService
app = FastAPI(title="Chronos Space", version="0.1.0")
service = ChronosService()
@app.get("/health", response_model=HealthResponse)
def health() -> HealthResponse:
return service.health()
@app.get("/")
def root() -> dict[str, str]:
return {"service": "chronos", "status": "ok"}
@app.post("/predict", response_model=PredictResponse)
def predict(payload: PredictRequest) -> PredictResponse:
try:
return service.predict(payload)
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
except RuntimeError as exc:
raise HTTPException(status_code=503, detail=str(exc)) from exc
except Exception as exc: # pragma: no cover
raise HTTPException(status_code=500, detail="prediction_failed") from exc
|