Hug0endob commited on
Commit
34d16de
·
verified ·
1 Parent(s): a6909ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -24
app.py CHANGED
@@ -589,30 +589,35 @@ def create_demo():
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
- progress(0.01, desc="Starting processing...") # Initial processing
598
- progress(0.03, desc="Checking URL / content-type...") # URL check
599
- is_img, is_vid = determine_media_type(url, progress=progress)
600
- progress(0.06, desc=f"Determined media type: image={is_img}, video={is_vid}")
601
- client = get_client(key)
602
- preview_local = None
603
- if is_vid:
604
- progress(0.08, desc="Fetching video bytes (may take a while)...")
605
- # Ensure video bytes fetching has proper error handling
606
- raw = fetch_bytes(url, timeout=120, progress=progress)
607
- if raw is None:
608
- return ("error", "Failed to fetch video bytes.", "")
609
- tmp = save_bytes_to_temp(raw, suffix=ext_from_src(url) or ".mp4")
610
- progress(0.18, desc="Saved video to temp; converting for preview if needed...")
611
- preview_tmp = _convert_video_for_preview(tmp)
612
- preview_local = preview_tmp if os.path.exists(preview_tmp) else tmp
613
- progress(0.25, desc="Starting video analysis...")
614
- res = analyze_video_cohesive(client, tmp, prompt or "", progress=progress)
615
- progress(0.90, desc="Finalizing results...")
 
 
 
 
 
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}", "")