Spaces:
Sleeping
Sleeping
Added new MIME types
#3
by Natsuna - opened
- api/art_classification.py +17 -1
api/art_classification.py
CHANGED
|
@@ -3,7 +3,23 @@ from lib.hugging_face import classify_art
|
|
| 3 |
|
| 4 |
router = APIRouter()
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
@router.post("/")
|
| 7 |
async def classify(file: UploadFile = File(...)):
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
return await classify_art(file)
|
|
|
|
| 3 |
|
| 4 |
router = APIRouter()
|
| 5 |
|
| 6 |
+
ALLOWED_TYPES = [
|
| 7 |
+
"image/jpeg",
|
| 8 |
+
"image/jpg",
|
| 9 |
+
"image/png",
|
| 10 |
+
"image/webp",
|
| 11 |
+
"image/avif",
|
| 12 |
+
"image/gif",
|
| 13 |
+
"image/bmp",
|
| 14 |
+
"image/tiff",
|
| 15 |
+
"image/svg+xml",
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
@router.post("/")
|
| 19 |
async def classify(file: UploadFile = File(...)):
|
| 20 |
+
if file.content_type not in ALLOWED_TYPES:
|
| 21 |
+
raise HTTPException(
|
| 22 |
+
status_code=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
|
| 23 |
+
detail=f"Unsupported file type: {file.content_type}. Allowed: {', '.join(ALLOWED_TYPES)}"
|
| 24 |
+
)
|
| 25 |
return await classify_art(file)
|