Spaces:
Sleeping
Sleeping
Download api/supplement.py from BOWOWEEEEE/pill-advisor-backend: direct link, hf CLI and curl.
- Browser
- Download file 976 Bytes
-
https://huggingface.co/spaces/BOWOWEEEEE/pill-advisor-backend/resolve/main/api/supplement.py
- Command line
-
hf download hf://spaces/BOWOWEEEEE/pill-advisor-backend/api/supplement.py
-
curl -L -o supplement.py https://huggingface.co/spaces/BOWOWEEEEE/pill-advisor-backend/resolve/main/api/supplement.py
976 Bytes
| from typing import Any | |
| from fastapi import APIRouter, File, Header, HTTPException, UploadFile | |
| from api.detect import extract_user_id, get_supabase | |
| from middleware.rate_limit import check_daily_limit | |
| from services import gemini as gemini_service | |
| router = APIRouter() | |
| async def supplement( | |
| image: UploadFile = File(...), | |
| authorization: str = Header(...), | |
| ) -> dict[str, Any]: | |
| """ | |
| 보충제 이미지를 Gemini Vision으로 분석해 성분 목록과 복용 가이드를 반환한다. | |
| """ | |
| if not authorization.startswith("Bearer "): | |
| raise HTTPException(status_code=401, detail="Authorization 헤더가 올바르지 않습니다.") | |
| token = authorization.removeprefix("Bearer ").strip() | |
| db = get_supabase() | |
| user_id = extract_user_id(token, db) | |
| await check_daily_limit(user_id, db) | |
| image_bytes = await image.read() | |
| result = await gemini_service.supplement_ocr(image_bytes) | |
| return result | |