Spaces:
Running on Zero
Running on Zero
Slicker UI: header badges, cards, prompt chips, status pill
Browse files
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 |
-
"
|
| 485 |
-
|
| 486 |
-
"
|
| 487 |
-
"A
|
| 488 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 489 |
|
| 490 |
CSS = """
|
| 491 |
-
.
|
| 492 |
-
|
| 493 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
with gr.
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
with gr.
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
gr.
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 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 |
-
|
|
|
|
|
|
|
| 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)
|