Spaces:
Sleeping
Sleeping
Download api/art_classification.py from thesis-sd3a/digital-art-api: direct link, hf CLI and curl.
- Browser
- Download file 674 Bytes
-
https://huggingface.co/spaces/thesis-sd3a/digital-art-api/resolve/refs%2Fpr%2F3/api/art_classification.py
- Command line
-
hf download hf://spaces/thesis-sd3a/digital-art-api@refs/pr/3/api/art_classification.py
-
curl -L -o art_classification.py https://huggingface.co/spaces/thesis-sd3a/digital-art-api/resolve/refs%2Fpr%2F3/api/art_classification.py
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", | |
| ] | |
| 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) | |