Spaces:
Running
Running
| 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) | |