dream2589632147 commited on
Commit
24bb430
·
verified ·
1 Parent(s): 4aaab6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -14
app.py CHANGED
@@ -10,7 +10,6 @@ import numpy as np
10
  from PIL import Image
11
  import random
12
  import gc
13
-
14
  from torchao.quantization import quantize_
15
  from torchao.quantization import Float8DynamicActivationFloat8WeightConfig, Int8WeightOnlyConfig
16
  import aoti
@@ -25,13 +24,11 @@ MAX_DIM = 832
25
  MIN_DIM = 480
26
  SQUARE_DIM = 640
27
  MULTIPLE_OF = 16
28
-
29
  MAX_SEED = np.iinfo(np.int32).max
30
 
31
  FIXED_FPS = 16
32
  MIN_FRAMES_MODEL = 8
33
  MAX_FRAMES_MODEL = 7720
34
-
35
  MIN_DURATION = round(MIN_FRAMES_MODEL / FIXED_FPS, 1)
36
  MAX_DURATION = round(MAX_FRAMES_MODEL / FIXED_FPS, 1)
37
 
@@ -95,6 +92,7 @@ aoti.aoti_blocks_load(pipe.transformer_2, 'zerogpu-aoti/Wan2', variant='fp8da')
95
  # DEFAULT PROMPTS
96
  # =========================================================
97
  default_prompt_i2v = "Make this image come alive with dynamic, cinematic human motion. Create smooth, natural, lifelike animation with fluid transitions, expressive body movement, realistic physics, and elegant camera flow. Deliver a polished, high-quality motion style that feels immersive, artistic, and visually captivating."
 
98
  default_negative_prompt = (
99
  "low quality, worst quality, motion artifacts, unstable motion, jitter, frame jitter, wobbling limbs, motion distortion, inconsistent movement, robotic movement, animation-like motion, awkward transitions, incorrect body mechanics, unnatural posing, off-balance poses, broken motion paths, frozen frames, duplicated frames, frame skipping, warped motion, stretching artifacts bad anatomy, incorrect proportions, deformed body, twisted torso, broken joints, dislocated limbs, distorted neck, unnatural spine curvature, malformed hands, extra fingers, missing fingers, fused fingers, distorted legs, extra limbs, collapsed feet, floating feet, foot sliding, foot jitter, backward walking, unnatural gait blurry details, long exposure blur, ghosting, shadow trails, smearing, washed-out colors, overexposure, underexposure, excessive contrast, blown highlights, poorly rendered clothing, fabric glitches, texture warping, clothing merging with body, incorrect cloth physics ugly background, cluttered scene, crowded background, random objects, unwanted text, subtitles, logos, graffiti, grain, noise, static artifacts, compression noise, jpeg artifacts, image-like stillness, painting-like look, cartoon texture, low-resolution textures"
100
  )
@@ -106,13 +104,12 @@ def resize_image(image: Image.Image) -> Image.Image:
106
  width, height = image.size
107
  if width == height:
108
  return image.resize((SQUARE_DIM, SQUARE_DIM), Image.LANCZOS)
109
-
110
  aspect_ratio = width / height
111
  MAX_ASPECT_RATIO = MAX_DIM / MIN_DIM
112
  MIN_ASPECT_RATIO = MIN_DIM / MAX_DIM
113
 
114
  image_to_resize = image
115
-
116
  if aspect_ratio > MAX_ASPECT_RATIO:
117
  crop_width = int(round(height * MAX_ASPECT_RATIO))
118
  left = (width - crop_width) // 2
@@ -121,20 +118,20 @@ def resize_image(image: Image.Image) -> Image.Image:
121
  crop_height = int(round(width / MIN_ASPECT_RATIO))
122
  top = (height - crop_height) // 2
123
  image_to_resize = image.crop((0, top, width, top + crop_height))
124
-
125
  if width > height:
126
  target_w = MAX_DIM
127
  target_h = int(round(target_w / aspect_ratio))
128
  else:
129
  target_h = MAX_DIM
130
  target_w = int(round(target_h * aspect_ratio))
131
-
132
  final_w = round(target_w / MULTIPLE_OF) * MULTIPLE_OF
133
  final_h = round(target_h / MULTIPLE_OF) * MULTIPLE_OF
134
-
135
  final_w = max(MIN_DIM, min(MAX_DIM, final_w))
