Spaces:
Running
Running
added api calls
Browse files- app/main.py +5 -0
app/main.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import io
|
| 2 |
import json
|
|
|
|
| 3 |
import os
|
| 4 |
import random
|
| 5 |
import tempfile
|
|
@@ -82,6 +83,8 @@ def _predict_with_preprocess(image: Image.Image) -> dict:
|
|
| 82 |
@app.post("/api/predict")
|
| 83 |
async def predict(file: UploadFile = File(...)):
|
| 84 |
content_type = (file.content_type or "").lower()
|
|
|
|
|
|
|
| 85 |
raw = await file.read()
|
| 86 |
size_mb = len(raw) / (1024 * 1024)
|
| 87 |
|
|
@@ -171,6 +174,8 @@ async def report(
|
|
| 171 |
# Read the uploaded file
|
| 172 |
raw = await file.read()
|
| 173 |
content_type = (file.content_type or "").lower()
|
|
|
|
|
|
|
| 174 |
if content_type not in IMAGE_TYPES | VIDEO_TYPES | GIF_TYPES:
|
| 175 |
raise HTTPException(415, "Unsupported file type for reporting.")
|
| 176 |
|
|
|
|
| 1 |
import io
|
| 2 |
import json
|
| 3 |
+
import mimetypes
|
| 4 |
import os
|
| 5 |
import random
|
| 6 |
import tempfile
|
|
|
|
| 83 |
@app.post("/api/predict")
|
| 84 |
async def predict(file: UploadFile = File(...)):
|
| 85 |
content_type = (file.content_type or "").lower()
|
| 86 |
+
if content_type in ("", "application/octet-stream") and file.filename:
|
| 87 |
+
content_type = mimetypes.guess_type(file.filename)[0] or content_type
|
| 88 |
raw = await file.read()
|
| 89 |
size_mb = len(raw) / (1024 * 1024)
|
| 90 |
|
|
|
|
| 174 |
# Read the uploaded file
|
| 175 |
raw = await file.read()
|
| 176 |
content_type = (file.content_type or "").lower()
|
| 177 |
+
if content_type in ("", "application/octet-stream") and file.filename:
|
| 178 |
+
content_type = mimetypes.guess_type(file.filename)[0] or content_type
|
| 179 |
if content_type not in IMAGE_TYPES | VIDEO_TYPES | GIF_TYPES:
|
| 180 |
raise HTTPException(415, "Unsupported file type for reporting.")
|
| 181 |
|