Hug0endob commited on
Commit
407153b
·
verified ·
1 Parent(s): 7529c8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -26
app.py CHANGED
@@ -622,28 +622,12 @@ def create_demo():
622
  if not url:
623
  return "error", "**Error:** No URL provided.", ""
624
 
625
- # ------------------------------------------------------------------
626
- # 1️⃣ Determine media type – use a *single* call to avoid duplicate work
627
- # ------------------------------------------------------------------
628
  progress(0.02, desc="Checking URL / content‑type")
629
  is_img, is_vid = determine_media_type(url, progress=progress)
630
 
631
  client = get_client(key)
632
  preview_path = ""
633
 
634
- # ------------------------------------------------------------------
635
- # 2️⃣ Helper to write a temp file with a *correct* suffix
636
- # ------------------------------------------------------------------
637
- def _temp_file(data: bytes, suffix: str) -> str:
638
- fd, p = tempfile.mkstemp(suffix=suffix)
639
- os.close(fd)
640
- with open(p, "wb") as f:
641
- f.write(data)
642
- return p
643
-
644
- # ------------------------------------------------------------------
645
- # 3️⃣ VIDEO PATH
646
- # ------------------------------------------------------------------
647
  if is_vid:
648
  progress(0.05, desc="Downloading video")
649
  raw = fetch_bytes(url, timeout=120, progress=progress)
@@ -651,7 +635,7 @@ def create_demo():
651
  return "error", "Failed to download video bytes.", ""
652
 
653
  # write with a proper video extension
654
- tmp_video = _temp_file(raw, suffix=ext_from_src(url) or ".mp4")
655
  progress(0.15, desc="Preparing preview")
656
  preview_path = _make_preview(url, raw)
657
 
@@ -662,9 +646,6 @@ def create_demo():
662
  try: os.remove(tmp_video)
663
  except Exception: pass
664
 
665
- # ------------------------------------------------------------------
666
- # 4️⃣ IMAGE PATH
667
- # ------------------------------------------------------------------
668
  elif is_img:
669
  progress(0.05, desc="Downloading image")
670
  raw = fetch_bytes(url, progress=progress)
@@ -675,9 +656,6 @@ def create_demo():
675
  progress(0.20, desc="Running image analysis")
676
  result = analyze_image_structured(client, raw, prompt, progress=progress)
677
 
678
- # ------------------------------------------------------------------
679
- # 5️⃣ FALLBACK – try image first, then video
680
- # ------------------------------------------------------------------
681
  else:
682
  progress(0.07, desc="Downloading unknown media")
683
  raw = fetch_bytes(url, timeout=120, progress=progress)
@@ -699,9 +677,6 @@ def create_demo():
699
  try: os.remove(tmp_vid)
700
  except Exception: pass
701
 
702
- # ------------------------------------------------------------------
703
- # 6️⃣ Final status
704
- # ------------------------------------------------------------------
705
  status = "done" if not (isinstance(result, str) and result.lower().startswith("error")) else "error"
706
  return status, result if isinstance(result, str) else str(result), preview_path or ""
707
 
 
622
  if not url:
623
  return "error", "**Error:** No URL provided.", ""
624
 
 
 
 
625
  progress(0.02, desc="Checking URL / content‑type")
626
  is_img, is_vid = determine_media_type(url, progress=progress)
627
 
628
  client = get_client(key)
629
  preview_path = ""
630
 
 
 
 
 
 
 
 
 
 
 
 
 
 
631
  if is_vid:
632
  progress(0.05, desc="Downloading video")
633
  raw = fetch_bytes(url, timeout=120, progress=progress)
 
635
  return "error", "Failed to download video bytes.", ""
636
 
637
  # write with a proper video extension
638
+ tmp_video = _temp_file(raw, suffix="." + (ext_from_src(url) or "mp4"))
639
  progress(0.15, desc="Preparing preview")
640
  preview_path = _make_preview(url, raw)
641
 
 
646
  try: os.remove(tmp_video)
647
  except Exception: pass
648
 
 
 
 
649
  elif is_img:
650
  progress(0.05, desc="Downloading image")
651
  raw = fetch_bytes(url, progress=progress)
 
656
  progress(0.20, desc="Running image analysis")
657
  result = analyze_image_structured(client, raw, prompt, progress=progress)
658
 
 
 
 
659
  else:
660
  progress(0.07, desc="Downloading unknown media")
661
  raw = fetch_bytes(url, timeout=120, progress=progress)
 
677
  try: os.remove(tmp_vid)
678
  except Exception: pass
679
 
 
 
 
680
  status = "done" if not (isinstance(result, str) and result.lower().startswith("error")) else "error"
681
  return status, result if isinstance(result, str) else str(result), preview_path or ""
682