Revert "Revert to 8acf492"
Browse filesThis reverts commit 39b7e2924078ef6cf9a66647334f1c268698166b.
- README.md +3 -3
- app.py +11 -17
- optimization.py +1 -7
README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.38.2
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Wan 2.2 fp8-dynamic 81 frames
|
| 3 |
+
emoji: 🎥
|
| 4 |
+
colorFrom: red
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.38.2
|
app.py
CHANGED
|
@@ -27,9 +27,6 @@ FIXED_FPS = 24
|
|
| 27 |
MIN_FRAMES_MODEL = 8
|
| 28 |
MAX_FRAMES_MODEL = 81
|
| 29 |
|
| 30 |
-
MIN_DURATION = round(MIN_FRAMES_MODEL/FIXED_FPS,1)
|
| 31 |
-
MAX_DURATION = round(MAX_FRAMES_MODEL/FIXED_FPS,1)
|
| 32 |
-
|
| 33 |
|
| 34 |
pipe = WanImageToVideoPipeline.from_pretrained(MODEL_ID,
|
| 35 |
transformer=WanTransformer3DModel.from_pretrained('cbensimon/Wan2.2-I2V-A14B-bf16-Diffusers',
|
|
@@ -56,7 +53,7 @@ optimize_pipeline_(pipe,
|
|
| 56 |
|
| 57 |
|
| 58 |
default_prompt_i2v = "make this image come alive, cinematic motion, smooth animation"
|
| 59 |
-
default_negative_prompt = "
|
| 60 |
|
| 61 |
|
| 62 |
def resize_image(image: Image.Image) -> Image.Image:
|
|
@@ -85,7 +82,7 @@ def get_duration(
|
|
| 85 |
input_image,
|
| 86 |
prompt,
|
| 87 |
negative_prompt,
|
| 88 |
-
|
| 89 |
guidance_scale,
|
| 90 |
steps,
|
| 91 |
seed,
|
|
@@ -99,9 +96,9 @@ def generate_video(
|
|
| 99 |
input_image,
|
| 100 |
prompt,
|
| 101 |
negative_prompt=default_negative_prompt,
|
| 102 |
-
|
| 103 |
-
guidance_scale =
|
| 104 |
-
steps =
|
| 105 |
seed = 42,
|
| 106 |
randomize_seed = False,
|
| 107 |
progress=gr.Progress(track_tqdm=True),
|
|
@@ -118,8 +115,8 @@ def generate_video(
|
|
| 118 |
prompt (str): Text prompt describing the desired animation or motion.
|
| 119 |
negative_prompt (str, optional): Negative prompt to avoid unwanted elements.
|
| 120 |
Defaults to default_negative_prompt (contains unwanted visual artifacts).
|
| 121 |
-
|
| 122 |
-
Defaults to
|
| 123 |
guidance_scale (float, optional): Controls adherence to the prompt. Higher values = more adherence.
|
| 124 |
Defaults to 1.0. Range: 0.0-20.0.
|
| 125 |
steps (int, optional): Number of inference steps. More steps = higher quality but slower.
|
|
@@ -140,15 +137,12 @@ def generate_video(
|
|
| 140 |
|
| 141 |
Note:
|
| 142 |
- The function automatically resizes the input image to the target dimensions
|
| 143 |
-
- Frame count is calculated as duration_seconds * FIXED_FPS (24)
|
| 144 |
- Output dimensions are adjusted to be multiples of MOD_VALUE (32)
|
| 145 |
- The function uses GPU acceleration via the @spaces.GPU decorator
|
| 146 |
-
- Generation time varies based on steps and duration (see get_duration function)
|
| 147 |
"""
|
| 148 |
if input_image is None:
|
| 149 |
raise gr.Error("Please upload an input image.")
|
| 150 |
|
| 151 |
-
num_frames = np.clip(int(round(duration_seconds * FIXED_FPS)), MIN_FRAMES_MODEL, MAX_FRAMES_MODEL)
|
| 152 |
current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
|
| 153 |
resized_image = resize_image(input_image)
|
| 154 |
|
|
@@ -178,14 +172,14 @@ with gr.Blocks() as demo:
|
|
| 178 |
with gr.Column():
|
| 179 |
input_image_component = gr.Image(type="pil", label="Input Image (auto-resized to target H/W)")
|
| 180 |
prompt_input = gr.Textbox(label="Prompt", value=default_prompt_i2v)
|
| 181 |
-
|
| 182 |
|
| 183 |
with gr.Accordion("Advanced Settings", open=False):
|
| 184 |
negative_prompt_input = gr.Textbox(label="Negative Prompt", value=default_negative_prompt, lines=3)
|
| 185 |
seed_input = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42, interactive=True)
|
| 186 |
randomize_seed_checkbox = gr.Checkbox(label="Randomize seed", value=True, interactive=True)
|
| 187 |
-
steps_slider = gr.Slider(minimum=1, maximum=
|
| 188 |
-
guidance_scale_input = gr.Slider(minimum=0.0, maximum=20.0, step=0.5, value=1.0, label="Guidance Scale"
|
| 189 |
|
| 190 |
generate_button = gr.Button("Generate Video", variant="primary")
|
| 191 |
with gr.Column():
|
|
@@ -193,7 +187,7 @@ with gr.Blocks() as demo:
|
|
| 193 |
|
| 194 |
ui_inputs = [
|
| 195 |
input_image_component, prompt_input,
|
| 196 |
-
negative_prompt_input,
|
| 197 |
guidance_scale_input, steps_slider, seed_input, randomize_seed_checkbox
|
| 198 |
]
|
| 199 |
generate_button.click(fn=generate_video, inputs=ui_inputs, outputs=[video_output, seed_input])
|
|
|
|
| 27 |
MIN_FRAMES_MODEL = 8
|
| 28 |
MAX_FRAMES_MODEL = 81
|
| 29 |
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
pipe = WanImageToVideoPipeline.from_pretrained(MODEL_ID,
|
| 32 |
transformer=WanTransformer3DModel.from_pretrained('cbensimon/Wan2.2-I2V-A14B-bf16-Diffusers',
|
|
|
|
| 53 |
|
| 54 |
|
| 55 |
default_prompt_i2v = "make this image come alive, cinematic motion, smooth animation"
|
| 56 |
+
default_negative_prompt = "色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走"
|
| 57 |
|
| 58 |
|
| 59 |
def resize_image(image: Image.Image) -> Image.Image:
|
|
|
|
| 82 |
input_image,
|
| 83 |
prompt,
|
| 84 |
negative_prompt,
|
| 85 |
+
num_frames,
|
| 86 |
guidance_scale,
|
| 87 |
steps,
|
| 88 |
seed,
|
|
|
|
| 96 |
input_image,
|
| 97 |
prompt,
|
| 98 |
negative_prompt=default_negative_prompt,
|
| 99 |
+
num_frames = MAX_FRAMES_MODEL,
|
| 100 |
+
guidance_scale = 3.5,
|
| 101 |
+
steps = 28,
|
| 102 |
seed = 42,
|
| 103 |
randomize_seed = False,
|
| 104 |
progress=gr.Progress(track_tqdm=True),
|
|
|
|
| 115 |
prompt (str): Text prompt describing the desired animation or motion.
|
| 116 |
negative_prompt (str, optional): Negative prompt to avoid unwanted elements.
|
| 117 |
Defaults to default_negative_prompt (contains unwanted visual artifacts).
|
| 118 |
+
num_frames (int, optional): Number of frames.
|
| 119 |
+
Defaults to MAX_FRAMES_MODEL
|
| 120 |
guidance_scale (float, optional): Controls adherence to the prompt. Higher values = more adherence.
|
| 121 |
Defaults to 1.0. Range: 0.0-20.0.
|
| 122 |
steps (int, optional): Number of inference steps. More steps = higher quality but slower.
|
|
|
|
| 137 |
|
| 138 |
Note:
|
| 139 |
- The function automatically resizes the input image to the target dimensions
|
|
|
|
| 140 |
- Output dimensions are adjusted to be multiples of MOD_VALUE (32)
|
| 141 |
- The function uses GPU acceleration via the @spaces.GPU decorator
|
|
|
|
| 142 |
"""
|
| 143 |
if input_image is None:
|
| 144 |
raise gr.Error("Please upload an input image.")
|
| 145 |
|
|
|
|
| 146 |
current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
|
| 147 |
resized_image = resize_image(input_image)
|
| 148 |
|
|
|
|
| 172 |
with gr.Column():
|
| 173 |
input_image_component = gr.Image(type="pil", label="Input Image (auto-resized to target H/W)")
|
| 174 |
prompt_input = gr.Textbox(label="Prompt", value=default_prompt_i2v)
|
| 175 |
+
num_frames_input = gr.Slider(minimum=MIN_FRAMES_MODEL, maximum=MAX_FRAMES_MODEL, step=1, value=MAX_FRAMES_MODEL, label="Frames")
|
| 176 |
|
| 177 |
with gr.Accordion("Advanced Settings", open=False):
|
| 178 |
negative_prompt_input = gr.Textbox(label="Negative Prompt", value=default_negative_prompt, lines=3)
|
| 179 |
seed_input = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42, interactive=True)
|
| 180 |
randomize_seed_checkbox = gr.Checkbox(label="Randomize seed", value=True, interactive=True)
|
| 181 |
+
steps_slider = gr.Slider(minimum=1, maximum=40, step=1, value=28, label="Inference Steps")
|
| 182 |
+
guidance_scale_input = gr.Slider(minimum=0.0, maximum=20.0, step=0.5, value=1.0, label="Guidance Scale")
|
| 183 |
|
| 184 |
generate_button = gr.Button("Generate Video", variant="primary")
|
| 185 |
with gr.Column():
|
|
|
|
| 187 |
|
| 188 |
ui_inputs = [
|
| 189 |
input_image_component, prompt_input,
|
| 190 |
+
negative_prompt_input, num_frames_input,
|
| 191 |
guidance_scale_input, steps_slider, seed_input, randomize_seed_checkbox
|
| 192 |
]
|
| 193 |
generate_button.click(fn=generate_video, inputs=ui_inputs, outputs=[video_output, seed_input])
|
optimization.py
CHANGED
|
@@ -20,13 +20,7 @@ from optimization_utils import ZeroGPUCompiledModel
|
|
| 20 |
P = ParamSpec('P')
|
| 21 |
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
TRANSFORMER_DYNAMIC_SHAPES = {
|
| 26 |
-
'hidden_states': {
|
| 27 |
-
2: TRANSFORMER_NUM_FRAMES_DIM,
|
| 28 |
-
},
|
| 29 |
-
}
|
| 30 |
|
| 31 |
INDUCTOR_CONFIGS = {
|
| 32 |
'conv_1x1_as_mm': True,
|
|
|
|
| 20 |
P = ParamSpec('P')
|
| 21 |
|
| 22 |
|
| 23 |
+
TRANSFORMER_DYNAMIC_SHAPES = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
INDUCTOR_CONFIGS = {
|
| 26 |
'conv_1x1_as_mm': True,
|