Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ import numpy as np
|
|
| 9 |
from PIL import Image
|
| 10 |
import random
|
| 11 |
import gc
|
|
|
|
| 12 |
|
| 13 |
from torchao.quantization import quantize_
|
| 14 |
from torchao.quantization import Float8DynamicActivationFloat8WeightConfig
|
|
@@ -75,6 +76,9 @@ pipe.load_lora_weights(
|
|
| 75 |
weight_name="livewallpaper_wan22_14b_i2v_low_model_0_1_e26.safetensors",
|
| 76 |
adapter_name="livewallpaper"
|
| 77 |
)
|
|
|
|
|
|
|
|
|
|
| 78 |
pipe.set_adapters(["livewallpaper"], adapter_weights=[1.])
|
| 79 |
pipe.fuse_lora(adapter_names=["livewallpaper"], lora_scale=2., components=["transformer"])
|
| 80 |
pipe.unload_lora_weights()
|
|
@@ -82,10 +86,14 @@ pipe.unload_lora_weights()
|
|
| 82 |
quantize_(pipe.text_encoder, Int8WeightOnlyConfig())
|
| 83 |
quantize_(pipe.transformer, Float8DynamicActivationFloat8WeightConfig())
|
| 84 |
quantize_(pipe.transformer_2, Float8DynamicActivationFloat8WeightConfig())
|
|
|
|
| 85 |
|
| 86 |
aoti.aoti_blocks_load(pipe.transformer, 'zerogpu-aoti/Wan2', variant='fp8da')
|
| 87 |
aoti.aoti_blocks_load(pipe.transformer_2, 'zerogpu-aoti/Wan2', variant='fp8da')
|
|
|
|
| 88 |
|
|
|
|
|
|
|
| 89 |
|
| 90 |
default_prompt_i2v = "make this image come alive, cinematic motion, smooth animation"
|
| 91 |
default_negative_prompt = "色调艳丽, 过曝, 静态, 细节模糊不清, 字幕, 风格, 作品, 画作, 画面, 静止, 整体发灰, 最差质量, 低质量, JPEG压缩残留, 丑陋的, 残缺的, 多余的手指, 画得不好的手部, 画得不好的脸部, 畸形的, 毁容的, 形态畸形的肢体, 手指融合, 静止不动的画面, 杂乱的背景, 三条腿, 背景人很多, 倒着走"
|
|
@@ -166,7 +174,7 @@ def get_inference_duration(
|
|
| 166 |
guidance_scale,
|
| 167 |
guidance_scale_2,
|
| 168 |
current_seed,
|
| 169 |
-
|
| 170 |
):
|
| 171 |
BASE_FRAMES_HEIGHT_WIDTH = 81 * 832 * 624
|
| 172 |
BASE_STEP_DURATION = 15
|
|
@@ -187,9 +195,14 @@ def run_inference(
|
|
| 187 |
guidance_scale,
|
| 188 |
guidance_scale_2,
|
| 189 |
current_seed,
|
|
|
|
| 190 |
progress=gr.Progress(track_tqdm=True),
|
| 191 |
):
|
| 192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
image=resized_image,
|
| 194 |
last_image=processed_last_image,
|
| 195 |
prompt=prompt,
|
|
@@ -203,6 +216,10 @@ def run_inference(
|
|
| 203 |
generator=torch.Generator(device="cuda").manual_seed(current_seed),
|
| 204 |
).frames[0]
|
| 205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
def generate_video(
|
| 208 |
input_image,
|
|
@@ -216,6 +233,7 @@ def generate_video(
|
|
| 216 |
seed=42,
|
| 217 |
randomize_seed=False,
|
| 218 |
quality=5,
|
|
|
|
| 219 |
progress=gr.Progress(track_tqdm=True),
|
| 220 |
):
|
| 221 |
"""
|
|
@@ -245,6 +263,8 @@ def generate_video(
|
|
| 245 |
Defaults to False.
|
| 246 |
quality (float, optional): Video output quality. Default is 5. Uses variable bit rate.
|
| 247 |
Highest quality is 10, lowest is 1.
|
|
|
|
|
|
|
| 248 |
progress (gr.Progress, optional): Gradio progress tracker. Defaults to gr.Progress(track_tqdm=True).
|
| 249 |
|
| 250 |
Returns:
|
|
@@ -283,6 +303,7 @@ def generate_video(
|
|
| 283 |
guidance_scale,
|
| 284 |
guidance_scale_2,
|
| 285 |
current_seed,
|
|
|
|
| 286 |
progress,
|
| 287 |
)
|
| 288 |
|
|
@@ -302,6 +323,7 @@ with gr.Blocks() as demo:
|
|
| 302 |
with gr.Column():
|
| 303 |
input_image_component = gr.Image(type="pil", label="Input Image")
|
| 304 |
prompt_input = gr.Textbox(label="Prompt", value=default_prompt_i2v)
|
|
|
|
| 305 |
duration_seconds_input = gr.Slider(minimum=MIN_DURATION, maximum=MAX_DURATION, step=0.1, value=3.5, label="Duration (seconds)", info=f"Clamped to model's {MIN_FRAMES_MODEL}-{MAX_FRAMES_MODEL} frames at {FIXED_FPS}fps.")
|
| 306 |
steps_slider = gr.Slider(minimum=1, maximum=30, step=1, value=6, label="Inference Steps")
|
| 307 |
quality_slider = gr.Slider(minimum=1, maximum=10, step=1, value=6, label="Video Quality")
|
|
@@ -323,7 +345,7 @@ with gr.Blocks() as demo:
|
|
| 323 |
input_image_component, last_image_component, prompt_input, steps_slider,
|
| 324 |
negative_prompt_input, duration_seconds_input,
|
| 325 |
guidance_scale_input, guidance_scale_2_input, seed_input, randomize_seed_checkbox,
|
| 326 |
-
quality_slider
|
| 327 |
]
|
| 328 |
generate_button.click(fn=generate_video, inputs=ui_inputs, outputs=[video_output, file_output, seed_input])
|
| 329 |
|
|
|
|
| 9 |
from PIL import Image
|
| 10 |
import random
|
| 11 |
import gc
|
| 12 |
+
import copy
|
| 13 |
|
| 14 |
from torchao.quantization import quantize_
|
| 15 |
from torchao.quantization import Float8DynamicActivationFloat8WeightConfig
|
|
|
|
| 76 |
weight_name="livewallpaper_wan22_14b_i2v_low_model_0_1_e26.safetensors",
|
| 77 |
adapter_name="livewallpaper"
|
| 78 |
)
|
| 79 |
+
|
| 80 |
+
default_transformer = copy.deepcopy(pipe.transformer)
|
| 81 |
+
|
| 82 |
pipe.set_adapters(["livewallpaper"], adapter_weights=[1.])
|
| 83 |
pipe.fuse_lora(adapter_names=["livewallpaper"], lora_scale=2., components=["transformer"])
|
| 84 |
pipe.unload_lora_weights()
|
|
|
|
| 86 |
quantize_(pipe.text_encoder, Int8WeightOnlyConfig())
|
| 87 |
quantize_(pipe.transformer, Float8DynamicActivationFloat8WeightConfig())
|
| 88 |
quantize_(pipe.transformer_2, Float8DynamicActivationFloat8WeightConfig())
|
| 89 |
+
quantize_(default_transformer, Float8DynamicActivationFloat8WeightConfig())
|
| 90 |
|
| 91 |
aoti.aoti_blocks_load(pipe.transformer, 'zerogpu-aoti/Wan2', variant='fp8da')
|
| 92 |
aoti.aoti_blocks_load(pipe.transformer_2, 'zerogpu-aoti/Wan2', variant='fp8da')
|
| 93 |
+
aoti.aoti_blocks_load(default_transformer, 'zerogpu-aoti/Wan2', variant='fp8da')
|
| 94 |
|
| 95 |
+
static_transformer = pipe.transformer
|
| 96 |
+
pipe.transformer = default_transformer
|
| 97 |
|
| 98 |
default_prompt_i2v = "make this image come alive, cinematic motion, smooth animation"
|
| 99 |
default_negative_prompt = "色调艳丽, 过曝, 静态, 细节模糊不清, 字幕, 风格, 作品, 画作, 画面, 静止, 整体发灰, 最差质量, 低质量, JPEG压缩残留, 丑陋的, 残缺的, 多余的手指, 画得不好的手部, 画得不好的脸部, 畸形的, 毁容的, 形态畸形的肢体, 手指融合, 静止不动的画面, 杂乱的背景, 三条腿, 背景人很多, 倒着走"
|
|
|
|
| 174 |
guidance_scale,
|
| 175 |
guidance_scale_2,
|
| 176 |
current_seed,
|
| 177 |
+
live_wallpaper_style,
|
| 178 |
):
|
| 179 |
BASE_FRAMES_HEIGHT_WIDTH = 81 * 832 * 624
|
| 180 |
BASE_STEP_DURATION = 15
|
|
|
|
| 195 |
guidance_scale,
|
| 196 |
guidance_scale_2,
|
| 197 |
current_seed,
|
| 198 |
+
live_wallpaper_style,
|
| 199 |
progress=gr.Progress(track_tqdm=True),
|
| 200 |
):
|
| 201 |
+
|
| 202 |
+
if live_wallpaper_style:
|
| 203 |
+
pipe.transformer = static_transformer
|
| 204 |
+
|
| 205 |
+
output_frames = pipe(
|
| 206 |
image=resized_image,
|
| 207 |
last_image=processed_last_image,
|
| 208 |
prompt=prompt,
|
|
|
|
| 216 |
generator=torch.Generator(device="cuda").manual_seed(current_seed),
|
| 217 |
).frames[0]
|
| 218 |
|
| 219 |
+
pipe.transformer = default_transformer
|
| 220 |
+
|
| 221 |
+
return output_frames
|
| 222 |
+
|
| 223 |
|
| 224 |
def generate_video(
|
| 225 |
input_image,
|
|
|
|
| 233 |
seed=42,
|
| 234 |
randomize_seed=False,
|
| 235 |
quality=5,
|
| 236 |
+
live_wallpaper_style=False,
|
| 237 |
progress=gr.Progress(track_tqdm=True),
|
| 238 |
):
|
| 239 |
"""
|
|
|
|
| 263 |
Defaults to False.
|
| 264 |
quality (float, optional): Video output quality. Default is 5. Uses variable bit rate.
|
| 265 |
Highest quality is 10, lowest is 1.
|
| 266 |
+
live_wallpaper_style (bool, optional): Whether to use the live wallpaper transformer.
|
| 267 |
+
Defaults to False.
|
| 268 |
progress (gr.Progress, optional): Gradio progress tracker. Defaults to gr.Progress(track_tqdm=True).
|
| 269 |
|
| 270 |
Returns:
|
|
|
|
| 303 |
guidance_scale,
|
| 304 |
guidance_scale_2,
|
| 305 |
current_seed,
|
| 306 |
+
live_wallpaper_style,
|
| 307 |
progress,
|
| 308 |
)
|
| 309 |
|
|
|
|
| 323 |
with gr.Column():
|
| 324 |
input_image_component = gr.Image(type="pil", label="Input Image")
|
| 325 |
prompt_input = gr.Textbox(label="Prompt", value=default_prompt_i2v)
|
| 326 |
+
live_wallpaper_style_checkbox = gr.Checkbox(label="Live Wallpaper Style", value=False, interactive=True)
|
| 327 |
duration_seconds_input = gr.Slider(minimum=MIN_DURATION, maximum=MAX_DURATION, step=0.1, value=3.5, label="Duration (seconds)", info=f"Clamped to model's {MIN_FRAMES_MODEL}-{MAX_FRAMES_MODEL} frames at {FIXED_FPS}fps.")
|
| 328 |
steps_slider = gr.Slider(minimum=1, maximum=30, step=1, value=6, label="Inference Steps")
|
| 329 |
quality_slider = gr.Slider(minimum=1, maximum=10, step=1, value=6, label="Video Quality")
|
|
|
|
| 345 |
input_image_component, last_image_component, prompt_input, steps_slider,
|
| 346 |
negative_prompt_input, duration_seconds_input,
|
| 347 |
guidance_scale_input, guidance_scale_2_input, seed_input, randomize_seed_checkbox,
|
| 348 |
+
quality_slider, live_wallpaper_style_checkbox
|
| 349 |
]
|
| 350 |
generate_button.click(fn=generate_video, inputs=ui_inputs, outputs=[video_output, file_output, seed_input])
|
| 351 |
|