Merge pull request #14626 from AUTOMATIC1111/hr-button-fix

more Hr button fix
This commit is contained in:
AUTOMATIC1111 2024-01-20 10:24:59 +03:00 committed by GitHub
commit 5df56b3980
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 23 deletions

View File

@ -230,7 +230,7 @@ def restore_old_hires_fix_params(res):
res['Hires resize-2'] = height 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: """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 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 returns a dict with field values
""" """
if skip_fields is None:
skip_fields = shared.opts.infotext_skip_pasting
res = {} res = {}
@ -356,8 +358,8 @@ Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 965400086, Size: 512x512, Model
infotext_versions.backcompat(res) infotext_versions.backcompat(res)
skip = set(shared.opts.infotext_skip_pasting) for key in skip_fields:
res = {k: v for k, v in res.items() if k not in skip} res.pop(key, None)
return res return res

View File

@ -1227,8 +1227,11 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
if not state.processing_has_refined_job_count: if not state.processing_has_refined_job_count:
if state.job_count == -1: if state.job_count == -1:
state.job_count = self.n_iter state.job_count = self.n_iter
if getattr(self, 'txt2img_upscale', False):
shared.total_tqdm.updateTotal((self.steps + (self.hr_second_pass_steps or self.steps)) * state.job_count) 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.job_count = state.job_count * 2
state.processing_has_refined_job_count = True state.processing_has_refined_job_count = True

View File

@ -3,7 +3,7 @@ from contextlib import closing
import modules.scripts import modules.scripts
from modules import processing, infotext_utils 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 from modules.shared import opts
import modules.shared as shared import modules.shared as shared
from modules.ui import plaintext_to_html from modules.ui import plaintext_to_html
@ -64,19 +64,18 @@ def txt2img_upscale(id_task: str, request: gr.Request, gallery, gallery_index, g
p.enable_hr = True p.enable_hr = True
p.batch_size = 1 p.batch_size = 1
p.n_iter = 1 p.n_iter = 1
p.txt2img_upscale = True
geninfo = json.loads(generation_info) 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] 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) p.firstpass_image = infotext_utils.image_from_url_text(image_info)
gallery_index_from_end = len(gallery) - gallery_index parameters = parse_generation_parameters(geninfo.get('infotexts')[gallery_index], [])
seed = all_seeds[-gallery_index_from_end if gallery_index_from_end < len(all_seeds) + 1 else 0] p.seed = parameters.get('Seed', -1)
subseed = all_subseeds[-gallery_index_from_end if gallery_index_from_end < len(all_seeds) + 1 else 0] p.subseed = parameters.get('Variation seed', -1)
p.seed = seed
p.subseed = subseed p.override_settings['save_images_before_highres_fix'] = False
with closing(p): with closing(p):
processed = modules.scripts.scripts_txt2img.run(p, *p.script_args) processed = modules.scripts.scripts_txt2img.run(p, *p.script_args)
@ -88,18 +87,13 @@ def txt2img_upscale(id_task: str, request: gr.Request, gallery, gallery_index, g
new_gallery = [] new_gallery = []
for i, image in enumerate(gallery): for i, image in enumerate(gallery):
fake_image = Image.new(mode="RGB", size=(1, 1))
if i == gallery_index: if i == gallery_index:
already_saved_as = getattr(processed.images[0], 'already_saved_as', None) geninfo["infotexts"][gallery_index: gallery_index+1] = processed.infotexts
if already_saved_as is not None: new_gallery.extend(processed.images)
fake_image.already_saved_as = already_saved_as
else:
fake_image = processed.images[0]
else: else:
fake_image.already_saved_as = image["name"] fake_image = Image.new(mode="RGB", size=(1, 1))
fake_image.already_saved_as = image["name"].rsplit('?', 1)[0]
new_gallery.append(fake_image) new_gallery.append(fake_image)
geninfo["infotexts"][gallery_index] = processed.info geninfo["infotexts"][gallery_index] = processed.info