Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -559,64 +559,98 @@ def video_generation_handler_streaming(prompt, seed=42, fps=15, aspect_ratio="16
|
|
559 |
print(f"β
PyAV streaming complete! {total_frames_yielded} frames across {num_blocks} blocks")
|
560 |
|
561 |
# --- Gradio UI Layout ---
|
562 |
-
with gr.Blocks(title="
|
563 |
-
gr.Markdown("
|
564 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
565 |
|
566 |
with gr.Row():
|
567 |
with gr.Column(scale=2):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
568 |
with gr.Group():
|
|
|
569 |
prompt = gr.Textbox(
|
570 |
-
label="
|
571 |
-
placeholder="A
|
572 |
lines=4,
|
573 |
-
value=""
|
|
|
574 |
)
|
575 |
-
enhance_button = gr.Button("β¨ Enhance Prompt", variant="secondary")
|
576 |
|
577 |
-
|
578 |
-
|
579 |
-
gr.Markdown("### π― Examples")
|
580 |
-
gr.Examples(
|
581 |
-
examples=[
|
582 |
-
"A close-up shot of a ceramic teacup slowly pouring water into a glass mug.",
|
583 |
-
"A playful cat is seen playing an electronic guitar, strumming the strings with its front paws. The cat has distinctive black facial markings and a bushy tail. It sits comfortably on a small stool, its body slightly tilted as it focuses intently on the instrument. The setting is a cozy, dimly lit room with vintage posters on the walls, adding a retro vibe. The cat's expressive eyes convey a sense of joy and concentration. Medium close-up shot, focusing on the cat's face and hands interacting with the guitar.",
|
584 |
-
"A dynamic over-the-shoulder perspective of a chef meticulously plating a dish in a bustling kitchen. The chef, a middle-aged woman, deftly arranges ingredients on a pristine white plate. Her hands move with precision, each gesture deliberate and practiced. The background shows a crowded kitchen with steaming pots, whirring blenders, and the clatter of utensils. Bright lights highlight the scene, casting shadows across the busy workspace. The camera angle captures the chef's detailed work from behind, emphasizing his skill and dedication.",
|
585 |
-
],
|
586 |
-
inputs=[prompt],
|
587 |
-
)
|
588 |
-
|
589 |
-
gr.Markdown("### βοΈ Settings")
|
590 |
with gr.Row():
|
591 |
-
seed = gr.Number(
|
592 |
-
label="Seed",
|
593 |
-
value=-1,
|
594 |
-
info="Use -1 for random seed",
|
595 |
-
precision=0
|
596 |
-
)
|
597 |
aspect_ratio = gr.Radio(
|
598 |
-
label="
|
599 |
-
choices=["16:9", "9
|
|
|
600 |
value="16:9",
|
601 |
-
info="
|
602 |
)
|
603 |
|
604 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
605 |
fps = gr.Slider(
|
606 |
label="Playback FPS",
|
607 |
minimum=1,
|
608 |
maximum=30,
|
609 |
value=args.fps,
|
610 |
step=1,
|
611 |
-
visible=False
|
612 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
613 |
)
|
614 |
|
|
|
|
|
615 |
with gr.Column(scale=3):
|
616 |
-
gr.Markdown("### πΊ Video
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
617 |
|
618 |
streaming_video = gr.Video(
|
619 |
-
label="Live
|
620 |
streaming=True,
|
621 |
loop=True,
|
622 |
height=400,
|
@@ -624,32 +658,78 @@ with gr.Blocks(title="Self-Forcing Streaming Demo") as demo:
|
|
624 |
show_label=False
|
625 |
)
|
626 |
|
627 |
-
gr.Markdown("###
|
628 |
|
629 |
-
# Complete video display with download enabled
|
630 |
complete_video = gr.Video(
|
631 |
-
label="
|
632 |
height=400,
|
633 |
show_label=False,
|
634 |
visible=False,
|
635 |
-
show_download_button=True
|
636 |
)
|
637 |
|
638 |
-
# File component for download
|
639 |
download_file = gr.File(
|
640 |
-
label="π₯ Download Video File",
|
641 |
visible=False
|
642 |
)
|
643 |
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
653 |
|
654 |
# Connect the generator to the streaming video
|
655 |
generation_event = start_btn.click(
|
|
|
559 |
print(f"β
PyAV streaming complete! {total_frames_yielded} frames across {num_blocks} blocks")
|
560 |
|
561 |
# --- Gradio UI Layout ---
|
562 |
+
with gr.Blocks(title="AI Video Generator - Transform Text to Video", theme=gr.themes.Soft()) as demo:
|
563 |
+
gr.Markdown("""
|
564 |
+
# π¬ AI Video Generator - Transform Your Words into Amazing Videos
|
565 |
+
|
566 |
+
### Welcome to the AI Video Generator!
|
567 |
+
Simply type a text description and AI will create stunning video content for you. No video editing experience needed - let your creativity come to life instantly!
|
568 |
+
|
569 |
+
**β¨ Key Features:**
|
570 |
+
- π **Easy to Use** - Just type what you want to see
|
571 |
+
- π **Real-time Generation** - Watch as your video is created
|
572 |
+
- π¨ **High Quality Output** - Professional-grade video results
|
573 |
+
- π± **Multiple Formats** - Support for landscape (16:9) and portrait (9:16)
|
574 |
+
""")
|
575 |
|
576 |
with gr.Row():
|
577 |
with gr.Column(scale=2):
|
578 |
+
gr.Markdown("""
|
579 |
+
### π How to Use
|
580 |
+
1. **Write Description** - Describe your desired video in the text box below
|
581 |
+
2. **Enhance Prompt** - Click "β¨ Enhance Prompt" to let AI improve your description
|
582 |
+
3. **Choose Format** - Select the appropriate video aspect ratio
|
583 |
+
4. **Generate** - Click "π¬ Start Video Generation"
|
584 |
+
5. **Download** - Save your video once generation is complete
|
585 |
+
""")
|
586 |
+
|
587 |
with gr.Group():
|
588 |
+
gr.Markdown("#### Step 1: Describe Your Video")
|
589 |
prompt = gr.Textbox(
|
590 |
+
label="Video Description",
|
591 |
+
placeholder="e.g., A cute cat playing guitar in a cozy room with warm lighting...",
|
592 |
lines=4,
|
593 |
+
value="",
|
594 |
+
info="π‘ Tip: The more detailed your description, the better the result! Include subjects, actions, settings, and style."
|
595 |
)
|
596 |
+
enhance_button = gr.Button("β¨ Enhance Prompt (Let AI improve your description)", variant="secondary")
|
597 |
|
598 |
+
gr.Markdown("#### Step 2: Choose Video Settings")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
599 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
600 |
aspect_ratio = gr.Radio(
|
601 |
+
label="Video Format",
|
602 |
+
choices=[("Landscape (16:9) - Best for computers/TVs", "16:9"),
|
603 |
+
("Portrait (9:16) - Best for phones/social media", "9:16")],
|
604 |
value="16:9",
|
605 |
+
info="Select the format that best suits your needs"
|
606 |
)
|
607 |
|
608 |
with gr.Row():
|
609 |
+
seed = gr.Number(
|
610 |
+
label="Random Seed",
|
611 |
+
value=-1,
|
612 |
+
info="Use the same seed to recreate identical videos (-1 for random)",
|
613 |
+
precision=0,
|
614 |
+
visible=False # Hide advanced options
|
615 |
+
)
|
616 |
fps = gr.Slider(
|
617 |
label="Playback FPS",
|
618 |
minimum=1,
|
619 |
maximum=30,
|
620 |
value=args.fps,
|
621 |
step=1,
|
622 |
+
visible=False
|
623 |
+
)
|
624 |
+
|
625 |
+
with gr.Accordion("π― Need Inspiration? Try These Examples", open=True):
|
626 |
+
gr.Examples(
|
627 |
+
examples=[
|
628 |
+
"A close-up shot of a ceramic teacup slowly pouring water into a glass mug. The water flows smoothly, creating gentle ripples.",
|
629 |
+
"A playful cat playing an electric guitar, strumming with its paws. The cat has distinctive black facial markings and a bushy tail. It sits on a small stool in a cozy room with vintage posters on the walls.",
|
630 |
+
"An over-the-shoulder view of a female chef carefully plating a dish in a busy kitchen. Her hands move with precision against a background of steaming pots and bustling activity.",
|
631 |
+
],
|
632 |
+
inputs=[prompt],
|
633 |
+
label="Click to use example"
|
634 |
)
|
635 |
|
636 |
+
start_btn = gr.Button("π¬ Start Video Generation", variant="primary", size="lg")
|
637 |
+
|
638 |
with gr.Column(scale=3):
|
639 |
+
gr.Markdown("### πΊ Video Preview")
|
640 |
+
|
641 |
+
status_display = gr.HTML(
|
642 |
+
value=(
|
643 |
+
"<div style='text-align: center; padding: 30px; color: #666; border: 2px dashed #e0e0e0; border-radius: 12px; background: #f9f9f9;'>"
|
644 |
+
"<h3 style='margin-top: 0; color: #333;'>π¬ Ready to Create</h3>"
|
645 |
+
"<p>Enter your creative description and click 'Start Video Generation' to begin</p>"
|
646 |
+
"<small style='color: #999;'>Generation typically takes 1-2 minutes</small>"
|
647 |
+
"</div>"
|
648 |
+
),
|
649 |
+
label="Generation Status"
|
650 |
+
)
|
651 |
|
652 |
streaming_video = gr.Video(
|
653 |
+
label="Live Preview",
|
654 |
streaming=True,
|
655 |
loop=True,
|
656 |
height=400,
|
|
|
658 |
show_label=False
|
659 |
)
|
660 |
|
661 |
+
gr.Markdown("### π Completed Video")
|
662 |
|
|
|
663 |
complete_video = gr.Video(
|
664 |
+
label="Final Video",
|
665 |
height=400,
|
666 |
show_label=False,
|
667 |
visible=False,
|
668 |
+
show_download_button=True
|
669 |
)
|
670 |
|
|
|
671 |
download_file = gr.File(
|
672 |
+
label="π₯ Click to Download Video File",
|
673 |
visible=False
|
674 |
)
|
675 |
|
676 |
+
gr.Markdown("""
|
677 |
+
---
|
678 |
+
### β Frequently Asked Questions
|
679 |
+
|
680 |
+
<details>
|
681 |
+
<summary><b>What's the quality of generated videos?</b></summary>
|
682 |
+
<p>The AI generates videos with optimized resolution suitable for social media sharing and personal use. Videos are clear and smooth.</p>
|
683 |
+
</details>
|
684 |
+
|
685 |
+
<details>
|
686 |
+
<summary><b>How long are the generated videos?</b></summary>
|
687 |
+
<p>Currently supports generating short videos of approximately 5-10 seconds, perfect for creating engaging short-form content.</p>
|
688 |
+
</details>
|
689 |
+
|
690 |
+
<details>
|
691 |
+
<summary><b>How do I write good video descriptions?</b></summary>
|
692 |
+
<p>
|
693 |
+
- Describe subjects in detail: appearance, actions, expressions<br>
|
694 |
+
- Specify the environment: indoor/outdoor, time of day, atmosphere<br>
|
695 |
+
- Include camera angles: close-up, wide shot, overhead view<br>
|
696 |
+
- Add style preferences: realistic, animated, artistic style
|
697 |
+
</p>
|
698 |
+
</details>
|
699 |
+
|
700 |
+
<details>
|
701 |
+
<summary><b>What if generation fails?</b></summary>
|
702 |
+
<p>Try: 1) Simplifying your description 2) Using the "Enhance Prompt" feature 3) Trying a different approach to your description</p>
|
703 |
+
</details>
|
704 |
+
|
705 |
+
<details>
|
706 |
+
<summary><b>Can I recreate the same video?</b></summary>
|
707 |
+
<p>Yes! Click "Show Advanced Settings" and use a specific seed number instead of -1. Using the same seed with the same prompt will generate identical videos.</p>
|
708 |
+
</details>
|
709 |
+
""")
|
710 |
+
|
711 |
+
# Add advanced settings toggle
|
712 |
+
with gr.Row():
|
713 |
+
with gr.Column(scale=2):
|
714 |
+
with gr.Accordion("βοΈ Advanced Settings", open=False):
|
715 |
+
gr.Markdown("**For Advanced Users Only**")
|
716 |
+
seed.visible = True
|
717 |
+
seed.render()
|
718 |
+
gr.Markdown("*Note: Use a specific seed value to recreate the same video*")
|
719 |
+
|
720 |
+
# Add footer
|
721 |
+
gr.Markdown("""
|
722 |
+
---
|
723 |
+
<div style='text-align: center; color: #666; padding: 20px;'>
|
724 |
+
<p>π‘ <b>Pro Tip</b>: Use the "Enhance Prompt" feature to let AI improve your description for better video results!</p>
|
725 |
+
<p style='font-size: 12px; margin-top: 10px;'>
|
726 |
+
Powered by Self-Forcing AI Model |
|
727 |
+
<a href="https://huggingface.co/gdhe17/Self-Forcing" target="_blank">Model Details</a> |
|
728 |
+
<a href="https://self-forcing.github.io" target="_blank">Project Page</a> |
|
729 |
+
<a href="https://huggingface.co/papers/2506.08009" target="_blank">Research Paper</a>
|
730 |
+
</p>
|
731 |
+
</div>
|
732 |
+
""")
|
733 |
|
734 |
# Connect the generator to the streaming video
|
735 |
generation_event = start_btn.click(
|