digital-art-api / api /art_classification.py
Hrudge's picture Natsuna's picture
Added new MIME types (#3)
ea93233
Raw History Blame Contribute Delete
674 Bytes
from fastapi import APIRouter, UploadFile, File, HTTPException, status
from lib.hugging_face import classify_art
router = APIRouter()
ALLOWED_TYPES = [
"image/jpeg",
"image/jpg",
"image/png",
"image/webp",
"image/avif",
"image/gif",
"image/bmp",
"image/tiff",
"image/svg+xml",
]
@router.post("/")
async def classify(file: UploadFile = File(...)):
if file.content_type not in ALLOWED_TYPES:
raise HTTPException(
status_code=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
detail=f"Unsupported file type: {file.content_type}. Allowed: {', '.join(ALLOWED_TYPES)}"
)
return await classify_art(file)