Spaces:
Running
Running
| from __future__ import annotations | |
| from fastapi import FastAPI, HTTPException | |
| from schemas import HealthResponse, PredictRequest, PredictResponse | |
| from service import TimesFmService | |
| app = FastAPI(title="TimesFm Space", version="0.1.0") | |
| service = TimesFmService() | |
| def health() -> HealthResponse: | |
| return service.health() | |
| def root() -> dict[str, str]: | |
| return {"service": "timesfm", "status": "ok"} | |
| 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 - API guardrail | |
| raise HTTPException(status_code=500, detail=f"prediction_failed: {exc}") from exc | |