Spaces:
Runtime error
Runtime error
fix(api): remove hardcoded multipart Content-Type header and refine multi-image file list extraction
Browse files- app/api/attendance.py +22 -4
app/api/attendance.py
CHANGED
|
@@ -47,11 +47,29 @@ async def analyze_classroom_photo(
|
|
| 47 |
if not subject:
|
| 48 |
raise HTTPException(status_code=404, detail="Subject not found.")
|
| 49 |
|
| 50 |
-
# Gather all uploaded files
|
| 51 |
uploaded_files: List[UploadFile] = []
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
if not uploaded_files:
|
| 57 |
raise HTTPException(status_code=400, detail="No classroom photo uploaded.")
|
|
|
|
| 47 |
if not subject:
|
| 48 |
raise HTTPException(status_code=404, detail="Subject not found.")
|
| 49 |
|
| 50 |
+
# Gather all uploaded files cleanly without duplicate files
|
| 51 |
uploaded_files: List[UploadFile] = []
|
| 52 |
+
|
| 53 |
+
# 1. Check primary 'files' list (for multi-image analysis)
|
| 54 |
+
files_list = form_data.getlist("files")
|
| 55 |
+
if files_list:
|
| 56 |
+
for item in files_list:
|
| 57 |
+
if hasattr(item, "filename") and item.filename:
|
| 58 |
+
uploaded_files.append(item)
|
| 59 |
+
|
| 60 |
+
# 2. Fallback to 'file' if 'files' was not provided
|
| 61 |
+
if not uploaded_files:
|
| 62 |
+
file_list = form_data.getlist("file")
|
| 63 |
+
for item in file_list:
|
| 64 |
+
if hasattr(item, "filename") and item.filename:
|
| 65 |
+
uploaded_files.append(item)
|
| 66 |
+
|
| 67 |
+
# 3. Fallback to scanning all values in form_data
|
| 68 |
+
if not uploaded_files:
|
| 69 |
+
for key, value in form_data.multi_items():
|
| 70 |
+
if hasattr(value, "filename") and value.filename:
|
| 71 |
+
if value not in uploaded_files:
|
| 72 |
+
uploaded_files.append(value)
|
| 73 |
|
| 74 |
if not uploaded_files:
|
| 75 |
raise HTTPException(status_code=400, detail="No classroom photo uploaded.")
|