Kidbea commited on
Commit
024adaf
·
1 Parent(s): 4e84c36
Files changed (2) hide show
  1. requirements.txt +0 -5
  2. app.py +18 -12
requirements.txt CHANGED
@@ -1,12 +1,7 @@
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
 
 
1
  gradio
 
2
  transformers>=4.30.0
3
  diffusers>=0.16.0
 
4
  torch>=2.4.0
 
5
  xfuser>=0.4.1
6
  accelerate
 
7
  huggingface_hub>=0.13.0
app.py CHANGED
@@ -1,32 +1,38 @@
 
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")
 
1
+ import os
2
  import gradio as gr
3
  import torch
4
  from diffusers import DiffusionPipeline
 
5
 
6
+ # Read token from environment (configured as a Space secret)
7
+ token = os.environ.get("HUGGINGFACE_TOKEN")
8
+ if token is None:
9
+ raise ValueError("Environment variable HUGGINGFACE_TOKEN is not set.")
10
+
11
  model_id = "Wan-AI/Wan2.1-I2V-14B-480P"
 
12
 
13
+ # Load pipeline directly from the Hub, using the token
14
  pipe = DiffusionPipeline.from_pretrained(
15
  model_id,
16
  torch_dtype=torch.float16,
17
+ trust_remote_code=True,
18
+ use_auth_token=token
19
  ).to("cuda")
20
 
21
+ # Enable memory-saving features
22
  pipe.enable_attention_slicing()
23
 
24
+ # Generation function
25
+ def generate_video(image, prompt, num_frames=16, steps=50, guidance_scale=7.5):
26
+ result = pipe(
27
  prompt=prompt,
28
  init_image=image,
29
+ num_inference_steps=steps,
30
+ guidance_scale=guidance_scale,
31
  num_frames=num_frames
32
+ )
33
+ return result.videos
34
 
35
+ # Gradio UI definition
36
  def main():
37
  with gr.Blocks() as demo:
38
  gr.Markdown("# Wan2.1 Image-to-Video Demo")