Spaces:
Running
Running
| from uuid import UUID | |
| from fastapi import Header, HTTPException, Request | |
| from .db.engine import SessionLocal | |
| def get_device_id(x_device_id: str = Header(..., alias="X-Device-Id")) -> UUID: | |
| try: | |
| return UUID(x_device_id) | |
| except ValueError: | |
| raise HTTPException( | |
| status_code=400, | |
| detail={"error": "MISSING_DEVICE_ID", "message": "X-Device-Id must be a valid UUID"}, | |
| ) | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |
| def get_whisper(request: Request): | |
| bundle = getattr(request.app.state, "whisper", None) | |
| primary = bundle.get("primary") if isinstance(bundle, dict) else bundle | |
| if primary is None: | |
| raise HTTPException( | |
| status_code=503, | |
| detail={"error": "MODEL_NOT_READY", "message": "Whisper model is warming up"}, | |
| ) | |
| return bundle | |
| def get_clf(request: Request): | |
| clf = getattr(request.app.state, "clf", None) | |
| if clf is None: | |
| raise HTTPException( | |
| status_code=503, | |
| detail={"error": "MODEL_NOT_READY", "message": "Classifier is warming up"}, | |
| ) | |
| return clf | |