File size: 2,495 Bytes
053e290
59e4b3b
 
053e290
59e4b3b
 
0b28d63
 
 
 
 
59e4b3b
0b28d63
 
 
59e4b3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f3e294e
0b28d63
053e290
0b28d63
 
 
 
 
053e290
0b28d63
 
59e4b3b
 
0b28d63
 
59e4b3b
 
 
 
0b28d63
 
59e4b3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import gradio as gr
from huggingface_hub import InferenceClient
import tempfile

MODEL_ID = "Wan-AI/Wan2.2-T2V-A14B"
PROVIDER = "fal-ai"

EXAMPLES = [
    "A golden retriever running through a sunlit meadow in slow motion, cinematic lighting",
    "A futuristic city at night with flying cars and neon lights reflecting off wet streets",
    "An astronaut floating in space with Earth in the background, gentle camera rotation",
    "Ocean waves crashing on a rocky coastline at sunset, dramatic sky with purple clouds",
    "A steaming cup of coffee on a wooden table with rain falling outside the window",
]


def generate_video(prompt, oauth_token: gr.OAuthToken | None = None):
    if oauth_token is None:
        raise gr.Error("Please sign in with your Hugging Face account first.")
    if not prompt or not prompt.strip():
        raise gr.Error("Please enter a text prompt.")

    client = InferenceClient(provider=PROVIDER, token=oauth_token.token)
    video_bytes = client.text_to_video(prompt, model=MODEL_ID)

    tmp = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False)
    tmp.write(video_bytes)
    tmp.close()
    return tmp.name


with gr.Blocks(fill_height=True, title="Wan 2.2 Text-to-Video") as demo:

    with gr.Sidebar():
        gr.Markdown("## Account")
        gr.Markdown(
            "This Space uses the **fal-ai** inference API. "
            "Sign in with your Hugging Face account to use it."
        )
        button = gr.LoginButton("Sign in")
        gr.Markdown("---")
        gr.Markdown(
            f"**Model:** [{MODEL_ID}](https://huggingface.co/{MODEL_ID})\n\n"
            f"**Provider:** {PROVIDER}"
        )

    gr.Markdown(
        "# Wan 2.2 — Text to Video Generator\n\n"
        f"Generate videos from text prompts using **{MODEL_ID}**. "
        "Sign in with your Hugging Face account to get started."
    )

    with gr.Row():
        with gr.Column():
            prompt = gr.Textbox(
                label="Prompt",
                placeholder="Describe the video you want to generate...",
                lines=3,
            )
            generate_btn = gr.Button("Generate Video", variant="primary")
            gr.Examples(examples=EXAMPLES, inputs=prompt)
        with gr.Column():
            video_output = gr.Video(label="Generated Video")

    generate_btn.click(fn=generate_video, inputs=prompt, outputs=video_output)
    prompt.submit(fn=generate_video, inputs=prompt, outputs=video_output)

demo.launch(ssr_mode=False)