136
  final_h = max(MIN_DIM, min(MAX_DIM, final_h))
137
-
138
  return image_to_resize.resize((final_w, final_h), Image.LANCZOS)
139
 
140
  # =========================================================
@@ -152,9 +149,9 @@ def get_duration(
152
  if input_image is None:
153
  return 120 # Return default duration if image is missing to prevent crash
154
  # -----------------------------------------------------
155
-
156
  BASE_FRAMES_HEIGHT_WIDTH = 81 * 832 * 624
157
  BASE_STEP_DURATION = 15
 
158
  width, height = resize_image(input_image).size
159
  frames = get_num_frames(duration_seconds)
160
  factor = frames * width * height / BASE_FRAMES_HEIGHT_WIDTH
@@ -179,7 +176,7 @@ def generate_video(
179
  ):
180
  if input_image is None:
181
  raise gr.Error("Please upload an input image.")
182
-
183
  num_frames = get_num_frames(duration_seconds)
184
  current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
185
  resized_image = resize_image(input_image)
@@ -199,6 +196,7 @@ def generate_video(
199
 
200
  with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
201
  video_path = tmpfile.name
 
202
  export_to_video(output_frames_list, video_path, fps=FIXED_FPS)
203
  return video_path, current_seed
204
 
@@ -209,7 +207,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
209
 
210
  # --- ADVERTISEMENT BANNER FOR DREAM HUB PRO ---
211
  gr.HTML("""
212
- <div style="background: linear-gradient(90deg, #4f46e5, #9333ea); color: white; padding: 15px; border-radius: 10px; text-align: center; margin-bottom: 20px; box-shadow: 0 4px 15px rgba(0,0,0,0.1);">
213
  <div style="display: flex; align-items: center; justify-content: center; gap: 20px; flex-wrap: wrap;">
214
  <div style="text-align: left;">
215
  <h3 style="margin: 0; font-weight: bold; font-size: 18px;">✨ New: Dream Hub Pro (All-in-One)</h3>
@@ -223,6 +221,26 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
223
  </div>
224
  </div>
225
  """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  # ---------------------------------------------
227
 
228
  gr.Markdown("# 🚀 Dream Wan 2.2 Faster Pro (14B) — Ultra Fast I2V with Lightning LoRA")
@@ -232,12 +250,13 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
232
  with gr.Column():
233
  input_image_component = gr.Image(type="pil", label="Input Image")
234
  prompt_input = gr.Textbox(label="Prompt", value=default_prompt_i2v)
 
235
  duration_seconds_input = gr.Slider(
236
  minimum=MIN_DURATION, maximum=MAX_DURATION, step=0.1, value=3.5,
237
  label="Duration (seconds)",
238
  info=f"Model range: {MIN_FRAMES_MODEL}-{MAX_FRAMES_MODEL} frames at {FIXED_FPS}fps."
239
  )
240
-
241
  with gr.Accordion("Advanced Settings", open=False):
242
  negative_prompt_input = gr.Textbox(label="Negative Prompt", value=default_negative_prompt, lines=3)
243
  seed_input = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42)
@@ -245,7 +264,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
245
  steps_slider = gr.Slider(minimum=1, maximum=30, step=1, value=6, label="Inference Steps")
246
  guidance_scale_input = gr.Slider(minimum=0.0, maximum=10.0, step=0.5, value=1, label="Guidance Scale (high noise)")
247
  guidance_scale_2_input = gr.Slider(minimum=0.0, maximum=10.0, step=0.5, value=1, label="Guidance Scale 2 (low noise)")
248
-
249
  generate_button = gr.Button("🎬 Generate Video", variant="primary")
250
 
251
  with gr.Column():
@@ -257,6 +276,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
257
  guidance_scale_input, guidance_scale_2_input,
258
  seed_input, randomize_seed_checkbox
259
  ]
 
260
  generate_button.click(fn=generate_video, inputs=ui_inputs, outputs=[video_output, seed_input])
261
 
262
  gr.Examples(
 
10
  from PIL import Image
11
  import random
12
  import gc
 
13
  from torchao.quantization import quantize_
14
  from torchao.quantization import Float8DynamicActivationFloat8WeightConfig, Int8WeightOnlyConfig
15
  import aoti
 
24
  MIN_DIM = 480
25
  SQUARE_DIM = 640
26
  MULTIPLE_OF = 16
 
27
  MAX_SEED = np.iinfo(np.int32).max
28
 
29
  FIXED_FPS = 16
30
  MIN_FRAMES_MODEL = 8
31
  MAX_FRAMES_MODEL = 7720
 
32
  MIN_DURATION = round(MIN_FRAMES_MODEL / FIXED_FPS, 1)
33
  MAX_DURATION = round(MAX_FRAMES_MODEL / FIXED_FPS, 1)
34
 
 
92
  # DEFAULT PROMPTS
93
  # =========================================================
94
  default_prompt_i2v = "Make this image come alive with dynamic, cinematic human motion. Create smooth, natural, lifelike animation with fluid transitions, expressive body movement, realistic physics, and elegant camera flow. Deliver a polished, high-quality motion style that feels immersive, artistic, and visually captivating."
95
+
96
  default_negative_prompt = (
97
  "low quality, worst quality, motion artifacts, unstable motion, jitter, frame jitter, wobbling limbs, motion distortion, inconsistent movement, robotic movement, animation-like motion, awkward transitions, incorrect body mechanics, unnatural posing, off-balance poses, broken motion paths, frozen frames, duplicated frames, frame skipping, warped motion, stretching artifacts bad anatomy, incorrect proportions, deformed body, twisted torso, broken joints, dislocated limbs, distorted neck, unnatural spine curvature, malformed hands, extra fingers, missing fingers, fused fingers, distorted legs, extra limbs, collapsed feet, floating feet, foot sliding, foot jitter, backward walking, unnatural gait blurry details, long exposure blur, ghosting, shadow trails, smearing, washed-out colors, overexposure, underexposure, excessive contrast, blown highlights, poorly rendered clothing, fabric glitches, texture warping, clothing merging with body, incorrect cloth physics ugly background, cluttered scene, crowded background, random objects, unwanted text, subtitles, logos, graffiti, grain, noise, static artifacts, compression noise, jpeg artifacts, image-like stillness, painting-like look, cartoon texture, low-resolution textures"
98
  )
 
104
  width, height = image.size
105
  if width == height:
106
  return image.resize((SQUARE_DIM, SQUARE_DIM), Image.LANCZOS)
107
+
108
  aspect_ratio = width / height
109
  MAX_ASPECT_RATIO = MAX_DIM / MIN_DIM
110
  MIN_ASPECT_RATIO = MIN_DIM / MAX_DIM
111
 
112
  image_to_resize = image
 
113
  if aspect_ratio > MAX_ASPECT_RATIO:
114
  crop_width = int(round(height * MAX_ASPECT_RATIO))
115
  left = (width - crop_width) // 2
 
118
  crop_height = int(round(width / MIN_ASPECT_RATIO))
119
  top = (height - crop_height) // 2
120
  image_to_resize = image.crop((0, top, width, top + crop_height))
121
+
122
  if width > height:
123
  target_w = MAX_DIM
124
  target_h = int(round(target_w / aspect_ratio))
125
  else:
126
  target_h = MAX_DIM
127
  target_w = int(round(target_h * aspect_ratio))
128
+
129
  final_w = round(target_w / MULTIPLE_OF) * MULTIPLE_OF
130
  final_h = round(target_h / MULTIPLE_OF) * MULTIPLE_OF
131
+
132
  final_w = max(MIN_DIM, min(MAX_DIM, final_w))
133
  final_h = max(MIN_DIM, min(MAX_DIM, final_h))
134
+
135
  return image_to_resize.resize((final_w, final_h), Image.LANCZOS)
136
 
137
  # =========================================================
 
149
  if input_image is None:
150
  return 120 # Return default duration if image is missing to prevent crash
151
  # -----------------------------------------------------
 
152
  BASE_FRAMES_HEIGHT_WIDTH = 81 * 832 * 624
153
  BASE_STEP_DURATION = 15
154
+
155
  width, height = resize_image(input_image).size
156
  frames = get_num_frames(duration_seconds)
157
  factor = frames * width * height / BASE_FRAMES_HEIGHT_WIDTH
 
176
  ):
177
  if input_image is None:
178
  raise gr.Error("Please upload an input image.")
179
+
180
  num_frames = get_num_frames(duration_seconds)
181
  current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
182
  resized_image = resize_image(input_image)
 
196
 
197
  with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
198
  video_path = tmpfile.name
199
+
200
  export_to_video(output_frames_list, video_path, fps=FIXED_FPS)
201
  return video_path, current_seed
202
 
 
207
 
208
  # --- ADVERTISEMENT BANNER FOR DREAM HUB PRO ---
209
  gr.HTML("""
210
+ <div style="background: linear-gradient(90deg, #4f46e5, #9333ea); color: white; padding: 15px; border-radius: 10px; text-align: center; margin-bottom: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1);">
211
  <div style="display: flex; align-items: center; justify-content: center; gap: 20px; flex-wrap: wrap;">
212
  <div style="text-align: left;">
213
  <h3 style="margin: 0; font-weight: bold; font-size: 18px;">✨ New: Dream Hub Pro (All-in-One)</h3>
 
221
  </div>
222
  </div>
223
  """)
224
+
225
+ # --- NEW: PROFESSIONAL YOUTUBE CHANNEL BANNER ---
226
+ gr.HTML("""
227
+ <div style="background: linear-gradient(90deg, #cc0000, #ff0000); color: white; padding: 12px; border-radius: 10px; text-align: center; margin-bottom: 20px; box-shadow: 0 4px 15px rgba(255,0,0,0.2);">
228
+ <div style="display: flex; align-items: center; justify-content: center; gap: 20px; flex-wrap: wrap;">
229
+ <div style="display: flex; align-items: center; gap: 10px;">
230
+ <span style="font-size: 28px;">▶️</span>
231
+ <div style="text-align: left;">
232
+ <h3 style="margin: 0; font-weight: bold; font-size: 18px;">Imagination Engineering</h3>
233
+ <p style="margin: 2px 0 0 0; opacity: 0.9; font-size: 13px;">Tutorials, AI Engineering & Creative Tech</p>
234
+ </div>
235
+ </div>
236
+ <a href="https://www.youtube.com/@ImaginationEngineering" target="_blank" style="text-decoration: none;">
237
+ <button style="background-color: white; color: #cc0000; border: none; padding: 8px 25px; border-radius: 25px; font-weight: bold; cursor: pointer; transition: transform 0.2s; font-size: 15px; box-shadow: 0 2px 5px rgba(0,0,0,0.2);">
238
+ Subscribe & Watch 📺
239
+ </button>
240
+ </a>
241
+ </div>
242
+ </div>
243
+ """)
244
  # ---------------------------------------------
245
 
246
  gr.Markdown("# 🚀 Dream Wan 2.2 Faster Pro (14B) — Ultra Fast I2V with Lightning LoRA")
 
250
  with gr.Column():
251
  input_image_component = gr.Image(type="pil", label="Input Image")
252
  prompt_input = gr.Textbox(label="Prompt", value=default_prompt_i2v)
253
+
254
  duration_seconds_input = gr.Slider(
255
  minimum=MIN_DURATION, maximum=MAX_DURATION, step=0.1, value=3.5,
256
  label="Duration (seconds)",
257
  info=f"Model range: {MIN_FRAMES_MODEL}-{MAX_FRAMES_MODEL} frames at {FIXED_FPS}fps."
258
  )
259
+
260
  with gr.Accordion("Advanced Settings", open=False):
261
  negative_prompt_input = gr.Textbox(label="Negative Prompt", value=default_negative_prompt, lines=3)
262
  seed_input = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42)
 
264
  steps_slider = gr.Slider(minimum=1, maximum=30, step=1, value=6, label="Inference Steps")
265
  guidance_scale_input = gr.Slider(minimum=0.0, maximum=10.0, step=0.5, value=1, label="Guidance Scale (high noise)")
266
  guidance_scale_2_input = gr.Slider(minimum=0.0, maximum=10.0, step=0.5, value=1, label="Guidance Scale 2 (low noise)")
267
+
268
  generate_button = gr.Button("🎬 Generate Video", variant="primary")
269
 
270
  with gr.Column():
 
276
  guidance_scale_input, guidance_scale_2_input,
277
  seed_input, randomize_seed_checkbox
278
  ]
279
+
280
  generate_button.click(fn=generate_video, inputs=ui_inputs, outputs=[video_output, seed_input])
281
 
282
  gr.Examples(