linoyts HF Staff commited on
Commit
9435cd9
·
verified ·
1 Parent(s): 3fe0882

Slicker UI: header badges, cards, prompt chips, status pill

Browse files
Files changed (1) hide show
  1. app.py +141 -74
app.py CHANGED
@@ -478,19 +478,78 @@ def go_clip(prompt, seed, sid):
478
 
479
  # ------------------------------------------------------------------------------------------- UI
480
 
481
- EXAMPLES = [
482
- "A corgi running along a sunny beach, waves rolling in, golden hour, cinematic tracking shot.",
483
- "A corgi running through deep fresh snow in a pine forest, snowflakes falling, cinematic tracking shot.",
484
- "A drone shot gliding over a misty green valley with a winding river at sunrise.",
485
- "A drone shot gliding over a red desert canyon with a winding river at sunset.",
486
- "A cozy café at night, rain streaking down the window, warm lamps, a cup of coffee steaming.",
487
- "A watercolor painting of a mother duck leading her ducklings across a calm pond.",
488
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
489
 
490
  CSS = """
491
- .ffl-wrap {max-width: 1100px; margin: 0 auto;}
492
- .ffl-status {font-variant-numeric: tabular-nums; min-height: 1.5em; overflow-wrap: anywhere;}
493
- .ffl-hint {opacity: 0.75; font-size: 0.9em;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
494
  """
495
 
496
  LICENSE_NOTE = (
@@ -501,83 +560,91 @@ LICENSE_NOTE = (
501
  "Apache-2.0) and the [Wan2.1](https://huggingface.co/Wan-AI/Wan2.1-T2V-1.3B) text encoder (Apache-2.0)."
502
  )
503
 
 
 
 
 
 
 
 
 
 
504
  with gr.Blocks(title="FastFrames-S Live") as demo:
505
  sid = gr.Textbox(visible=False) # per-browser session id (a Textbox so the API can pass it too)
506
- with gr.Column(elem_classes="ffl-wrap"):
507
- gr.Markdown(
508
- "# FastFrames-S Live\n"
509
- "Real-time text-to-video with [apple/FastFrames-S](https://huggingface.co/apple/FastFrames-S). "
510
- "Press **Go live**, then keep editing the prompt."
511
- )
512
- with gr.Tabs():
513
- with gr.Tab("Clip"):
514
- with gr.Row(equal_height=False):
515
- with gr.Column(scale=2, min_width=300):
516
- clip_video = gr.Video(label="Latest clip (loops)", autoplay=True, loop=True,
517
- interactive=False, height=420)
518
- clip_status = gr.Markdown("", elem_classes="ffl-status")
519
- with gr.Column(scale=1, min_width=260):
520
- clip_prompt = gr.Textbox(label="Prompt (every edit renders a new 5 s clip)", lines=5,
521
- max_length=MAX_CHARS, value=EXAMPLES[0])
522
- with gr.Row():
523
- clip_start = gr.Button("Go live", variant="primary")
524
- clip_stop = gr.Button("Stop")
525
- with gr.Row():
526
- clip_seed = gr.Number(value=0, precision=0, label="Seed", min_width=100)
527
- clip_reseed = gr.Button("New seed", min_width=100)
528
- clip_preview = gr.Image(label="Rendering", interactive=False, height=180)
529
- gr.Markdown(
530
- f"Each session holds a GPU for about {RT_WINDOW} s. A clip takes about 3 s; a newer "
531
- "edit replaces the clip in progress. Keep the seed fixed to see the same shot change "
532
- "with your words.", elem_classes="ffl-hint")
533
- gr.Examples([[e] for e in EXAMPLES], [clip_prompt], label="Examples")
534
- with gr.Tab("Endless stream"):
535
- with gr.Row(equal_height=False):
536
- with gr.Column(scale=2, min_width=300):
537
- live = gr.Video(label="Live", streaming=True, autoplay=True, interactive=False, height=420)
538
- status = gr.Markdown("", elem_classes="ffl-status")
539
- with gr.Column(scale=1, min_width=260):
540
- prompt = gr.Textbox(label="Prompt (edit while it plays)", lines=5, max_length=MAX_CHARS,
541
- value=EXAMPLES[0])
542
- with gr.Row():
543
- start = gr.Button("Go live", variant="primary")
544
- stop = gr.Button("Stop")
545
- restart = gr.Button("New scene")
546
- with gr.Accordion("Settings", open=False):
547
- seed = gr.Number(value=0, precision=0, label="Seed")
548
- randomize = gr.Checkbox(value=True, label="Randomize seed")
549
- recache = gr.Checkbox(value=True, label="Re-cache on prompt change",
550
- info="Rebuild the cached frames under the new prompt so the "
551
- "switch takes hold. Off = only new frames see the prompt.")
552
- keep = gr.Slider(0, CAP, value=KEEP_ON_SWITCH, step=1,
553
- label="Frames kept on prompt change",
554
- info="Fewer = the new prompt takes over faster (0 = hard cut); "
555
- f"{CAP} = keep the whole context.")
556
- gr.Markdown(
557
- "One continuous video with a rolling memory, so it can run for the whole session. "
558
- "Expect some drift on long runs.", elem_classes="ffl-hint")
559
- gr.Examples([[e] for e in EXAMPLES], [prompt], label="Examples")
560
- recording = gr.Video(label="Session recording", interactive=False)
561
- gr.Markdown(LICENSE_NOTE, elem_classes="ffl-hint")
562
-
563
- demo.load(lambda: uuid.uuid4().hex, None, sid)
564
 
565
  # clip mode
566
  clip_prompt.change(push_clip, [clip_prompt, clip_seed, sid], None, show_progress="hidden", api_name="push_clip")
567
- clip_seed.change(push_clip, [clip_prompt, clip_seed, sid], None, show_progress="hidden")
568
- clip_reseed.click(lambda: random.randint(0, MAX_SEED), None, clip_seed, show_progress="hidden")
 
 
569
  clip_start.click(go_clip, [clip_prompt, clip_seed, sid], [clip_video, clip_preview, clip_status],
570
  api_name="go_clip", concurrency_limit=4)
571
  clip_stop.click(stop_clip, [sid], None, show_progress="hidden", api_name="stop_clip")
572
 
573
  # endless stream
574
  prompt.change(push_prompt, [prompt, recache, keep, sid], None, show_progress="hidden", api_name="push_prompt")
575
- recache.change(push_prompt, [prompt, recache, keep, sid], None, show_progress="hidden")
576
- keep.change(push_prompt, [prompt, recache, keep, sid], None, show_progress="hidden")
577
  start.click(go_live, [prompt, seed, randomize, recache, keep, sid], [live, recording, status, seed],
578
  api_name="go_live", concurrency_limit=4)
579
  restart.click(push_restart, [seed, randomize, sid], [seed], show_progress="hidden", api_name="restart")
580
  stop.click(push_stop, [sid], None, show_progress="hidden", api_name="stop")
581
 
582
  if __name__ == "__main__":
583
- demo.launch(css=CSS)
 
478
 
479
  # ------------------------------------------------------------------------------------------- UI
480
 
481
+ EXAMPLES = { # chip label -> prompt
482
+ "🐶 Beach run": "A corgi running along a sunny beach, waves rolling in, golden hour, cinematic tracking shot.",
483
+ "❄️ Snow run": "A corgi running through deep fresh snow in a pine forest, snowflakes falling, cinematic tracking shot.",
484
+ "🌃 Neon city": "A corgi running along a neon-lit city street at night in the rain, reflections on wet asphalt, "
485
+ "cinematic tracking shot.",
486
+ "🏞️ Misty valley": "A drone shot gliding over a misty green valley with a winding river at sunrise.",
487
+ "🏜️ Red canyon": "A drone shot gliding over a red desert canyon with a winding river at sunset.",
488
+ "☕ Rainy café": "A cozy café at night, rain streaking down the window, warm lamps, a cup of coffee steaming.",
489
+ "🦆 Watercolor ducks": "A watercolor painting of a mother duck leading her ducklings across a calm pond.",
490
+ }
491
+ DEFAULT_PROMPT = EXAMPLES["🐶 Beach run"]
492
+
493
+ THEME = gr.themes.Base(
494
+ primary_hue=gr.themes.colors.orange,
495
+ neutral_hue=gr.themes.colors.zinc,
496
+ font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
497
+ font_mono=[gr.themes.GoogleFont("JetBrains Mono"), "ui-monospace", "monospace"],
498
+ radius_size=gr.themes.sizes.radius_lg,
499
+ ).set(
500
+ button_primary_background_fill="linear-gradient(90deg, *primary_500, *primary_600)",
501
+ button_primary_background_fill_hover="linear-gradient(90deg, *primary_400, *primary_500)",
502
+ button_primary_text_color="white",
503
+ block_border_width="1px",
504
+ block_shadow="none",
505
+ )
506
 
507
  CSS = """
508
+ .gradio-container {max-width: 1180px !important; margin: 0 auto !important;}
509
+ #ffl-header {display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
510
+ gap: 12px 24px; padding: 8px 2px 4px;}
511
+ #ffl-header .ffl-title {min-width: 0;}
512
+ #ffl-header h1 {margin: 0; font-size: clamp(1.6rem, 3.2vw, 2.3rem); font-weight: 750; letter-spacing: -0.02em;
513
+ line-height: 1.1;}
514
+ #ffl-header h1 span {background: linear-gradient(90deg, #f97316, #ec4899); -webkit-background-clip: text;
515
+ background-clip: text; color: transparent;}
516
+ #ffl-header p {margin: 6px 0 0; color: var(--body-text-color-subdued, #71717a); overflow-wrap: anywhere;}
517
+ .ffl-badges {display: flex; flex-wrap: wrap; gap: 6px;}
518
+ .ffl-badge {display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
519
+ border: 1px solid var(--border-color-primary, #e4e4e7); font-size: 0.8rem; white-space: nowrap;
520
+ color: var(--body-text-color, inherit); background: var(--block-background-fill, transparent);}
521
+ .ffl-badge b {font-weight: 650;}
522
+ .ffl-card {border: 1px solid var(--border-color-primary, #e4e4e7) !important; border-radius: 16px !important;
523
+ padding: 14px !important; background: var(--block-background-fill, transparent) !important; min-width: 0;}
524
+ .ffl-stage video {max-width: 100%; object-fit: contain; background: #09090b; border-radius: 12px;}
525
+ .ffl-stage {min-width: 0;}
526
+ .ffl-status {min-height: 1.6em;}
527
+ .ffl-status p {display: inline-block; max-width: 100%; margin: 0; padding: 5px 12px; border-radius: 999px;
528
+ font-family: var(--font-mono, monospace); font-size: 0.78rem; font-variant-numeric: tabular-nums;
529
+ background: var(--background-fill-secondary, #f4f4f5); overflow-wrap: anywhere;}
530
+ .ffl-status p:empty {display: none;}
531
+ .ffl-prompt textarea {font-size: 16px !important; line-height: 1.45;}
532
+ .ffl-chips {display: flex !important; flex-wrap: wrap !important; gap: 6px !important;}
533
+ .ffl-chips > * {flex: 0 1 auto !important; min-width: 0 !important; width: auto !important;}
534
+ .ffl-chip {min-width: 0 !important; padding: 4px 12px !important; font-size: 0.82rem !important;
535
+ border-radius: 999px !important; white-space: nowrap;}
536
+ .ffl-preview img {object-fit: cover; background: var(--background-fill-secondary, #f4f4f5);}
537
+ .ffl-hint, .ffl-hint p {color: var(--body-text-color-subdued, #71717a); font-size: 0.85rem; overflow-wrap: anywhere;}
538
+ .ffl-footer {margin-top: 8px; text-align: center;}
539
+ """
540
+
541
+ HEADER = f"""
542
+ <div id="ffl-header">
543
+ <div class="ffl-title">
544
+ <h1>FastFrames-S <span>Live</span></h1>
545
+ <p>Real-time text-to-video: hit <b>Go live</b> and keep typing; the video follows your words.</p>
546
+ </div>
547
+ <div class="ffl-badges">
548
+ <span class="ffl-badge">⚡ <b>~2.5 s</b> per 5 s clip</span>
549
+ <span class="ffl-badge">🎞️ 832×480 · 16 fps</span>
550
+ <a class="ffl-badge" href="https://huggingface.co/apple/FastFrames-S" target="_blank" rel="noopener">🍎 apple/FastFrames-S</a>
551
+ </div>
552
+ </div>
553
  """
554
 
555
  LICENSE_NOTE = (
 
560
  "Apache-2.0) and the [Wan2.1](https://huggingface.co/Wan-AI/Wan2.1-T2V-1.3B) text encoder (Apache-2.0)."
561
  )
562
 
563
+
564
+ def chips(target):
565
+ """One-click example prompts; setting the textbox fires its .change, which feeds the live session."""
566
+ with gr.Row(elem_classes="ffl-chips"):
567
+ for label, text in EXAMPLES.items():
568
+ gr.Button(label, size="sm", variant="secondary", elem_classes="ffl-chip").click(
569
+ lambda t=text: t, None, target, show_progress="hidden", api_visibility="private")
570
+
571
+
572
  with gr.Blocks(title="FastFrames-S Live") as demo:
573
  sid = gr.Textbox(visible=False) # per-browser session id (a Textbox so the API can pass it too)
574
+ gr.HTML(HEADER)
575
+ with gr.Tabs():
576
+ with gr.Tab("🎬 Clip mode"):
577
+ with gr.Row(equal_height=False):
578
+ with gr.Column(scale=3, min_width=320, elem_classes=["ffl-card", "ffl-stage"]):
579
+ clip_video = gr.Video(show_label=False, autoplay=True, loop=True, interactive=False,
580
+ height=440)
581
+ clip_status = gr.Markdown("", elem_classes="ffl-status")
582
+ with gr.Column(scale=2, min_width=280, elem_classes="ffl-card"):
583
+ clip_prompt = gr.Textbox(label="Prompt", lines=4, max_length=MAX_CHARS, value=DEFAULT_PROMPT,
584
+ placeholder="Describe a shot, then keep editing it...",
585
+ elem_classes="ffl-prompt")
586
+ chips(clip_prompt)
587
+ with gr.Row():
588
+ clip_start = gr.Button("▶ Go live", variant="primary", scale=3, min_width=120)
589
+ clip_stop = gr.Button("■ Stop", variant="secondary", scale=1, min_width=80)
590
+ with gr.Row(equal_height=True):
591
+ clip_seed = gr.Number(value=0, precision=0, label="Seed", min_width=100, scale=2)
592
+ clip_reseed = gr.Button("🎲 New seed", variant="secondary", min_width=100, scale=1)
593
+ clip_preview = gr.Image(label="Rendering", interactive=False, height=150,
594
+ elem_classes="ffl-preview")
595
+ gr.Markdown(
596
+ f"Every edit renders a fresh 5 s clip (~2.5 s) that loops while you keep typing; a newer "
597
+ f"edit replaces the one in progress. Keep the seed to see the same shot change with your "
598
+ f"words. A session holds a GPU for about {RT_WINDOW} s.", elem_classes="ffl-hint")
599
+ with gr.Tab("♾️ Endless stream"):
600
+ with gr.Row(equal_height=False):
601
+ with gr.Column(scale=3, min_width=320, elem_classes=["ffl-card", "ffl-stage"]):
602
+ live = gr.Video(show_label=False, streaming=True, autoplay=True, interactive=False, height=440)
603
+ status = gr.Markdown("", elem_classes="ffl-status")
604
+ with gr.Column(scale=2, min_width=280, elem_classes="ffl-card"):
605
+ prompt = gr.Textbox(label="Prompt", lines=4, max_length=MAX_CHARS, value=DEFAULT_PROMPT,
606
+ placeholder="Describe a shot, then edit it while it plays...",
607
+ elem_classes="ffl-prompt")
608
+ chips(prompt)
609
+ with gr.Row():
610
+ start = gr.Button("▶ Go live", variant="primary", scale=3, min_width=120)
611
+ stop = gr.Button("■ Stop", variant="secondary", scale=1, min_width=80)
612
+ restart = gr.Button("🎬 New scene", variant="secondary")
613
+ with gr.Accordion("Settings", open=False):
614
+ seed = gr.Number(value=0, precision=0, label="Seed")
615
+ randomize = gr.Checkbox(value=True, label="Randomize seed")
616
+ recache = gr.Checkbox(value=True, label="Re-cache on prompt change",
617
+ info="Rebuild the cached frames under the new prompt so the switch "
618
+ "takes hold. Off = only new frames see the prompt.")
619
+ keep = gr.Slider(0, CAP, value=KEEP_ON_SWITCH, step=1, label="Frames kept on prompt change",
620
+ info="Fewer = the new prompt takes over faster (0 = hard cut); "
621
+ f"{CAP} = keep the whole context.")
622
+ gr.Markdown("One continuous video with a rolling memory that runs for the whole session. "
623
+ "Expect some drift on long runs.", elem_classes="ffl-hint")
624
+ with gr.Accordion("Session recording", open=False):
625
+ recording = gr.Video(show_label=False, interactive=False)
626
+ gr.Markdown(LICENSE_NOTE, elem_classes=["ffl-hint", "ffl-footer"])
627
+
628
+ demo.load(lambda: uuid.uuid4().hex, None, sid, api_visibility="private")
 
 
 
629
 
630
  # clip mode
631
  clip_prompt.change(push_clip, [clip_prompt, clip_seed, sid], None, show_progress="hidden", api_name="push_clip")
632
+ clip_seed.change(push_clip, [clip_prompt, clip_seed, sid], None, show_progress="hidden",
633
+ api_visibility="private")
634
+ clip_reseed.click(lambda: random.randint(0, MAX_SEED), None, clip_seed, show_progress="hidden",
635
+ api_visibility="private")
636
  clip_start.click(go_clip, [clip_prompt, clip_seed, sid], [clip_video, clip_preview, clip_status],
637
  api_name="go_clip", concurrency_limit=4)
638
  clip_stop.click(stop_clip, [sid], None, show_progress="hidden", api_name="stop_clip")
639
 
640
  # endless stream
641
  prompt.change(push_prompt, [prompt, recache, keep, sid], None, show_progress="hidden", api_name="push_prompt")
642
+ recache.change(push_prompt, [prompt, recache, keep, sid], None, show_progress="hidden", api_visibility="private")
643
+ keep.change(push_prompt, [prompt, recache, keep, sid], None, show_progress="hidden", api_visibility="private")
644
  start.click(go_live, [prompt, seed, randomize, recache, keep, sid], [live, recording, status, seed],
645
  api_name="go_live", concurrency_limit=4)
646
  restart.click(push_restart, [seed, randomize, sid], [seed], show_progress="hidden", api_name="restart")
647
  stop.click(push_stop, [sid], None, show_progress="hidden", api_name="stop")
648
 
649
  if __name__ == "__main__":
650
+ demo.launch(theme=THEME, css=CSS)