Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -589,30 +589,35 @@ def create_demo():
|
|
| 589 |
pass
|
| 590 |
return _convert_video_for_preview(path)
|
| 591 |
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 616 |
|
| 617 |
except Exception as e:
|
| 618 |
return ("error", f"Unexpected worker error: {e}", "")
|
|
|
|
| 589 |
pass
|
| 590 |
return _convert_video_for_preview(path)
|
| 591 |
|
| 592 |
+
# Worker now returns (status_state, output_md, preview_path_state)
|
| 593 |
+
def worker(url: str, prompt: str, key: str, progress=gr.Progress()):
|
| 594 |
+
try:
|
| 595 |
+
if not url:
|
| 596 |
+
return ("error", "**Error:** No URL provided.", "")
|
| 597 |
+
|
| 598 |
+
progress(0.01, desc="Starting processing...") # Initial processing
|
| 599 |
+
progress(0.03, desc="Checking URL / content-type...") # URL check
|
| 600 |
+
is_img, is_vid = determine_media_type(url, progress=progress)
|
| 601 |
+
progress(0.06, desc=f"Determined media type: image={is_img}, video={is_vid}")
|
| 602 |
+
|
| 603 |
+
client = get_client(key)
|
| 604 |
+
preview_local = None
|
| 605 |
+
|
| 606 |
+
if is_vid:
|
| 607 |
+
progress(0.08, desc="Fetching video bytes (may take a while)...")
|
| 608 |
+
# Ensure video bytes fetching has proper error handling
|
| 609 |
+
raw = fetch_bytes(url, timeout=120, progress=progress)
|
| 610 |
+
if raw is None:
|
| 611 |
+
return ("error", "Failed to fetch video bytes.", "")
|
| 612 |
+
|
| 613 |
+
tmp = save_bytes_to_temp(raw, suffix=ext_from_src(url) or ".mp4")
|
| 614 |
+
progress(0.18, desc="Saved video to temp; converting for preview if needed...")
|
| 615 |
+
preview_tmp = _convert_video_for_preview(tmp)
|
| 616 |
+
preview_local = preview_tmp if os.path.exists(preview_tmp) else tmp
|
| 617 |
+
|
| 618 |
+
progress(0.25, desc="Starting video analysis...")
|
| 619 |
+
res = analyze_video_cohesive(client, tmp, prompt or "", progress=progress)
|
| 620 |
+
progress(0.90, desc="Finalizing results...")
|
| 621 |
|
| 622 |
except Exception as e:
|
| 623 |
return ("error", f"Unexpected worker error: {e}", "")
|