GitHub Actions
Deploy to Hugging Face Space: product-image-update-port-10
18faf97
# ----------------------------------------------------------------------
# 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")
)