AndyPak commited on
Commit Β·
d5513a8
1
Parent(s): 829a155
Switch to 1.3B model for faster generation
Browse files
app.py
CHANGED
|
@@ -9,11 +9,12 @@ from diffusers import AutoencoderKLWan, WanPipeline
|
|
| 9 |
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
|
| 10 |
|
| 11 |
# ββ Load model once at startup ββββββββββββββββββββββββββββββββββββββββββ
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
vae = AutoencoderKLWan.from_pretrained(MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
|
| 15 |
pipe = WanPipeline.from_pretrained(MODEL_ID, vae=vae, torch_dtype=torch.bfloat16)
|
| 16 |
-
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=
|
| 17 |
pipe.to("cuda")
|
| 18 |
|
| 19 |
# ββ Resolution presets ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -21,12 +22,10 @@ RESOLUTIONS = {
|
|
| 21 |
"9:16 (480p)": (480, 832),
|
| 22 |
"16:9 (480p)": (832, 480),
|
| 23 |
"1:1 (480p)": (624, 624),
|
| 24 |
-
"9:16 (720p)": (720, 1280),
|
| 25 |
-
"16:9 (720p)": (1280, 720),
|
| 26 |
}
|
| 27 |
|
| 28 |
# ββ Generation function βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 29 |
-
@spaces.GPU(duration=
|
| 30 |
def generate(prompt, negative_prompt, resolution, steps, guidance, seed, progress=gr.Progress(track_tqdm=True)):
|
| 31 |
width, height = RESOLUTIONS.get(resolution, (480, 832))
|
| 32 |
|
|
@@ -35,8 +34,8 @@ def generate(prompt, negative_prompt, resolution, steps, guidance, seed, progres
|
|
| 35 |
output = pipe(
|
| 36 |
prompt=prompt,
|
| 37 |
negative_prompt=negative_prompt or None,
|
| 38 |
-
num_inference_steps=steps,
|
| 39 |
-
guidance_scale=guidance,
|
| 40 |
height=height,
|
| 41 |
width=width,
|
| 42 |
num_frames=81,
|
|
@@ -52,7 +51,7 @@ def generate(prompt, negative_prompt, resolution, steps, guidance, seed, progres
|
|
| 52 |
|
| 53 |
# ββ Gradio UI ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 54 |
with gr.Blocks(title="Wan 2.1 Video Generator") as demo:
|
| 55 |
-
gr.Markdown("# Wan 2.1 T2V (
|
| 56 |
|
| 57 |
with gr.Row():
|
| 58 |
with gr.Column(scale=3):
|
|
|
|
| 9 |
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
|
| 10 |
|
| 11 |
# ββ Load model once at startup ββββββββββββββββββββββββββββββββββββββββββ
|
| 12 |
+
# 1.3B model β fast and fits easily in A10G (24GB)
|
| 13 |
+
MODEL_ID = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers"
|
| 14 |
|
| 15 |
vae = AutoencoderKLWan.from_pretrained(MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
|
| 16 |
pipe = WanPipeline.from_pretrained(MODEL_ID, vae=vae, torch_dtype=torch.bfloat16)
|
| 17 |
+
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=3.0)
|
| 18 |
pipe.to("cuda")
|
| 19 |
|
| 20 |
# ββ Resolution presets ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 22 |
"9:16 (480p)": (480, 832),
|
| 23 |
"16:9 (480p)": (832, 480),
|
| 24 |
"1:1 (480p)": (624, 624),
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
|
| 27 |
# ββ Generation function βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 28 |
+
@spaces.GPU(duration=180)
|
| 29 |
def generate(prompt, negative_prompt, resolution, steps, guidance, seed, progress=gr.Progress(track_tqdm=True)):
|
| 30 |
width, height = RESOLUTIONS.get(resolution, (480, 832))
|
| 31 |
|
|
|
|
| 34 |
output = pipe(
|
| 35 |
prompt=prompt,
|
| 36 |
negative_prompt=negative_prompt or None,
|
| 37 |
+
num_inference_steps=int(steps),
|
| 38 |
+
guidance_scale=float(guidance),
|
| 39 |
height=height,
|
| 40 |
width=width,
|
| 41 |
num_frames=81,
|
|
|
|
| 51 |
|
| 52 |
# ββ Gradio UI ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 53 |
with gr.Blocks(title="Wan 2.1 Video Generator") as demo:
|
| 54 |
+
gr.Markdown("# Wan 2.1 T2V (1.3B) β ZeroGPU")
|
| 55 |
|
| 56 |
with gr.Row():
|
| 57 |
with gr.Column(scale=3):
|