Spaces:
Running
on
Zero
Running
on
Zero
lora
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ import tempfile
|
|
| 13 |
import numpy as np
|
| 14 |
from PIL import Image
|
| 15 |
import random
|
| 16 |
-
|
| 17 |
from optimization import optimize_pipeline_
|
| 18 |
|
| 19 |
|
|
@@ -23,7 +23,7 @@ LANDSCAPE_WIDTH = 832
|
|
| 23 |
LANDSCAPE_HEIGHT = 480
|
| 24 |
MAX_SEED = np.iinfo(np.int32).max
|
| 25 |
|
| 26 |
-
FIXED_FPS =
|
| 27 |
MIN_FRAMES_MODEL = 8
|
| 28 |
MAX_FRAMES_MODEL = 81
|
| 29 |
|
|
@@ -45,8 +45,17 @@ pipe = WanImageToVideoPipeline.from_pretrained(MODEL_ID,
|
|
| 45 |
torch_dtype=torch.bfloat16,
|
| 46 |
).to('cuda')
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
#apply_first_block_cache(pipe.transformer, FirstBlockCacheConfig(threshold=0.05))
|
| 50 |
|
| 51 |
optimize_pipeline_(pipe,
|
| 52 |
image=Image.new('RGB', (LANDSCAPE_WIDTH, LANDSCAPE_HEIGHT)),
|
|
@@ -89,6 +98,7 @@ def get_duration(
|
|
| 89 |
negative_prompt,
|
| 90 |
duration_seconds,
|
| 91 |
guidance_scale,
|
|
|
|
| 92 |
steps,
|
| 93 |
seed,
|
| 94 |
randomize_seed,
|
|
@@ -102,8 +112,9 @@ def generate_video(
|
|
| 102 |
prompt,
|
| 103 |
negative_prompt=default_negative_prompt,
|
| 104 |
duration_seconds = MAX_DURATION,
|
| 105 |
-
guidance_scale =
|
| 106 |
-
|
|
|
|
| 107 |
seed = 42,
|
| 108 |
randomize_seed = False,
|
| 109 |
progress=gr.Progress(track_tqdm=True),
|
|
@@ -124,6 +135,8 @@ def generate_video(
|
|
| 124 |
Defaults to 2. Clamped between MIN_FRAMES_MODEL/FIXED_FPS and MAX_FRAMES_MODEL/FIXED_FPS.
|
| 125 |
guidance_scale (float, optional): Controls adherence to the prompt. Higher values = more adherence.
|
| 126 |
Defaults to 1.0. Range: 0.0-20.0.
|
|
|
|
|
|
|
| 127 |
steps (int, optional): Number of inference steps. More steps = higher quality but slower.
|
| 128 |
Defaults to 4. Range: 1-30.
|
| 129 |
seed (int, optional): Random seed for reproducible results. Defaults to 42.
|
|
@@ -162,6 +175,7 @@ def generate_video(
|
|
| 162 |
width=resized_image.width,
|
| 163 |
num_frames=num_frames,
|
| 164 |
guidance_scale=float(guidance_scale),
|
|
|
|
| 165 |
num_inference_steps=int(steps),
|
| 166 |
generator=torch.Generator(device="cuda").manual_seed(current_seed),
|
| 167 |
).frames[0]
|
|
@@ -186,8 +200,9 @@ with gr.Blocks() as demo:
|
|
| 186 |
negative_prompt_input = gr.Textbox(label="Negative Prompt", value=default_negative_prompt, lines=3)
|
| 187 |
seed_input = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42, interactive=True)
|
| 188 |
randomize_seed_checkbox = gr.Checkbox(label="Randomize seed", value=True, interactive=True)
|
| 189 |
-
steps_slider = gr.Slider(minimum=1, maximum=
|
| 190 |
-
guidance_scale_input = gr.Slider(minimum=0.0, maximum=
|
|
|
|
| 191 |
|
| 192 |
generate_button = gr.Button("Generate Video", variant="primary")
|
| 193 |
with gr.Column():
|
|
@@ -196,7 +211,7 @@ with gr.Blocks() as demo:
|
|
| 196 |
ui_inputs = [
|
| 197 |
input_image_component, prompt_input,
|
| 198 |
negative_prompt_input, duration_seconds_input,
|
| 199 |
-
guidance_scale_input, steps_slider, seed_input, randomize_seed_checkbox
|
| 200 |
]
|
| 201 |
generate_button.click(fn=generate_video, inputs=ui_inputs, outputs=[video_output, seed_input])
|
| 202 |
|
|
|
|
| 13 |
import numpy as np
|
| 14 |
from PIL import Image
|
| 15 |
import random
|
| 16 |
+
|
| 17 |
from optimization import optimize_pipeline_
|
| 18 |
|
| 19 |
|
|
|
|
| 23 |
LANDSCAPE_HEIGHT = 480
|
| 24 |
MAX_SEED = np.iinfo(np.int32).max
|
| 25 |
|
| 26 |
+
FIXED_FPS = 16
|
| 27 |
MIN_FRAMES_MODEL = 8
|
| 28 |
MAX_FRAMES_MODEL = 81
|
| 29 |
|
|
|
|
| 45 |
torch_dtype=torch.bfloat16,
|
| 46 |
).to('cuda')
|
| 47 |
|
| 48 |
+
# load, fuse, unload before compilation
|
| 49 |
+
pipe.load_lora_weights(
|
| 50 |
+
"Kijai/WanVideo_comfy",
|
| 51 |
+
weight_name="Lightx2v/lightx2v_I2V_14B_480p_cfg_step_distill_rank32_bf16.safetensors",
|
| 52 |
+
adapter_name="lightx2v"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
pipe.set_adapters(["lightx2v"], adapter_weights=[1.0])
|
| 56 |
+
pipe.fuse_lora(adapter_names=["lightx2v"], lora_scale=1.0)
|
| 57 |
+
pipe.unload_lora_weights()
|
| 58 |
|
|
|
|
| 59 |
|
| 60 |
optimize_pipeline_(pipe,
|
| 61 |
image=Image.new('RGB', (LANDSCAPE_WIDTH, LANDSCAPE_HEIGHT)),
|
|
|
|
| 98 |
negative_prompt,
|
| 99 |
duration_seconds,
|
| 100 |
guidance_scale,
|
| 101 |
+
guidance_scale_2,
|
| 102 |
steps,
|
| 103 |
seed,
|
| 104 |
randomize_seed,
|
|
|
|
| 112 |
prompt,
|
| 113 |
negative_prompt=default_negative_prompt,
|
| 114 |
duration_seconds = MAX_DURATION,
|
| 115 |
+
guidance_scale = 2.5,
|
| 116 |
+
guidance_scale_2 = 3.5,
|
| 117 |
+
steps = 6,
|
| 118 |
seed = 42,
|
| 119 |
randomize_seed = False,
|
| 120 |
progress=gr.Progress(track_tqdm=True),
|
|
|
|
| 135 |
Defaults to 2. Clamped between MIN_FRAMES_MODEL/FIXED_FPS and MAX_FRAMES_MODEL/FIXED_FPS.
|
| 136 |
guidance_scale (float, optional): Controls adherence to the prompt. Higher values = more adherence.
|
| 137 |
Defaults to 1.0. Range: 0.0-20.0.
|
| 138 |
+
guidance_scale_2 (float, optional): Controls adherence to the prompt. Higher values = more adherence.
|
| 139 |
+
Defaults to 1.0. Range: 0.0-20.0.
|
| 140 |
steps (int, optional): Number of inference steps. More steps = higher quality but slower.
|
| 141 |
Defaults to 4. Range: 1-30.
|
| 142 |
seed (int, optional): Random seed for reproducible results. Defaults to 42.
|
|
|
|
| 175 |
width=resized_image.width,
|
| 176 |
num_frames=num_frames,
|
| 177 |
guidance_scale=float(guidance_scale),
|
| 178 |
+
guidance_scale_2=float(guidance_scale_2),
|
| 179 |
num_inference_steps=int(steps),
|
| 180 |
generator=torch.Generator(device="cuda").manual_seed(current_seed),
|
| 181 |
).frames[0]
|
|
|
|
| 200 |
negative_prompt_input = gr.Textbox(label="Negative Prompt", value=default_negative_prompt, lines=3)
|
| 201 |
seed_input = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42, interactive=True)
|
| 202 |
randomize_seed_checkbox = gr.Checkbox(label="Randomize seed", value=True, interactive=True)
|
| 203 |
+
steps_slider = gr.Slider(minimum=1, maximum=30, step=1, value=6, label="Inference Steps")
|
| 204 |
+
guidance_scale_input = gr.Slider(minimum=0.0, maximum=10.0, step=0.5, value=2.5, label="Guidance Scale - high noise stage", visible=False)
|
| 205 |
+
guidance_scale_2_input = gr.Slider(minimum=0.0, maximum=10.0, step=0.5, value=3.5, label="Guidance Scale 2 - low noise stage", visible=False)
|
| 206 |
|
| 207 |
generate_button = gr.Button("Generate Video", variant="primary")
|
| 208 |
with gr.Column():
|
|
|
|
| 211 |
ui_inputs = [
|
| 212 |
input_image_component, prompt_input,
|
| 213 |
negative_prompt_input, duration_seconds_input,
|
| 214 |
+
guidance_scale_input, guidance_scale_2_input, steps_slider, seed_input, randomize_seed_checkbox
|
| 215 |
]
|
| 216 |
generate_button.click(fn=generate_video, inputs=ui_inputs, outputs=[video_output, seed_input])
|
| 217 |
|