Update app.py
Browse files
app.py
CHANGED
@@ -4,32 +4,31 @@ from diffusers import AutoencoderKLWan, WanPipeline
|
|
4 |
from diffusers.utils import export_to_video
|
5 |
import spaces # ZeroGPU integration
|
6 |
|
7 |
-
@spaces.GPU #
|
8 |
def generate_video(prompt, negative_prompt=""):
|
9 |
model_id = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers"
|
10 |
|
11 |
-
# Load the VAE and pipeline with proper data types
|
12 |
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
|
13 |
-
# With accelerate installed, low_cpu_mem_usage can now be enabled automatically.
|
14 |
pipe = WanPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16)
|
15 |
pipe.to("cuda")
|
16 |
|
17 |
-
# Generate video frames at 480p resolution (480x832) with
|
18 |
output = pipe(
|
19 |
prompt=prompt,
|
20 |
negative_prompt=negative_prompt,
|
21 |
height=480, # 480p height
|
22 |
-
width=832, # width
|
23 |
-
num_frames=81, #
|
24 |
-
guidance_scale=5.0 # Recommended for
|
25 |
).frames[0]
|
26 |
|
27 |
-
#
|
28 |
video_path = "output.mp4"
|
29 |
export_to_video(output, video_path, fps=15)
|
30 |
return video_path
|
31 |
|
32 |
-
# Create a Gradio interface for
|
33 |
iface = gr.Interface(
|
34 |
fn=generate_video,
|
35 |
inputs=[
|
@@ -42,4 +41,4 @@ iface = gr.Interface(
|
|
42 |
)
|
43 |
|
44 |
if __name__ == "__main__":
|
45 |
-
iface.launch()
|
|
|
4 |
from diffusers.utils import export_to_video
|
5 |
import spaces # ZeroGPU integration
|
6 |
|
7 |
+
@spaces.GPU # Request a GPU via ZeroGPU
|
8 |
def generate_video(prompt, negative_prompt=""):
|
9 |
model_id = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers"
|
10 |
|
11 |
+
# Load the VAE and pipeline with proper data types
|
12 |
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
|
|
|
13 |
pipe = WanPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16)
|
14 |
pipe.to("cuda")
|
15 |
|
16 |
+
# Generate video frames at 480p resolution (480x832) with desired settings
|
17 |
output = pipe(
|
18 |
prompt=prompt,
|
19 |
negative_prompt=negative_prompt,
|
20 |
height=480, # 480p height
|
21 |
+
width=832, # Suitable width for 480p
|
22 |
+
num_frames=81, # Adjust as needed for video length
|
23 |
+
guidance_scale=5.0 # Recommended for T2V-1.3B model
|
24 |
).frames[0]
|
25 |
|
26 |
+
# Export the generated frames to a video file
|
27 |
video_path = "output.mp4"
|
28 |
export_to_video(output, video_path, fps=15)
|
29 |
return video_path
|
30 |
|
31 |
+
# Create a Gradio interface for video generation
|
32 |
iface = gr.Interface(
|
33 |
fn=generate_video,
|
34 |
inputs=[
|
|
|
41 |
)
|
42 |
|
43 |
if __name__ == "__main__":
|
44 |
+
iface.launch()
|