Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from diffusers import WanPipeline, UniPCMultistepScheduler
|
| 4 |
+
|
| 5 |
+
pipe = WanPipeline.from_pretrained(
|
| 6 |
+
"Wan-AI/Wan2.2-T2V-1.3B-Diffusers",
|
| 7 |
+
torch_dtype=torch.float16,
|
| 8 |
+
revision="fp16"
|
| 9 |
+
)
|
| 10 |
+
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
| 11 |
+
pipe = pipe.to("cpu")
|
| 12 |
+
|
| 13 |
+
def generate_video(prompt, duration):
|
| 14 |
+
"""
|
| 15 |
+
Generates a video from a text prompt locally using Wan 2.2.
|
| 16 |
+
Duration is clamped between 1 and 8 seconds.
|
| 17 |
+
Returns the path to the saved MP4 file.
|
| 18 |
+
"""
|
| 19 |
+
duration = max(1, min(duration, 8))
|
| 20 |
+
video = pipe(prompt=prompt, height=512, width=512, duration_seconds=duration, guidance_scale=1.0).videos[0]
|
| 21 |
+
video_path = "output.mp4"
|
| 22 |
+
video.save(video_path)
|
| 23 |
+
return video_path
|
| 24 |
+
|
| 25 |
+
with gr.Blocks() as demo:
|
| 26 |
+
gr.Markdown("## Wan 2.2 Video Generator (Local)")
|
| 27 |
+
|
| 28 |
+
with gr.Row():
|
| 29 |
+
prompt_input = gr.Textbox(label="Prompt", placeholder="Describe your scene")
|
| 30 |
+
duration_input = gr.Slider(label="Duration (sec)", minimum=1, maximum=8, step=1, value=6)
|
| 31 |
+
submit_btn = gr.Button("Generate Video")
|
| 32 |
+
output_video = gr.Video(label="Generated Video")
|
| 33 |
+
|
| 34 |
+
submit_btn.click(generate_video, inputs=[prompt_input, duration_input], outputs=output_video)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
demo.launch(api_name="generate-video")
|