Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,619 Bytes
18faf97 |
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# ----------------------------------------------------------------------
# API ROUTES
# ----------------------------------------------------------------------
from fastapi import APIRouter, HTTPException
from typing import List, Dict, Any, Union
from src.config import (
HTTP_OK,
HTTP_BAD_REQUEST,
ERROR_INVALID_PAYLOAD,
ERROR_NO_VALID_URLS
)
# ----------------------------------------------------------------------
# ROUTER SETUP
# ----------------------------------------------------------------------
router = APIRouter(prefix="/api", tags=["processing"])
# ----------------------------------------------------------------------
# ROUTE HANDLERS
# ----------------------------------------------------------------------
@router.get("/status")
async def get_status():
from src.models.model_loader import MODELS_LOADED, DEVICE
from src.utils import get_system_info
return {
"status": "online",
"models_loaded": MODELS_LOADED,
"device": DEVICE,
"system": get_system_info()
}
@router.post("/process")
async def process_images(payload: Dict[str, Any]):
if "urls" not in payload:
raise HTTPException(
status_code=HTTP_BAD_REQUEST,
detail=ERROR_INVALID_PAYLOAD
)
urls = payload.get("urls", [])
if not urls:
raise HTTPException(
status_code=HTTP_BAD_REQUEST,
detail=ERROR_NO_VALID_URLS
)
from app import process_images as process_fn
return process_fn(
urls=urls,
product_type=payload.get("product_type", "General")
)
|