Revert to 8acf492
Browse files- README.md +3 -3
- app.py +17 -11
- optimization.py +7 -1
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: Wan2 2 Fp8da Aoti
|
| 3 |
+
emoji: 🐨
|
| 4 |
+
colorFrom: gray
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.38.2
|
app.py
CHANGED
|
@@ -27,6 +27,9 @@ FIXED_FPS = 24
|
|
| 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,7 +56,7 @@ optimize_pipeline_(pipe,
|
|
| 53 |
|
| 54 |
|
| 55 |
default_prompt_i2v = "make this image come alive, cinematic motion, smooth animation"
|
| 56 |
-
default_negative_prompt = "
|
| 57 |
|
| 58 |
|
| 59 |
def resize_image(image: Image.Image) -> Image.Image:
|
|
@@ -82,7 +85,7 @@ def get_duration(
|
|
| 82 |
input_image,
|
| 83 |
prompt,
|
| 84 |
negative_prompt,
|
| 85 |
-
|
| 86 |
guidance_scale,
|
| 87 |
steps,
|
| 88 |
seed,
|
|
@@ -96,9 +99,9 @@ def generate_video(
|
|
| 96 |
input_image,
|
| 97 |
prompt,
|
| 98 |
negative_prompt=default_negative_prompt,
|
| 99 |
-
|
| 100 |
-
guidance_scale =
|
| 101 |
-
steps =
|
| 102 |
seed = 42,
|
| 103 |
randomize_seed = False,
|
| 104 |
progress=gr.Progress(track_tqdm=True),
|
|
@@ -115,8 +118,8 @@ def generate_video(
|
|
| 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 |
-
|
| 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,12 +140,15 @@ def generate_video(
|
|
| 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,14 +178,14 @@ with gr.Blocks() as demo:
|
|
| 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 |
-
|
| 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=
|
| 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,7 +193,7 @@ with gr.Blocks() as demo:
|
|
| 187 |
|
| 188 |
ui_inputs = [
|
| 189 |
input_image_component, prompt_input,
|
| 190 |
-
negative_prompt_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])
|
|
|
|
| 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 |
|
| 57 |
|
| 58 |
default_prompt_i2v = "make this image come alive, cinematic motion, smooth animation"
|
| 59 |
+
default_negative_prompt = "色调艳丽, 过曝, 静态, 细节模糊不清, 字幕, 风格, 作品, 画作, 画面, 静止, 整体发灰, 最差质量, 低质量, JPEG压缩残留, 丑陋的, 残缺的, 多余的手指, 画得不好的手部, 画得不好的脸部, 畸形的, 毁容的, 形态畸形的肢体, 手指融合, 静止不动的画面, 杂乱的背景, 三条腿, 背景人很多, 倒着走"
|
| 60 |
|
| 61 |
|
| 62 |
def resize_image(image: Image.Image) -> Image.Image:
|
|
|
|
| 85 |
input_image,
|
| 86 |
prompt,
|
| 87 |
negative_prompt,
|
| 88 |
+
duration_seconds,
|
| 89 |
guidance_scale,
|
| 90 |
steps,
|
| 91 |
seed,
|
|
|
|
| 99 |
input_image,
|
| 100 |
prompt,
|
| 101 |
negative_prompt=default_negative_prompt,
|
| 102 |
+
duration_seconds = MAX_DURATION,
|
| 103 |
+
guidance_scale = 1,
|
| 104 |
+
steps = 4,
|
| 105 |
seed = 42,
|
| 106 |
randomize_seed = False,
|
| 107 |
progress=gr.Progress(track_tqdm=True),
|
|
|
|
| 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 |
+
duration_seconds (float, optional): Duration of the generated video in seconds.
|
| 122 |
+
Defaults to 2. Clamped between MIN_FRAMES_MODEL/FIXED_FPS and MAX_FRAMES_MODEL/FIXED_FPS.
|
| 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 |
|
| 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 |
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 |
+
duration_seconds_input = gr.Slider(minimum=MIN_DURATION, maximum=MAX_DURATION, step=0.1, value=MAX_DURATION, label="Duration (seconds)", info=f"Clamped to model's {MIN_FRAMES_MODEL}-{MAX_FRAMES_MODEL} frames at {FIXED_FPS}fps.")
|
| 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=30, step=1, value=4, label="Inference Steps")
|
| 188 |
+
guidance_scale_input = gr.Slider(minimum=0.0, maximum=20.0, step=0.5, value=1.0, label="Guidance Scale", visible=False)
|
| 189 |
|
| 190 |
generate_button = gr.Button("Generate Video", variant="primary")
|
| 191 |
with gr.Column():
|
|
|
|
| 193 |
|
| 194 |
ui_inputs = [
|
| 195 |
input_image_component, prompt_input,
|
| 196 |
+
negative_prompt_input, duration_seconds_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])
|
optimization.py
CHANGED
|
@@ -20,7 +20,13 @@ from optimization_utils import ZeroGPUCompiledModel
|
|
| 20 |
P = ParamSpec('P')
|
| 21 |
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
INDUCTOR_CONFIGS = {
|
| 26 |
'conv_1x1_as_mm': True,
|
|
|
|
| 20 |
P = ParamSpec('P')
|
| 21 |
|
| 22 |
|
| 23 |
+
TRANSFORMER_NUM_FRAMES_DIM = torch.export.Dim('num_frames', min=3, max=21)
|
| 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,
|