Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,28 @@
|
|
1 |
import torch
|
2 |
-
|
3 |
-
from diffusers import
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
pipe =
|
8 |
-
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
"""
|
12 |
-
Generates a video from the provided prompt using the pre-loaded model.
|
13 |
-
"""
|
14 |
-
try:
|
15 |
-
# Generate video using the model pipeline
|
16 |
-
video = pipe(prompt).videos[0] # Assuming output is a video tensor
|
17 |
-
|
18 |
-
# Return the generated video
|
19 |
-
return video
|
20 |
|
21 |
-
|
22 |
-
print(f"Error during video generation: {e}")
|
23 |
-
return "Error generating video"
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
fn=generate_video,
|
28 |
-
inputs=gr.Textbox(label="Enter Text Prompt"),
|
29 |
-
outputs=gr.Video(label="Generated Video"),
|
30 |
-
title="Text-to-Video Generation with Wan2.1-T2V",
|
31 |
-
description="This app generates a video based on the text prompt using the Wan2.1-T2V model."
|
32 |
-
)
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import torch
|
2 |
+
from diffusers.utils import export_to_video
|
3 |
+
from diffusers import AutoencoderKLWan, WanPipeline
|
4 |
+
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
|
5 |
|
6 |
+
model_id = "Wan-AI/Wan2.1-T2V-14B-Diffusers"
|
7 |
+
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
|
8 |
+
pipe = WanPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16)
|
9 |
+
flow_shift = 3.0 # 5.0 for 720P, 3.0 for 480P
|
10 |
+
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=flow_shift)
|
11 |
+
pipe.to("cuda")
|
12 |
|
13 |
+
pipe.load_lora_weights("NIVEDAN/wan2.1-lora")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
pipe.enable_model_cpu_offload() #for low-vram environments
|
|
|
|
|
16 |
|
17 |
+
prompt = "nivedan"
|
18 |
+
negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards"
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
output = pipe(
|
21 |
+
prompt=prompt,
|
22 |
+
negative_prompt=negative_prompt,
|
23 |
+
height=480,
|
24 |
+
width=832,
|
25 |
+
num_frames=81,
|
26 |
+
guidance_scale=5.0,
|
27 |
+
).frames[0]
|
28 |
+
export_to_video(output, "output.mp4", fps=16)
|