From f8acbb8f880815facb5037efcd676f2f0d2b5bf4 Mon Sep 17 00:00:00 2001 From: Michoko Date: Tue, 27 Sep 2022 23:02:11 +0200 Subject: Add output folder icons Adds icons on the first 3 tabs to directly open the corresponding images output directory --- modules/ui.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index 87024238..4c93fca9 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -61,7 +61,7 @@ random_symbol = '\U0001f3b2\ufe0f' # 🎲️ reuse_symbol = '\u267b\ufe0f' # ♻️ art_symbol = '\U0001f3a8' # 🎨 paste_symbol = '\u2199\ufe0f' # ↙ - +folder_symbol = '\uD83D\uDCC2' def plaintext_to_html(text): text = "

" + "
\n".join([f"{html.escape(x)}" for x in text.split('\n')]) + "

" @@ -461,6 +461,7 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): send_to_img2img = gr.Button('Send to img2img') send_to_inpaint = gr.Button('Send to inpaint') send_to_extras = gr.Button('Send to extras') + open_txt2img_folder = gr.Button(folder_symbol, elem_id="open_folder") with gr.Group(): html_info = gr.HTML() @@ -637,6 +638,7 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): img2img_send_to_img2img = gr.Button('Send to img2img') img2img_send_to_inpaint = gr.Button('Send to inpaint') img2img_send_to_extras = gr.Button('Send to extras') + open_img2img_folder = gr.Button(folder_symbol, elem_id="open_folder") with gr.Group(): html_info = gr.HTML() @@ -809,6 +811,7 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): html_info = gr.HTML() extras_send_to_img2img = gr.Button('Send to img2img') extras_send_to_inpaint = gr.Button('Send to inpaint') + open_extras_folder = gr.Button('Open output directory') submit.click( fn=run_extras, @@ -907,6 +910,9 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): components = [] component_dict = {} + def open_folder(f): + os.startfile(os.path.normpath(f)) + def run_settings(*args): changed = 0 @@ -1068,6 +1074,24 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): outputs=[extras_image], ) + open_txt2img_folder.click( + fn=lambda: open_folder(opts.outdir_samples or opts.outdir_txt2img_samples), + inputs=[], + outputs=[], + ) + + open_img2img_folder.click( + fn=lambda: open_folder(opts.outdir_samples or opts.outdir_img2img_samples), + inputs=[], + outputs=[], + ) + + open_extras_folder.click( + fn=lambda: open_folder(opts.outdir_samples or opts.outdir_extras_samples), + inputs=[], + outputs=[], + ) + img2img_send_to_extras.click( fn=lambda x: image_from_url_text(x), _js="extract_image_from_gallery_extras", -- cgit v1.2.1 From 02c4b757b6e4e0894c5a988b49cb8f50c0d99cc1 Mon Sep 17 00:00:00 2001 From: Michoko Date: Wed, 28 Sep 2022 10:31:53 +0200 Subject: Add output folder icons Handling of the --hide-ui-dir-config flag and added multi-platform code for opening a folder --- modules/ui.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index 4c93fca9..2dbcd50c 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -9,6 +9,8 @@ import random import sys import time import traceback +import platform +import subprocess as sp import numpy as np import torch @@ -461,7 +463,8 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): send_to_img2img = gr.Button('Send to img2img') send_to_inpaint = gr.Button('Send to inpaint') send_to_extras = gr.Button('Send to extras') - open_txt2img_folder = gr.Button(folder_symbol, elem_id="open_folder") + button_id = "open_folder_hidden" if shared.cmd_opts.hide_ui_dir_config else 'open_folder' + open_txt2img_folder = gr.Button(folder_symbol, elem_id=button_id) with gr.Group(): html_info = gr.HTML() @@ -638,7 +641,8 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): img2img_send_to_img2img = gr.Button('Send to img2img') img2img_send_to_inpaint = gr.Button('Send to inpaint') img2img_send_to_extras = gr.Button('Send to extras') - open_img2img_folder = gr.Button(folder_symbol, elem_id="open_folder") + button_id = "open_folder_hidden" if shared.cmd_opts.hide_ui_dir_config else 'open_folder' + open_img2img_folder = gr.Button(folder_symbol, elem_id=button_id) with gr.Group(): html_info = gr.HTML() @@ -811,7 +815,8 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): html_info = gr.HTML() extras_send_to_img2img = gr.Button('Send to img2img') extras_send_to_inpaint = gr.Button('Send to inpaint') - open_extras_folder = gr.Button('Open output directory') + button_id = "open_folder_hidden" if shared.cmd_opts.hide_ui_dir_config else '' + open_extras_folder = gr.Button('Open output directory', elem_id=button_id) submit.click( fn=run_extras, @@ -911,7 +916,14 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): component_dict = {} def open_folder(f): - os.startfile(os.path.normpath(f)) + if not shared.cmd_opts.hide_ui_dir_config: + path = os.path.normpath(f) + if platform.system() == "Windows": + os.startfile(path) + elif platform.system() == "Darwin": + sp.Popen(["open", path]) + else: + sp.Popen(["xdg-open", path]) def run_settings(*args): changed = 0 -- cgit v1.2.1 From 819fd3af40d7cb5bac9a496f0e08c062fedf100b Mon Sep 17 00:00:00 2001 From: Michoko Date: Wed, 28 Sep 2022 10:40:05 +0200 Subject: Add output folder icons Changed the hidden element class name to a more generic one, so people can reuse it if they want to hide further elements in the future --- modules/ui.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index 2dbcd50c..f704749a 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -463,7 +463,7 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): send_to_img2img = gr.Button('Send to img2img') send_to_inpaint = gr.Button('Send to inpaint') send_to_extras = gr.Button('Send to extras') - button_id = "open_folder_hidden" if shared.cmd_opts.hide_ui_dir_config else 'open_folder' + button_id = "hidden_element" if shared.cmd_opts.hide_ui_dir_config else 'open_folder' open_txt2img_folder = gr.Button(folder_symbol, elem_id=button_id) with gr.Group(): @@ -641,7 +641,7 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): img2img_send_to_img2img = gr.Button('Send to img2img') img2img_send_to_inpaint = gr.Button('Send to inpaint') img2img_send_to_extras = gr.Button('Send to extras') - button_id = "open_folder_hidden" if shared.cmd_opts.hide_ui_dir_config else 'open_folder' + button_id = "hidden_element" if shared.cmd_opts.hide_ui_dir_config else 'open_folder' open_img2img_folder = gr.Button(folder_symbol, elem_id=button_id) with gr.Group(): @@ -815,7 +815,7 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): html_info = gr.HTML() extras_send_to_img2img = gr.Button('Send to img2img') extras_send_to_inpaint = gr.Button('Send to inpaint') - button_id = "open_folder_hidden" if shared.cmd_opts.hide_ui_dir_config else '' + button_id = "hidden_element" if shared.cmd_opts.hide_ui_dir_config else '' open_extras_folder = gr.Button('Open output directory', elem_id=button_id) submit.click( -- cgit v1.2.1 From 66fed8ffb8e75bbed4e36ae39c30df686b477677 Mon Sep 17 00:00:00 2001 From: safentisAuth Date: Thu, 29 Sep 2022 02:50:34 +0300 Subject: Add custom name and try-except --- modules/ui.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index f704749a..9b5e4e92 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -882,6 +882,7 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): with gr.Row(): primary_model_name = gr.Dropdown(modules.sd_models.checkpoint_tiles(), elem_id="modelmerger_primary_model_name", label="Primary Model Name") secondary_model_name = gr.Dropdown(modules.sd_models.checkpoint_tiles(), elem_id="modelmerger_secondary_model_name", label="Secondary Model Name") + custom_name = gr.Textbox(label="Custom Name (Optional)") interp_amount = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label='Interpolation Amount', value=0.3) interp_method = gr.Radio(choices=["Weighted Sum", "Sigmoid", "Inverse Sigmoid"], value="Weighted Sum", label="Interpolation Method") save_as_half = gr.Checkbox(value=False, label="Safe as float16") @@ -1031,15 +1032,26 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): inputs=components, outputs=[result, text_settings], ) + + def modelmerger(*args): + try: + results = run_modelmerger(*args) + except Exception as e: + print("Error loading/saving model file:", file=sys.stderr) + print(traceback.format_exc(), file=sys.stderr) + modules.sd_models.list_models() #To remove the potentially missing models from the list + return ["Error loading/saving model file. It doesn't exist or the name contains illegal characters"] + [gr.Dropdown.update(choices=modules.sd_models.checkpoint_tiles()) for _ in range(3)] + return results modelmerger_merge.click( - fn=run_modelmerger, + fn=modelmerger, inputs=[ primary_model_name, secondary_model_name, interp_method, interp_amount, save_as_half, + custom_name, ], outputs=[ submit_result, -- cgit v1.2.1 From ca5901b5c8b5851d2556844d64760bac7caab354 Mon Sep 17 00:00:00 2001 From: Justin Maier Date: Wed, 28 Sep 2022 20:51:11 -0600 Subject: Save should use desired sample format fixes #1028 --- modules/ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index 9b5e4e92..e1e88396 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -114,7 +114,7 @@ def save_files(js_data, images, index): filename_base = str(int(time.time() * 1000)) for i, filedata in enumerate(images): - filename = filename_base + ("" if len(images) == 1 else "-" + str(i + 1)) + ".png" + filename = filename_base + ("" if len(images) == 1 else "-" + str(i + 1)) + f".{opts.samples_format}" filepath = os.path.join(opts.outdir_save, filename) if filedata.startswith("data:image/png;base64,"): -- cgit v1.2.1 From a112168d2814d691936a7fb1d4cde5acb8440679 Mon Sep 17 00:00:00 2001 From: Justin Maier Date: Thu, 29 Sep 2022 08:54:45 -0600 Subject: Save parameters as comments when saving as jpg --- modules/ui.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index e1e88396..ada9a38e 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -15,6 +15,7 @@ import subprocess as sp import numpy as np import torch from PIL import Image, PngImagePlugin +import piexif import gradio as gr import gradio.utils @@ -113,18 +114,26 @@ def save_files(js_data, images, index): writer.writerow(["prompt", "seed", "width", "height", "sampler", "cfgs", "steps", "filename", "negative_prompt"]) filename_base = str(int(time.time() * 1000)) + extension = opts.samples_format.lower() for i, filedata in enumerate(images): - filename = filename_base + ("" if len(images) == 1 else "-" + str(i + 1)) + f".{opts.samples_format}" + filename = filename_base + ("" if len(images) == 1 else "-" + str(i + 1)) + f".{extension}" filepath = os.path.join(opts.outdir_save, filename) if filedata.startswith("data:image/png;base64,"): filedata = filedata[len("data:image/png;base64,"):] - pnginfo = PngImagePlugin.PngInfo() - pnginfo.add_text('parameters', infotexts[i]) - image = Image.open(io.BytesIO(base64.decodebytes(filedata.encode('utf-8')))) - image.save(filepath, quality=opts.jpeg_quality, pnginfo=pnginfo) + if opts.enable_pnginfo and extension == 'png': + pnginfo = PngImagePlugin.PngInfo() + pnginfo.add_text('parameters', infotexts[i]) + image.save(filepath, pnginfo=pnginfo) + else: + image.save(filepath, quality=opts.jpeg_quality) + + if opts.enable_pnginfo and extension in ("jpg", "jpeg", "webp"): + piexif.insert(piexif.dump({"Exif": { + piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(infotexts[i], encoding="unicode") + }}), filepath) filenames.append(filename) -- cgit v1.2.1 From 43c87ef0fcf1771d5511004968e70f804cfd95b8 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Fri, 30 Sep 2022 18:07:49 +0300 Subject: change default inpaint mode to original --- modules/ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index ada9a38e..249b3eea 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -599,7 +599,7 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): mask_mode = gr.Radio(label="Mask mode", show_label=False, choices=["Draw mask", "Upload mask"], type="index", value="Draw mask", elem_id="mask_mode") inpainting_mask_invert = gr.Radio(label='Masking mode', show_label=False, choices=['Inpaint masked', 'Inpaint not masked'], value='Inpaint masked', type="index") - inpainting_fill = gr.Radio(label='Masked content', choices=['fill', 'original', 'latent noise', 'latent nothing'], value='fill', type="index") + inpainting_fill = gr.Radio(label='Masked content', choices=['fill', 'original', 'latent noise', 'latent nothing'], value='original', type="index") with gr.Row(): inpaint_full_res = gr.Checkbox(label='Inpaint at full resolution', value=False) -- cgit v1.2.1 From d1db330010de31d48975bb3ec86e9e60d56ae9e9 Mon Sep 17 00:00:00 2001 From: Trung Ngo Date: Fri, 30 Sep 2022 15:31:00 -0500 Subject: ALT + return will submit prompt when it's in focus --- modules/ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/ui.py') diff --git a/modules/ui.py b/modules/ui.py index 249b3eea..15572bb0 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -380,7 +380,7 @@ def create_toprow(is_img2img): with gr.Column(scale=1): with gr.Row(): interrupt = gr.Button('Interrupt', elem_id=f"{id_part}_interrupt") - submit = gr.Button('Generate', elem_id="generate", variant='primary') + submit = gr.Button('Generate', elem_id=f"{id_part}_generate", variant='primary') interrupt.click( fn=lambda: shared.state.interrupt(), -- cgit v1.2.1