mirror of
https://github.com/lllyasviel/stable-diffusion-webui-forge.git
synced 2026-04-30 03:01:15 +00:00
Chasing save issues (#2331)
* already_saved_as attribute for gallery items after hiresfix quickbutton * different method to select image in gallery after hires quickbutton with insert option to avoid other changes
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import datetime, time
|
import datetime
|
||||||
import functools
|
import functools
|
||||||
import pytz
|
import pytz
|
||||||
import io
|
import io
|
||||||
@@ -740,7 +740,7 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i
|
|||||||
|
|
||||||
fullfn_without_extension = _atomically_save_image(image, fullfn_without_extension, extension)
|
fullfn_without_extension = _atomically_save_image(image, fullfn_without_extension, extension)
|
||||||
fullfn = fullfn_without_extension + extension
|
fullfn = fullfn_without_extension + extension
|
||||||
image.already_saved_as = f"{fullfn}\?{time.process_time_ns()}"
|
image.already_saved_as = fullfn
|
||||||
|
|
||||||
oversize = image.width > opts.target_side_length or image.height > opts.target_side_length
|
oversize = image.width > opts.target_side_length or image.height > opts.target_side_length
|
||||||
if opts.export_for_4chan and (oversize or os.stat(fullfn).st_size > opts.img_downscale_threshold * 1024 * 1024):
|
if opts.export_for_4chan and (oversize or os.stat(fullfn).st_size > opts.img_downscale_threshold * 1024 * 1024):
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ def txt2img_upscale_function(id_task: str, request: gr.Request, gallery, gallery
|
|||||||
new_gallery = []
|
new_gallery = []
|
||||||
for i, image in enumerate(gallery):
|
for i, image in enumerate(gallery):
|
||||||
if insert or i != gallery_index:
|
if insert or i != gallery_index:
|
||||||
|
image[0].already_saved_as = image[0].filename.rsplit('?', 1)[0]
|
||||||
new_gallery.append(image)
|
new_gallery.append(image)
|
||||||
if i == gallery_index:
|
if i == gallery_index:
|
||||||
new_gallery.extend(processed.images)
|
new_gallery.extend(processed.images)
|
||||||
@@ -117,7 +118,7 @@ def txt2img_upscale_function(id_task: str, request: gr.Request, gallery, gallery
|
|||||||
else:
|
else:
|
||||||
geninfo["infotexts"][gallery_index] = processed.info
|
geninfo["infotexts"][gallery_index] = processed.info
|
||||||
|
|
||||||
return gr.Gallery(new_gallery, selected_index=new_index), json.dumps(geninfo), plaintext_to_html(processed.info), plaintext_to_html(processed.comments, classname="comments")
|
return new_gallery, json.dumps(geninfo), plaintext_to_html(processed.info), plaintext_to_html(processed.comments, classname="comments")
|
||||||
|
|
||||||
|
|
||||||
def txt2img_function(id_task: str, request: gr.Request, *args):
|
def txt2img_function(id_task: str, request: gr.Request, *args):
|
||||||
|
|||||||
@@ -470,6 +470,12 @@ def create_ui():
|
|||||||
toprow.prompt.submit(**txt2img_args)
|
toprow.prompt.submit(**txt2img_args)
|
||||||
toprow.submit.click(**txt2img_args)
|
toprow.submit.click(**txt2img_args)
|
||||||
|
|
||||||
|
def select_gallery_image(index):
|
||||||
|
index = int(index)
|
||||||
|
if getattr(shared.opts, 'hires_button_gallery_insert', False):
|
||||||
|
index += 1
|
||||||
|
return gr.update(selected_index=index)
|
||||||
|
|
||||||
txt2img_upscale_inputs = txt2img_inputs[0:1] + [output_panel.gallery, dummy_component_number, output_panel.generation_info] + txt2img_inputs[1:]
|
txt2img_upscale_inputs = txt2img_inputs[0:1] + [output_panel.gallery, dummy_component_number, output_panel.generation_info] + txt2img_inputs[1:]
|
||||||
output_panel.button_upscale.click(
|
output_panel.button_upscale.click(
|
||||||
fn=wrap_gradio_gpu_call(modules.txt2img.txt2img_upscale, extra_outputs=[None, '', '']),
|
fn=wrap_gradio_gpu_call(modules.txt2img.txt2img_upscale, extra_outputs=[None, '', '']),
|
||||||
@@ -477,7 +483,7 @@ def create_ui():
|
|||||||
inputs=txt2img_upscale_inputs,
|
inputs=txt2img_upscale_inputs,
|
||||||
outputs=txt2img_outputs,
|
outputs=txt2img_outputs,
|
||||||
show_progress=False,
|
show_progress=False,
|
||||||
)
|
).then(fn=select_gallery_image, js="selected_gallery_index", inputs=[dummy_component], outputs=[output_panel.gallery])
|
||||||
|
|
||||||
res_switch_btn.click(lambda w, h: (h, w), inputs=[width, height], outputs=[width, height], show_progress=False)
|
res_switch_btn.click(lambda w, h: (h, w), inputs=[width, height], outputs=[width, height], show_progress=False)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user