|
import gradio as gr |
|
import random |
|
|
|
with gr.Blocks(fill_height=True) as demo: |
|
with gr.Sidebar(): |
|
gr.Markdown("# Inference Provider") |
|
gr.Markdown("This Space showcases the Wan-AI/Wan2.1-T2V-1.3B model, served by the fal-ai API. Sign in with your Hugging Face account to use this API.") |
|
button = gr.LoginButton("Sign in") |
|
|
|
gr.Markdown("## 🎬 Generate Video from Text") |
|
with gr.Row(): |
|
with gr.Column(): |
|
text_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt to generate video...") |
|
fps_slider = gr.Slider(1, 24, value=8, label="FPS") |
|
frames_slider = gr.Slider(8, 48, value=24, label="Number of Frames") |
|
aspect_ratio = gr.Dropdown(choices=["square", "landscape", "portrait"], value="square", label="Aspect Ratio") |
|
guidance_scale = gr.Slider(1, 20, value=15, label="Guidance Scale") |
|
seed_input = gr.Number(value=random.randint(1, 99999), label="Seed") |
|
generate_button = gr.Button("Generate Video") |
|
with gr.Column(): |
|
video_output = gr.Video(label="Generated Video") |
|
|
|
|
|
model = gr.load( |
|
"models/Wan-AI/Wan2.1-T2V-1.3B", |
|
inputs=["prompt", "num_frames", "fps", "aspect_ratio", "guidance_scale", "negative_prompt", "seed"], |
|
outputs=video_output, |
|
accept_token=button, |
|
provider="fal-ai" |
|
) |
|
|
|
def generate_video_fn(prompt, fps, num_frames, aspect_ratio, guidance_scale, seed): |
|
return model( |
|
prompt=prompt, |
|
num_frames=num_frames, |
|
fps=fps, |
|
aspect_ratio=aspect_ratio, |
|
guidance_scale=guidance_scale, |
|
negative_prompt="", |
|
seed=int(seed) |
|
) |
|
|
|
generate_button.click( |
|
fn=generate_video_fn, |
|
inputs=[text_input, fps_slider, frames_slider, aspect_ratio, guidance_scale, seed_input], |
|
outputs=video_output |
|
) |
|
|
|
demo.launch() |
|
|