Spaces:
Running
on
Zero
Running
on
Zero
new
Browse files- requirements.txt +12 -0
- app.py +39 -4
- spaces_config.json +9 -0
requirements.txt
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Gradio UI
|
2 |
+
gradio
|
3 |
+
# Transformers + Diffusers
|
4 |
+
transformers>=4.30.0
|
5 |
+
diffusers>=0.16.0
|
6 |
+
# PyTorch
|
7 |
+
torch>=2.4.0
|
8 |
+
# Wan-VAE and DiT dependencies
|
9 |
+
xfuser>=0.4.1
|
10 |
+
accelerate
|
11 |
+
# Optional: huggingface_hub for model download
|
12 |
+
huggingface_hub>=0.13.0
|
app.py
CHANGED
@@ -1,7 +1,42 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import DiffusionPipeline
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
|
6 |
+
# Load model weights from Hub
|
7 |
+
model_id = "Wan-AI/Wan2.1-I2V-14B-480P"
|
8 |
+
ckpt_dir = hf_hub_download(repo_id=model_id, filename=".")
|
9 |
|
10 |
+
pipe = DiffusionPipeline.from_pretrained(
|
11 |
+
model_id,
|
12 |
+
torch_dtype=torch.float16,
|
13 |
+
use_auth_token=True
|
14 |
+
).to("cuda")
|
15 |
+
|
16 |
+
pipe.enable_attention_slicing()
|
17 |
+
|
18 |
+
|
19 |
+
def generate_video(image, prompt, num_frames=16):
|
20 |
+
video = pipe(
|
21 |
+
prompt=prompt,
|
22 |
+
init_image=image,
|
23 |
+
num_inference_steps=50,
|
24 |
+
guidance_scale=7.5,
|
25 |
+
num_frames=num_frames
|
26 |
+
).videos
|
27 |
+
return video
|
28 |
+
|
29 |
+
# Gradio UI
|
30 |
+
def main():
|
31 |
+
with gr.Blocks() as demo:
|
32 |
+
gr.Markdown("# Wan2.1 Image-to-Video Demo")
|
33 |
+
with gr.Row():
|
34 |
+
img_in = gr.Image(type="pil", label="Input Image")
|
35 |
+
txt_p = gr.Textbox(label="Prompt")
|
36 |
+
btn = gr.Button("Generate Video")
|
37 |
+
out = gr.Video(label="Generated Video")
|
38 |
+
btn.click(fn=generate_video, inputs=[img_in, txt_p], outputs=out)
|
39 |
+
return demo
|
40 |
+
|
41 |
+
if __name__ == "__main__":
|
42 |
+
main().launch()
|
spaces_config.json
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"sdk": "gradio",
|
3 |
+
"hardware": {
|
4 |
+
"gpu": true,
|
5 |
+
"cpu": false,
|
6 |
+
"quantized": false
|
7 |
+
},
|
8 |
+
"timeout": 3600
|
9 |
+
}
|