Spaces:
Runtime error
Runtime error
| from fastapi import APIRouter, UploadFile, File, Depends | |
| from PIL import Image | |
| from prediction.domain.domain import SegmentationResult, ClassificationResult, DetectionResult, FullPredictionResult | |
| from auth.service.auth_service import auth | |
| from io import BytesIO | |
| from prediction.service.PetPredictionService import PetPredictionService | |
| from fastapi.security import OAuth2PasswordBearer | |
| from sqlalchemy.orm import Session | |
| from database import get_db | |
| oauth2_scheme = OAuth2PasswordBearer(tokenUrl="login") | |
| router = APIRouter() | |
| async def predict_full( | |
| file: UploadFile = File(...), | |
| token: str = Depends(oauth2_scheme), | |
| db: Session = Depends(get_db) | |
| ): | |
| user = auth(token, db) | |
| contents = await file.read() | |
| image = Image.open(BytesIO(contents)).convert("RGB") | |
| return PetPredictionService().full_pet_prediction(image) | |
| async def predict_classification( | |
| file: UploadFile = File(...), | |
| token: str = Depends(oauth2_scheme), | |
| db: Session = Depends(get_db) | |
| ): | |
| user = auth(token, db) | |
| contents = await file.read() | |
| image = Image.open(BytesIO(contents)).convert("RGB") | |
| return PetPredictionService().classify(image) | |
| async def predict_detection( | |
| file: UploadFile = File(...), | |
| token: str = Depends(oauth2_scheme), | |
| db: Session = Depends(get_db) | |
| ): | |
| user = auth(token, db) | |
| contents = await file.read() | |
| image = Image.open(BytesIO(contents)).convert("RGB") | |
| return PetPredictionService().detect(image) | |
| async def predict_segmentation( | |
| file: UploadFile = File(...), | |
| token: str = Depends(oauth2_scheme), | |
| db: Session = Depends(get_db) | |
| ): | |
| user = auth(token, db) | |
| contents = await file.read() | |
| image = Image.open(BytesIO(contents)).convert("RGB") | |
| return PetPredictionService().segment(image) |