Spaces:
Running on Zero
Running on Zero
feat: implement fallback to video loading if image processing fails in file handling logic
Browse files
app.py
CHANGED
|
@@ -224,7 +224,13 @@ def predict(
|
|
| 224 |
h_content = []
|
| 225 |
if turn_files:
|
| 226 |
for f_path in turn_files:
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
if user_text:
|
| 230 |
h_content.append({"type": "text", "text": user_text})
|
|
@@ -238,22 +244,17 @@ def predict(
|
|
| 238 |
if files:
|
| 239 |
for f in files:
|
| 240 |
file_path = f["path"]
|
| 241 |
-
# Detect if video or image
|
| 242 |
-
is_video = False
|
| 243 |
try:
|
| 244 |
-
#
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
content.append({"type": "video", "video": frames})
|
| 255 |
-
else:
|
| 256 |
-
content.append({"type": "image", "image": Image.open(file_path).convert("RGB")})
|
| 257 |
|
| 258 |
if message:
|
| 259 |
content.append({"type": "text", "text": message})
|
|
|
|
| 224 |
h_content = []
|
| 225 |
if turn_files:
|
| 226 |
for f_path in turn_files:
|
| 227 |
+
try:
|
| 228 |
+
img = Image.open(f_path).convert("RGB")
|
| 229 |
+
h_content.append({"type": "image", "image": img})
|
| 230 |
+
except Exception:
|
| 231 |
+
v_frames = load_video(f_path, max_frames=max_frames)
|
| 232 |
+
if v_frames:
|
| 233 |
+
h_content.append({"type": "video", "video": v_frames})
|
| 234 |
|
| 235 |
if user_text:
|
| 236 |
h_content.append({"type": "text", "text": user_text})
|
|
|
|
| 244 |
if files:
|
| 245 |
for f in files:
|
| 246 |
file_path = f["path"]
|
|
|
|
|
|
|
| 247 |
try:
|
| 248 |
+
# Try opening as image first
|
| 249 |
+
img = Image.open(file_path).convert("RGB")
|
| 250 |
+
content.append({"type": "image", "image": img})
|
| 251 |
+
except Exception:
|
| 252 |
+
# If image fails, try as video
|
| 253 |
+
v_frames = load_video(file_path, max_frames=max_frames)
|
| 254 |
+
if v_frames:
|
| 255 |
+
content.append({"type": "video", "video": v_frames})
|
| 256 |
+
else:
|
| 257 |
+
print(f"Failed to identify file type for: {file_path}")
|
|
|
|
|
|
|
|
|
|
| 258 |
|
| 259 |
if message:
|
| 260 |
content.append({"type": "text", "text": message})
|