Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -206,7 +206,7 @@ def validate_video(path):
|
|
| 206 |
return False, str(e)
|
| 207 |
|
| 208 |
# Input Resolution
|
| 209 |
-
def resolve_input(mode,
|
| 210 |
"""
|
| 211 |
Resolves the media input based on selected mode.
|
| 212 |
- If mode is 'Upload', accepts either:
|
|
@@ -216,7 +216,7 @@ def resolve_input(mode, uploaded_files, url):
|
|
| 216 |
|
| 217 |
Args:
|
| 218 |
mode (str): 'Upload' or 'URL'
|
| 219 |
-
|
| 220 |
url (str): URL to image or video
|
| 221 |
|
| 222 |
Returns:
|
|
@@ -226,12 +226,12 @@ def resolve_input(mode, uploaded_files, url):
|
|
| 226 |
logger.info(f"Resolving input for mode: {mode}")
|
| 227 |
|
| 228 |
if mode == "Upload":
|
| 229 |
-
if not
|
| 230 |
logger.warning("No upload detected.")
|
| 231 |
return None
|
| 232 |
|
| 233 |
-
image_files = [f for f in
|
| 234 |
-
video_files = [f for f in
|
| 235 |
|
| 236 |
if image_files and video_files:
|
| 237 |
logger.warning("Mixed media upload not supported (images + video).")
|
|
@@ -393,7 +393,7 @@ def process_image(
|
|
| 393 |
return None, {"error": str(e)}, None
|
| 394 |
|
| 395 |
# Main Handler
|
| 396 |
-
def handle(mode,
|
| 397 |
"""
|
| 398 |
Master handler for resolving input and processing.
|
| 399 |
Returns outputs for Gradio interface.
|
|
@@ -402,7 +402,7 @@ def handle(mode, uploaded_files, url, run_det, det_model, det_confidence, run_se
|
|
| 402 |
logger.info(f"Session ID: {session_id} | Handler activated with mode: {mode}")
|
| 403 |
start_time = time.time()
|
| 404 |
|
| 405 |
-
media = resolve_input(mode,
|
| 406 |
if not media:
|
| 407 |
return None, format_error("No valid input provided. Please check your upload or URL."), None
|
| 408 |
|
|
@@ -495,7 +495,7 @@ with gr.Blocks() as demo:
|
|
| 495 |
# Button Click Event
|
| 496 |
run.click(
|
| 497 |
handle,
|
| 498 |
-
inputs=[mode,
|
| 499 |
outputs=[img_out, json_out, zip_out]
|
| 500 |
)
|
| 501 |
|
|
|
|
| 206 |
return False, str(e)
|
| 207 |
|
| 208 |
# Input Resolution
|
| 209 |
+
def resolve_input(mode, media_upload, url):
|
| 210 |
"""
|
| 211 |
Resolves the media input based on selected mode.
|
| 212 |
- If mode is 'Upload', accepts either:
|
|
|
|
| 216 |
|
| 217 |
Args:
|
| 218 |
mode (str): 'Upload' or 'URL'
|
| 219 |
+
media_upload (List[Union[PIL.Image.Image, str]]): Uploaded media
|
| 220 |
url (str): URL to image or video
|
| 221 |
|
| 222 |
Returns:
|
|
|
|
| 226 |
logger.info(f"Resolving input for mode: {mode}")
|
| 227 |
|
| 228 |
if mode == "Upload":
|
| 229 |
+
if not media_upload:
|
| 230 |
logger.warning("No upload detected.")
|
| 231 |
return None
|
| 232 |
|
| 233 |
+
image_files = [f for f in media_upload if isinstance(f, Image.Image)]
|
| 234 |
+
video_files = [f for f in media_upload if isinstance(f, str) and f.lower().endswith((".mp4", ".mov", ".avi"))]
|
| 235 |
|
| 236 |
if image_files and video_files:
|
| 237 |
logger.warning("Mixed media upload not supported (images + video).")
|
|
|
|
| 393 |
return None, {"error": str(e)}, None
|
| 394 |
|
| 395 |
# Main Handler
|
| 396 |
+
def handle(mode, media_upload, url, run_det, det_model, det_confidence, run_seg, seg_model, run_depth, depth_model, blend):
|
| 397 |
"""
|
| 398 |
Master handler for resolving input and processing.
|
| 399 |
Returns outputs for Gradio interface.
|
|
|
|
| 402 |
logger.info(f"Session ID: {session_id} | Handler activated with mode: {mode}")
|
| 403 |
start_time = time.time()
|
| 404 |
|
| 405 |
+
media = resolve_input(mode, media_upload, url)
|
| 406 |
if not media:
|
| 407 |
return None, format_error("No valid input provided. Please check your upload or URL."), None
|
| 408 |
|
|
|
|
| 495 |
# Button Click Event
|
| 496 |
run.click(
|
| 497 |
handle,
|
| 498 |
+
inputs=[mode, media_upload, url, run_det, det_model, det_confidence, run_seg, seg_model, run_depth, depth_model, blend],
|
| 499 |
outputs=[img_out, json_out, zip_out]
|
| 500 |
)
|
| 501 |
|