File size: 1,955 Bytes
3f975b2
 
 
a461351
 
 
 
 
3f975b2
a461351
3f975b2
 
a461351
 
 
 
 
 
 
3f975b2
a461351
 
 
 
 
 
 
 
 
 
3f975b2
a461351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3f975b2
 
a461351
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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")

    # Load model
    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()