update
Browse files
app.py
CHANGED
@@ -164,6 +164,8 @@ def generate(
|
|
164 |
randomize_cfg: bool,
|
165 |
text_cfg_scale: float,
|
166 |
image_cfg_scale: float,
|
|
|
|
|
167 |
):
|
168 |
seed = random.randint(0, 100000) if randomize_seed else seed
|
169 |
text_cfg_scale = round(random.uniform(6.0, 9.0), ndigits=2) if randomize_cfg else text_cfg_scale
|
@@ -222,35 +224,30 @@ def generate(
|
|
222 |
edited_mask = Image.fromarray(x_1.type(torch.uint8).cpu().numpy())
|
223 |
|
224 |
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
with imageio.get_writer(image_video_path, fps=fps) as video:
|
248 |
-
for image in image_video:
|
249 |
-
video.append_data(image)
|
250 |
-
|
251 |
|
252 |
# 对edited_mask做膨胀
|
253 |
-
|
254 |
edited_mask_copy = edited_mask.copy()
|
255 |
kernel = np.ones((3, 3), np.uint8)
|
256 |
edited_mask = cv2.dilate(np.array(edited_mask), kernel, iterations=3)
|
@@ -286,7 +283,7 @@ def generate(
|
|
286 |
return [int(seed), text_cfg_scale, image_cfg_scale, edited_image, mix_image, edited_mask_copy, mask_video_path, image_video_path, input_image_copy, mix_result_with_red_mask]
|
287 |
|
288 |
def reset():
|
289 |
-
return [100, "Randomize Seed", 1372, "Fix CFG", 7.5, 1.5, None, None, None, None, None, None, None]
|
290 |
|
291 |
def get_example():
|
292 |
return [
|
@@ -336,8 +333,8 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
|
|
336 |
text_cfg_scale = gr.Number(value=7.5, label=f"Text CFG", interactive=True)
|
337 |
image_cfg_scale = gr.Number(value=1.5, label=f"Image CFG", interactive=True)
|
338 |
with gr.Row():
|
339 |
-
generate_button = gr.Button("Generate")
|
340 |
reset_button = gr.Button("Reset")
|
|
|
341 |
with gr.Column(scale=1, min_width=100):
|
342 |
with gr.Column():
|
343 |
mix_image = gr.Image(label=f"Mix Image", type="pil", interactive=False)
|
@@ -346,6 +343,18 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
|
|
346 |
|
347 |
|
348 |
with gr.Accordion('More outputs', open=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
with gr.Row():
|
350 |
image_video = gr.Video(label="Real-time Image Output")
|
351 |
mask_video = gr.Video(label="Real-time Mask Output")
|
@@ -353,6 +362,7 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
|
|
353 |
original_image = gr.Image(label=f"Original Image", type="pil", interactive=False)
|
354 |
edited_image = gr.Image(label=f"Output Image", type="pil", interactive=False)
|
355 |
mix_result_with_red_mask = gr.Image(label=f"Mix Image With Red Mask", type="pil", interactive=False)
|
|
|
356 |
|
357 |
with gr.Row():
|
358 |
gr.Examples(
|
@@ -374,13 +384,15 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
|
|
374 |
randomize_cfg,
|
375 |
text_cfg_scale,
|
376 |
image_cfg_scale,
|
|
|
|
|
377 |
],
|
378 |
outputs=[seed, text_cfg_scale, image_cfg_scale, edited_image, mix_image, edited_mask, mask_video, image_video, original_image, mix_result_with_red_mask],
|
379 |
)
|
380 |
reset_button.click(
|
381 |
fn=reset,
|
382 |
inputs=[],
|
383 |
-
outputs=[steps, randomize_seed, seed, randomize_cfg, text_cfg_scale, image_cfg_scale, edited_image, mix_image, edited_mask, mask_video, image_video, original_image, mix_result_with_red_mask],
|
384 |
)
|
385 |
|
386 |
|
|
|
164 |
randomize_cfg: bool,
|
165 |
text_cfg_scale: float,
|
166 |
image_cfg_scale: float,
|
167 |
+
weather_hide_video: bool,
|
168 |
+
decode_image_batch: int
|
169 |
):
|
170 |
seed = random.randint(0, 100000) if randomize_seed else seed
|
171 |
text_cfg_scale = round(random.uniform(6.0, 9.0), ndigits=2) if randomize_cfg else text_cfg_scale
|
|
|
224 |
edited_mask = Image.fromarray(x_1.type(torch.uint8).cpu().numpy())
|
225 |
|
226 |
|
227 |
+
image_video_path = None
|
228 |
+
if not weather_hide_video:
|
229 |
+
image_video = []
|
230 |
+
|
231 |
+
for i in range(0, len(image_list), decode_image_batch):
|
232 |
+
if i + decode_image_batch < len(image_list):
|
233 |
+
tmp_image_list = image_list[i:i+decode_image_batch]
|
234 |
+
else:
|
235 |
+
tmp_image_list = image_list[i:]
|
236 |
+
tmp_image_list = model.decode_first_stage(tmp_image_list)
|
237 |
+
tmp_image_list = torch.clamp((tmp_image_list + 1.0) / 2.0, min=0.0, max=1.0)
|
238 |
+
tmp_image_list = 255.0 * rearrange(tmp_image_list, "b c h w -> b h w c")
|
239 |
+
tmp_image_list = tmp_image_list.type(torch.uint8).cpu().numpy()
|
240 |
+
# image list to image
|
241 |
+
for image in tmp_image_list:
|
242 |
+
image_video.append(image)
|
243 |
+
|
244 |
+
image_video_path = "image.mp4"
|
245 |
+
fps = 30
|
246 |
+
with imageio.get_writer(image_video_path, fps=fps) as video:
|
247 |
+
for image in image_video:
|
248 |
+
video.append_data(image)
|
|
|
|
|
|
|
|
|
249 |
|
250 |
# 对edited_mask做膨胀
|
|
|
251 |
edited_mask_copy = edited_mask.copy()
|
252 |
kernel = np.ones((3, 3), np.uint8)
|
253 |
edited_mask = cv2.dilate(np.array(edited_mask), kernel, iterations=3)
|
|
|
283 |
return [int(seed), text_cfg_scale, image_cfg_scale, edited_image, mix_image, edited_mask_copy, mask_video_path, image_video_path, input_image_copy, mix_result_with_red_mask]
|
284 |
|
285 |
def reset():
|
286 |
+
return [100, "Randomize Seed", 1372, "Fix CFG", 7.5, 1.5, None, None, None, None, None, None, None, "Hide Image Video", 10]
|
287 |
|
288 |
def get_example():
|
289 |
return [
|
|
|
333 |
text_cfg_scale = gr.Number(value=7.5, label=f"Text CFG", interactive=True)
|
334 |
image_cfg_scale = gr.Number(value=1.5, label=f"Image CFG", interactive=True)
|
335 |
with gr.Row():
|
|
|
336 |
reset_button = gr.Button("Reset")
|
337 |
+
generate_button = gr.Button("Generate")
|
338 |
with gr.Column(scale=1, min_width=100):
|
339 |
with gr.Column():
|
340 |
mix_image = gr.Image(label=f"Mix Image", type="pil", interactive=False)
|
|
|
343 |
|
344 |
|
345 |
with gr.Accordion('More outputs', open=False):
|
346 |
+
with gr.Row():
|
347 |
+
# 单选框 选择是否显示视频
|
348 |
+
weather_hide_video = gr.Radio(
|
349 |
+
["Show Image Video", "Hide Image Video"],
|
350 |
+
value="Hide Image Video",
|
351 |
+
type="index",
|
352 |
+
label="Dynamic Process",
|
353 |
+
show_label=False,
|
354 |
+
interactive=True,
|
355 |
+
)
|
356 |
+
# decode的batch size,最大为steps的值
|
357 |
+
decode_image_batch = gr.Number(value=10, precision=0, label="Decode Image Batch (<steps)", interactive=True)
|
358 |
with gr.Row():
|
359 |
image_video = gr.Video(label="Real-time Image Output")
|
360 |
mask_video = gr.Video(label="Real-time Mask Output")
|
|
|
362 |
original_image = gr.Image(label=f"Original Image", type="pil", interactive=False)
|
363 |
edited_image = gr.Image(label=f"Output Image", type="pil", interactive=False)
|
364 |
mix_result_with_red_mask = gr.Image(label=f"Mix Image With Red Mask", type="pil", interactive=False)
|
365 |
+
|
366 |
|
367 |
with gr.Row():
|
368 |
gr.Examples(
|
|
|
384 |
randomize_cfg,
|
385 |
text_cfg_scale,
|
386 |
image_cfg_scale,
|
387 |
+
weather_hide_video,
|
388 |
+
decode_image_batch
|
389 |
],
|
390 |
outputs=[seed, text_cfg_scale, image_cfg_scale, edited_image, mix_image, edited_mask, mask_video, image_video, original_image, mix_result_with_red_mask],
|
391 |
)
|
392 |
reset_button.click(
|
393 |
fn=reset,
|
394 |
inputs=[],
|
395 |
+
outputs=[steps, randomize_seed, seed, randomize_cfg, text_cfg_scale, image_cfg_scale, edited_image, mix_image, edited_mask, mask_video, image_video, original_image, mix_result_with_red_mask, weather_hide_video, decode_image_batch],
|
396 |
)
|
397 |
|
398 |
|