Spaces:
Runtime error
Runtime error
Update core/input_handler.py
Browse files- core/input_handler.py +18 -3
core/input_handler.py
CHANGED
|
@@ -139,15 +139,30 @@ def resolve_input(mode, media_upload, url):
|
|
| 139 |
"""
|
| 140 |
try:
|
| 141 |
logger.info(f"Resolving input for mode: {mode}")
|
|
|
|
| 142 |
|
| 143 |
if mode == "Upload":
|
| 144 |
if not media_upload:
|
| 145 |
logger.warning("No upload detected.")
|
| 146 |
return None
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
if image_files and video_files:
|
| 152 |
logger.warning("Mixed media upload not supported (images + video).")
|
| 153 |
return None
|
|
|
|
| 139 |
"""
|
| 140 |
try:
|
| 141 |
logger.info(f"Resolving input for mode: {mode}")
|
| 142 |
+
logger.info(f"Raw uploaded input: {media_upload}")
|
| 143 |
|
| 144 |
if mode == "Upload":
|
| 145 |
if not media_upload:
|
| 146 |
logger.warning("No upload detected.")
|
| 147 |
return None
|
| 148 |
|
| 149 |
+
# Gradio gives file paths, so open and classify them
|
| 150 |
+
image_files = []
|
| 151 |
+
video_files = []
|
| 152 |
+
|
| 153 |
+
for file in media_upload:
|
| 154 |
+
if isinstance(file, str):
|
| 155 |
+
ext = file.lower().split('.')[-1]
|
| 156 |
+
if ext in ['jpg', 'jpeg', 'png']:
|
| 157 |
+
try:
|
| 158 |
+
img = Image.open(file).convert("RGB")
|
| 159 |
+
image_files.append(img)
|
| 160 |
+
except Exception as e:
|
| 161 |
+
logger.warning(f"Failed to open image: {file} - {e}")
|
| 162 |
+
elif ext in ['mp4', 'avi', 'mov']:
|
| 163 |
+
video_files.append(file)
|
| 164 |
+
|
| 165 |
+
# Only one type of input allowed
|
| 166 |
if image_files and video_files:
|
| 167 |
logger.warning("Mixed media upload not supported (images + video).")
|
| 168 |
return None
|