Hug0endob commited on
Commit
df202fa
·
verified ·
1 Parent(s): cdb71d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -416,16 +416,18 @@ def create_demo():
416
  with gr.Row():
417
  with gr.Column(scale=1):
418
  preview_image = gr.Image(label="Preview Image", type="filepath", elem_classes="preview_media", visible=False)
419
- preview_video = gr.Video(label="Preview Video", elem_classes="preview_media", visible=False, format="mp4", show_controls=False)
 
420
  def _play_pause(video_path):
421
- # simple JS to toggle playback – Gradio lets you inject JS via `gr.HTML`
422
  return f'''
423
  <script>
424
  const vid = document.querySelector('video[src="{video_path}"]');
425
  if (vid) vid.paused ? vid.play() : vid.pause();
426
  </script>
427
  '''
 
428
  preview_status = gr.Textbox(label="Preview status", interactive=False, lines=2, value="", visible=True)
 
429
  with gr.Column(scale=2):
430
  url_input = gr.Textbox(label="Image / Video URL", placeholder="https://...", lines=1)
431
  with gr.Accordion("Prompt (optional)", open=False):
@@ -435,11 +437,11 @@ def create_demo():
435
  with gr.Row():
436
  submit_btn = gr.Button("Submit")
437
  clear_btn = gr.Button("Clear")
 
438
  progress_md = gr.Markdown("Idle")
439
  output_md = gr.Markdown("")
440
  status_state = gr.State("idle")
441
- # hidden state to pass preview path from worker to frontend
442
- preview_path_state = gr.State("")
443
 
444
  # small helper: fetch URL into bytes with retries and respect Retry-After
445
  def _fetch_with_retries_bytes(src: str, timeout: int = 15, max_retries: int = 3):
 
416
  with gr.Row():
417
  with gr.Column(scale=1):
418
  preview_image = gr.Image(label="Preview Image", type="filepath", elem_classes="preview_media", visible=False)
419
+ preview_video = gr.Video(label="Preview Video", elem_classes="preview_media", visible=False, format="mp4")
420
+
421
  def _play_pause(video_path):
 
422
  return f'''
423
  <script>
424
  const vid = document.querySelector('video[src="{video_path}"]');
425
  if (vid) vid.paused ? vid.play() : vid.pause();
426
  </script>
427
  '''
428
+
429
  preview_status = gr.Textbox(label="Preview status", interactive=False, lines=2, value="", visible=True)
430
+
431
  with gr.Column(scale=2):
432
  url_input = gr.Textbox(label="Image / Video URL", placeholder="https://...", lines=1)
433
  with gr.Accordion("Prompt (optional)", open=False):
 
437
  with gr.Row():
438
  submit_btn = gr.Button("Submit")
439
  clear_btn = gr.Button("Clear")
440
+
441
  progress_md = gr.Markdown("Idle")
442
  output_md = gr.Markdown("")
443
  status_state = gr.State("idle")
444
+ preview_path_state = gr.State("") # hidden state to pass preview path from worker to frontend
 
445
 
446
  # small helper: fetch URL into bytes with retries and respect Retry-After
447
  def _fetch_with_retries_bytes(src: str, timeout: int = 15, max_retries: int = 3):