ElBeh commited on
Commit
809a914
Β·
verified Β·
1 Parent(s): 5a454f0

Update tabs/tab_videoframes.py

Browse files
Files changed (1) hide show
  1. tabs/tab_videoframes.py +13 -12
tabs/tab_videoframes.py CHANGED
@@ -10,7 +10,6 @@ import numpy as np
10
  from PIL import Image
11
  import tempfile
12
  import os
13
- import re
14
  import yt_dlp
15
 
16
  # Import classification function
@@ -326,7 +325,7 @@ def fetch_youtube_info(url):
326
  """Fetch video metadata from a YouTube URL without downloading."""
327
  if not url or not url.strip():
328
  return (
329
- "⚠️ Please enter a URL.",
330
  0,
331
  gr.update(), # yt_start_time slider
332
  gr.update(interactive=False, visible=False), # download button
@@ -342,9 +341,11 @@ def fetch_youtube_info(url):
342
 
343
  duration = info.get("duration", 0)
344
  title = info.get("title", "Unknown")
 
 
345
 
346
  if duration <= MAX_YOUTUBE_DURATION:
347
- status = f"βœ“ **{title}** ({duration:.0f}s) β€” Ready to download."
348
  return (
349
  status,
350
  duration,
@@ -357,8 +358,8 @@ def fetch_youtube_info(url):
357
  secs = int(duration % 60)
358
  max_start = max(0, int(duration - MAX_YOUTUBE_DURATION))
359
  status = (
360
- f"βœ“ **{title}** ({mins}:{secs:02d}) β€” "
361
- f"Video exceeds {MAX_YOUTUBE_DURATION}s. Select a segment below."
362
  )
363
  return (
364
  status,
@@ -370,7 +371,7 @@ def fetch_youtube_info(url):
370
 
371
  except Exception as e:
372
  return (
373
- f"βœ— Error: {e}",
374
  0,
375
  gr.update(),
376
  gr.update(interactive=False, visible=False),
@@ -390,7 +391,7 @@ def download_and_load_youtube(url, start_time, duration):
390
  return (
391
  [], 0, gr.update(maximum=0, value=0),
392
  "No video loaded", 0, 0, {}, None, {},
393
- "⚠️ No URL provided.",
394
  )
395
 
396
  url = url.strip()
@@ -429,17 +430,17 @@ def download_and_load_youtube(url, start_time, duration):
429
  return (
430
  [], 0, gr.update(maximum=0, value=0),
431
  "No video loaded", 0, 0, {}, None, {},
432
- "βœ— Download failed β€” no output file found.",
433
  )
434
 
435
  result = load_video_frames(video_path)
436
- return (*result, "βœ“ Video loaded successfully.")
437
 
438
  except Exception as e:
439
  return (
440
  [], 0, gr.update(maximum=0, value=0),
441
  "No video loaded", 0, 0, {}, None, {},
442
- f"βœ— Download error: {e}",
443
  )
444
 
445
 
@@ -508,7 +509,7 @@ def create_tab_videoframes(tab_label, process_image, shared_video_frames=None):
508
  label="YouTube URL",
509
  placeholder="https://www.youtube.com/watch?v=...",
510
  )
511
- yt_btn_fetch = gr.Button("πŸ” Fetch Info", size="sm")
512
  yt_status = gr.Markdown("")
513
 
514
  with gr.Column(visible=False) as yt_time_col:
@@ -521,7 +522,7 @@ def create_tab_videoframes(tab_label, process_image, shared_video_frames=None):
521
  )
522
 
523
  yt_btn_download = gr.Button(
524
- "⬇️ Download & Load", size="sm",
525
  variant="primary", interactive=False, visible=False,
526
  )
527
 
 
10
  from PIL import Image
11
  import tempfile
12
  import os
 
13
  import yt_dlp
14
 
15
  # Import classification function
 
325
  """Fetch video metadata from a YouTube URL without downloading."""
326
  if not url or not url.strip():
327
  return (
328
+ "Please enter a URL.",
329
  0,
330
  gr.update(), # yt_start_time slider
331
  gr.update(interactive=False, visible=False), # download button
 
341
 
342
  duration = info.get("duration", 0)
343
  title = info.get("title", "Unknown")
344
+ if len(title) > 60:
345
+ title = title[:57] + "..."
346
 
347
  if duration <= MAX_YOUTUBE_DURATION:
348
+ status = f"**{title}** ({duration:.0f}s) β€” Ready to download."
349
  return (
350
  status,
351
  duration,
 
358
  secs = int(duration % 60)
359
  max_start = max(0, int(duration - MAX_YOUTUBE_DURATION))
360
  status = (
361
+ f"**{title}** ({mins}:{secs:02d}) β€” "
362
+ f"Exceeds {MAX_YOUTUBE_DURATION}s. Select a segment below."
363
  )
364
  return (
365
  status,
 
371
 
372
  except Exception as e:
373
  return (
374
+ f"Error: {e}",
375
  0,
376
  gr.update(),
377
  gr.update(interactive=False, visible=False),
 
391
  return (
392
  [], 0, gr.update(maximum=0, value=0),
393
  "No video loaded", 0, 0, {}, None, {},
394
+ "No URL provided.",
395
  )
396
 
397
  url = url.strip()
 
430
  return (
431
  [], 0, gr.update(maximum=0, value=0),
432
  "No video loaded", 0, 0, {}, None, {},
433
+ "Download failed β€” no output file found.",
434
  )
435
 
436
  result = load_video_frames(video_path)
437
+ return (*result, "Video loaded successfully.")
438
 
439
  except Exception as e:
440
  return (
441
  [], 0, gr.update(maximum=0, value=0),
442
  "No video loaded", 0, 0, {}, None, {},
443
+ f"Download error: {e}",
444
  )
445
 
446
 
 
509
  label="YouTube URL",
510
  placeholder="https://www.youtube.com/watch?v=...",
511
  )
512
+ yt_btn_fetch = gr.Button("Fetch Info", size="sm")
513
  yt_status = gr.Markdown("")
514
 
515
  with gr.Column(visible=False) as yt_time_col:
 
522
  )
523
 
524
  yt_btn_download = gr.Button(
525
+ "Download & Load", size="sm",
526
  variant="primary", interactive=False, visible=False,
527
  )
528