From 92501d4f8006866cec3438c038e1588315d835bc Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Sat, 13 Jan 2024 02:20:06 +0900 Subject: [PATCH 1/7] disable saving images before highres fix --- modules/txt2img.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/txt2img.py b/modules/txt2img.py index d22a1f319..115587859 100644 --- a/modules/txt2img.py +++ b/modules/txt2img.py @@ -77,7 +77,7 @@ def txt2img_upscale(id_task: str, request: gr.Request, gallery, gallery_index, g subseed = all_subseeds[-gallery_index_from_end if gallery_index_from_end < len(all_seeds) + 1 else 0] p.seed = seed p.subseed = subseed - + p.override_settings['save_images_before_highres_fix'] = False with closing(p): processed = modules.scripts.scripts_txt2img.run(p, *p.script_args) From cfb90a938eff6d5d4cfa39f58ebc0ab32ffedfb3 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Sat, 13 Jan 2024 02:22:32 +0900 Subject: [PATCH 2/7] allowe hr pass to return multiple images --- modules/txt2img.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/modules/txt2img.py b/modules/txt2img.py index 115587859..daf8f51a9 100644 --- a/modules/txt2img.py +++ b/modules/txt2img.py @@ -88,18 +88,13 @@ def txt2img_upscale(id_task: str, request: gr.Request, gallery, gallery_index, g new_gallery = [] for i, image in enumerate(gallery): - fake_image = Image.new(mode="RGB", size=(1, 1)) - if i == gallery_index: - already_saved_as = getattr(processed.images[0], 'already_saved_as', None) - if already_saved_as is not None: - fake_image.already_saved_as = already_saved_as - else: - fake_image = processed.images[0] + geninfo["infotexts"][gallery_index: gallery_index+1] = processed.infotexts + new_gallery.extend(processed.images) else: + fake_image = Image.new(mode="RGB", size=(1, 1)) fake_image.already_saved_as = image["name"] - - new_gallery.append(fake_image) + new_gallery.append(fake_image) geninfo["infotexts"][gallery_index] = processed.info From ee9d4870811a34533ad5d20ed8aca2ff116fd3b9 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Sat, 13 Jan 2024 02:23:16 +0900 Subject: [PATCH 3/7] fix gallery black image issue --- modules/txt2img.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/txt2img.py b/modules/txt2img.py index daf8f51a9..7a1a16267 100644 --- a/modules/txt2img.py +++ b/modules/txt2img.py @@ -93,7 +93,7 @@ def txt2img_upscale(id_task: str, request: gr.Request, gallery, gallery_index, g new_gallery.extend(processed.images) else: fake_image = Image.new(mode="RGB", size=(1, 1)) - fake_image.already_saved_as = image["name"] + fake_image.already_saved_as = image["name"].rsplit('?', 1)[0] new_gallery.append(fake_image) geninfo["infotexts"][gallery_index] = processed.info From 208ccfbe7c04e1dd5b262f705a904204e8297102 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Sun, 14 Jan 2024 02:11:39 +0900 Subject: [PATCH 4/7] seed info from infotexts --- modules/txt2img.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/txt2img.py b/modules/txt2img.py index 7a1a16267..e617cb1c5 100644 --- a/modules/txt2img.py +++ b/modules/txt2img.py @@ -3,7 +3,7 @@ from contextlib import closing import modules.scripts from modules import processing, infotext_utils -from modules.infotext_utils import create_override_settings_dict +from modules.infotext_utils import create_override_settings_dict, parse_generation_parameters from modules.shared import opts import modules.shared as shared from modules.ui import plaintext_to_html @@ -66,18 +66,16 @@ def txt2img_upscale(id_task: str, request: gr.Request, gallery, gallery_index, g p.n_iter = 1 geninfo = json.loads(generation_info) - all_seeds = geninfo["all_seeds"] - all_subseeds = geninfo["all_subseeds"] image_info = gallery[gallery_index] if 0 <= gallery_index < len(gallery) else gallery[0] p.firstpass_image = infotext_utils.image_from_url_text(image_info) - gallery_index_from_end = len(gallery) - gallery_index - seed = all_seeds[-gallery_index_from_end if gallery_index_from_end < len(all_seeds) + 1 else 0] - subseed = all_subseeds[-gallery_index_from_end if gallery_index_from_end < len(all_seeds) + 1 else 0] - p.seed = seed - p.subseed = subseed + parameters = parse_generation_parameters(geninfo.get('infotexts')[gallery_index]) + p.seed = parameters.get('Seed', -1) + p.subseed = parameters.get('Variation seed', -1) + p.override_settings['save_images_before_highres_fix'] = False + with closing(p): processed = modules.scripts.scripts_txt2img.run(p, *p.script_args) From 6916de5c0bd8df3835d450caa3327d1924db081c Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Tue, 16 Jan 2024 20:16:07 +0900 Subject: [PATCH 5/7] parse_generation_parameters skip_fields --- modules/infotext_utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/infotext_utils.py b/modules/infotext_utils.py index 9a02cdf24..1049c6c3c 100644 --- a/modules/infotext_utils.py +++ b/modules/infotext_utils.py @@ -230,7 +230,7 @@ def restore_old_hires_fix_params(res): res['Hires resize-2'] = height -def parse_generation_parameters(x: str): +def parse_generation_parameters(x: str, skip_fields: list[str] | None = None): """parses generation parameters string, the one you see in text field under the picture in UI: ``` girl with an artist's beret, determined, blue eyes, desert scene, computer monitors, heavy makeup, by Alphonse Mucha and Charlie Bowater, ((eyeshadow)), (coquettish), detailed, intricate @@ -240,6 +240,8 @@ Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 965400086, Size: 512x512, Model returns a dict with field values """ + if skip_fields is None: + skip_fields = shared.opts.infotext_skip_pasting res = {} @@ -356,8 +358,8 @@ Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 965400086, Size: 512x512, Model infotext_versions.backcompat(res) - skip = set(shared.opts.infotext_skip_pasting) - res = {k: v for k, v in res.items() if k not in skip} + for key in skip_fields: + res.pop(key, None) return res From e1dfd452c0447e729a7341c434b4aab6063aa654 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Tue, 16 Jan 2024 20:27:29 +0900 Subject: [PATCH 6/7] parse_generation_parameters with no skip_fields --- modules/txt2img.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/txt2img.py b/modules/txt2img.py index e617cb1c5..92a160d61 100644 --- a/modules/txt2img.py +++ b/modules/txt2img.py @@ -70,7 +70,7 @@ def txt2img_upscale(id_task: str, request: gr.Request, gallery, gallery_index, g image_info = gallery[gallery_index] if 0 <= gallery_index < len(gallery) else gallery[0] p.firstpass_image = infotext_utils.image_from_url_text(image_info) - parameters = parse_generation_parameters(geninfo.get('infotexts')[gallery_index]) + parameters = parse_generation_parameters(geninfo.get('infotexts')[gallery_index], []) p.seed = parameters.get('Seed', -1) p.subseed = parameters.get('Variation seed', -1) From 2cf23099ebb81832a27c8016f14062885f5a9c98 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Thu, 18 Jan 2024 04:44:21 +0900 Subject: [PATCH 7/7] fix console total progress bar when using txt2img_upscale add p.txt2img_upscale as indicator --- modules/processing.py | 7 +++++-- modules/txt2img.py | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/processing.py b/modules/processing.py index dcc807fe3..547ab2f86 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -1227,8 +1227,11 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): if not state.processing_has_refined_job_count: if state.job_count == -1: state.job_count = self.n_iter - - shared.total_tqdm.updateTotal((self.steps + (self.hr_second_pass_steps or self.steps)) * state.job_count) + if getattr(self, 'txt2img_upscale', False): + total_steps = (self.hr_second_pass_steps or self.steps) * state.job_count + else: + total_steps = (self.steps + (self.hr_second_pass_steps or self.steps)) * state.job_count + shared.total_tqdm.updateTotal(total_steps) state.job_count = state.job_count * 2 state.processing_has_refined_job_count = True diff --git a/modules/txt2img.py b/modules/txt2img.py index 92a160d61..4efcb4c3d 100644 --- a/modules/txt2img.py +++ b/modules/txt2img.py @@ -64,6 +64,7 @@ def txt2img_upscale(id_task: str, request: gr.Request, gallery, gallery_index, g p.enable_hr = True p.batch_size = 1 p.n_iter = 1 + p.txt2img_upscale = True geninfo = json.loads(generation_info)