Skip to content

Commit

Permalink
feat: support registering InfiniteZoom result to gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
linjiX committed Oct 22, 2024
1 parent a683d3e commit 6d88d4c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
20 changes: 16 additions & 4 deletions iz_helpers/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from modules.paths_internal import script_path
from modules.paths import Paths
from modules.model_info import AllModelInfo
from modules import script_callbacks

from .helpers import (
fix_env_Path_ffprobe,
closest_upper_divisible_by_eight,
Expand Down Expand Up @@ -101,6 +103,7 @@ def outpaint_steps(
main_frames = [init_img.convert("RGB")]

processed = None
p = None

for i in range(outpaint_steps):
print_out = (
Expand Down Expand Up @@ -130,7 +133,7 @@ def outpaint_steps(
save2Collect(current_image, out_config, f"exit_img.png")
else:
pr = prompts[max(k for k in prompts.keys() if k <= i)]
processed, newseed = renderImg2Img(
processed, newseed, p = renderImg2Img(
request,
f"{common_prompt_pre}\n{pr}\n{common_prompt_suf}".strip(),
negative_prompt,
Expand Down Expand Up @@ -173,7 +176,8 @@ def outpaint_steps(
main_frames[i] = corrected_frame
# else :TEST
# current_image.paste(prev_image, mask=prev_image)
return main_frames, processed

return main_frames, processed, p


def create_zoom(
Expand Down Expand Up @@ -392,7 +396,7 @@ def create_zoom_single(
)

pr = prompts[min(k for k in prompts.keys() if k >= 0)]
processed, newseed = renderTxt2Img(
processed, newseed, p = renderTxt2Img(
request,
f"{common_prompt_pre}\n{pr}\n{common_prompt_suf}".strip(),
negative_prompt,
Expand All @@ -404,6 +408,7 @@ def create_zoom_single(
height,
all_model_info,
)

if len(processed.images) > 0:
current_image = processed.images[0]
save2Collect(current_image, out_config, f"init_txt2img.png")
Expand All @@ -426,7 +431,7 @@ def create_zoom_single(
all_model_info,
specified_model=main_sd_model
)
main_frames, processed = outpaint_steps(
main_frames, processed, p = outpaint_steps(
request,
width,
height,
Expand All @@ -451,6 +456,7 @@ def create_zoom_single(
custom_exit_image,
all_model_info,
)

all_frames.append(
do_upscaleImg(main_frames[0], upscale_do, upscaler_name, upscale_by)
if upscale_do
Expand Down Expand Up @@ -543,6 +549,12 @@ def create_zoom_single(
int(video_start_frame_dupe_amount),
int(video_last_frame_dupe_amount),
)
p.feature = "INFINITE_ZOOM"
script_callbacks.image_saved_callback(
script_callbacks.ImageSaveParams(
None, p, out_config["video_filename"], {"parameters": processed.info}
)
)
print("Video saved in: " + os.path.join(script_path, out_config["video_filename"]))
return (
out_config["video_filename"],
Expand Down
9 changes: 7 additions & 2 deletions iz_helpers/sd_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def renderTxt2Img(
)
p.set_request(request)
p.set_all_model_info(all_model_info)
p.do_not_save_samples = True
p.do_not_save_grid = True

with monitor_call_context(
request,
get_function_name_from_processing(p),
Expand All @@ -42,7 +45,7 @@ def renderTxt2Img(
):
processed = process_images(p)
newseed = p.seed
return processed, newseed
return processed, newseed, p


def renderImg2Img(
Expand Down Expand Up @@ -90,6 +93,8 @@ def renderImg2Img(
# p.latent_mask = Image.new("RGB", (p.width, p.height), "white")
p.set_request(request)
p.set_all_model_info(all_model_info)
p.do_not_save_samples = True
p.do_not_save_grid = True

with monitor_call_context(
request,
Expand All @@ -106,4 +111,4 @@ def renderImg2Img(
print("\nGrid image detected applying patch")

newseed = p.seed
return processed, newseed
return processed, newseed, p

0 comments on commit 6d88d4c

Please sign in to comment.