Spaces:
Runtime error
Runtime error
No more duration, only frames
Browse files
app.py
CHANGED
|
@@ -27,9 +27,6 @@ FIXED_FPS = 24
|
|
| 27 |
MIN_FRAMES_MODEL = 8
|
| 28 |
MAX_FRAMES_MODEL = 121
|
| 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',
|
|
@@ -85,7 +82,7 @@ def get_duration(
|
|
| 85 |
input_image,
|
| 86 |
prompt,
|
| 87 |
negative_prompt,
|
| 88 |
-
|
| 89 |
guidance_scale,
|
| 90 |
steps,
|
| 91 |
seed,
|
|
@@ -99,7 +96,7 @@ def generate_video(
|
|
| 99 |
input_image,
|
| 100 |
prompt,
|
| 101 |
negative_prompt=default_negative_prompt,
|
| 102 |
-
|
| 103 |
guidance_scale = 3.5,
|
| 104 |
steps = 28,
|
| 105 |
seed = 42,
|
|
@@ -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,7 +172,7 @@ 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)
|
|
@@ -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 = 121
|
| 29 |
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
pipe = WanImageToVideoPipeline.from_pretrained(MODEL_ID,
|
| 32 |
transformer=WanTransformer3DModel.from_pretrained('cbensimon/Wan2.2-I2V-A14B-bf16-Diffusers',
|
|
|
|
| 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,
|
|
|
|
| 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)
|
|
|
|
| 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])
|