From 699aecd4ae04683e74717f1786d6eba49b09bc79 Mon Sep 17 00:00:00 2001 From: Dylan Cathelijn Date: Thu, 22 Sep 2022 11:35:12 +0200 Subject: [PATCH 01/10] Update README to link to wiki page for Apple Silicon installs --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index c15381009..3cb4efb9b 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,10 @@ sudo pacman -S wget git python3 bash <(wget -qO- https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/webui.sh) ``` +### Installation on Apple Silicon + +Find the instructions [here](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Installation-on-Apple-Silicon). + ## Documentation The documentation was moved from this README over to the project's [wiki](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki). From a213d3a21c9e37297fdcb2c2b48bd24290a479cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Aires=20Rast=C3=A9n?= Date: Thu, 22 Sep 2022 10:47:16 +0200 Subject: [PATCH 02/10] Add option to always log generation info --- modules/img2img.py | 6 +++++- modules/shared.py | 1 + modules/txt2img.py | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/img2img.py b/modules/img2img.py index 91689232b..bce8b712d 100644 --- a/modules/img2img.py +++ b/modules/img2img.py @@ -118,4 +118,8 @@ def img2img(mode: int, prompt: str, negative_prompt: str, prompt_style: str, pro shared.total_tqdm.clear() - return processed.images, processed.js(), plaintext_to_html(processed.info) + generation_info_js = processed.js() + if opts.samples_log_stdout: + print(generation_info_js) + + return processed.images, generation_info_js, plaintext_to_html(processed.info) \ No newline at end of file diff --git a/modules/shared.py b/modules/shared.py index 841a9877e..5ffaefc55 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -125,6 +125,7 @@ class Options: "outdir_img2img_grids": OptionInfo("outputs/img2img-grids", 'Output directory for img2img grids', component_args=hide_dirs), "outdir_save": OptionInfo("log/images", "Directory for saving images using the Save button", component_args=hide_dirs), "samples_save": OptionInfo(True, "Always save all generated images"), + "samples_log_stdout": OptionInfo(False, "Always print all generation info to standard output"), "save_selected_only": OptionInfo(False, "When using 'Save' button, only save a single selected image"), "samples_format": OptionInfo('png', 'File format for individual samples'), "filter_nsfw": OptionInfo(False, "Filter NSFW content"), diff --git a/modules/txt2img.py b/modules/txt2img.py index 9123fca19..d2cf39efd 100644 --- a/modules/txt2img.py +++ b/modules/txt2img.py @@ -44,5 +44,9 @@ def txt2img(prompt: str, negative_prompt: str, prompt_style: str, prompt_style2: shared.total_tqdm.clear() - return processed.images, processed.js(), plaintext_to_html(processed.info) + generation_info_js = processed.js() + if opts.samples_log_stdout: + print(generation_info_js) + + return processed.images, generation_info_js, plaintext_to_html(processed.info) From cae09e1651e7969e815b4d3443debaf606c8d4bb Mon Sep 17 00:00:00 2001 From: DepFA <35278260+dfaker@users.noreply.github.com> Date: Thu, 22 Sep 2022 15:22:34 +0100 Subject: [PATCH 03/10] Update selectors after ui and core overhaul --- javascript/aspectRatioOverlay.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/javascript/aspectRatioOverlay.js b/javascript/aspectRatioOverlay.js index 52e9f3817..96f1c00d0 100644 --- a/javascript/aspectRatioOverlay.js +++ b/javascript/aspectRatioOverlay.js @@ -18,9 +18,9 @@ function dimensionChange(e,dimname){ return; } - var img2imgMode = gradioApp().querySelector("input[name=radio-img2img_mode]:checked") + var img2imgMode = gradioApp().querySelector('#mode_img2img.tabs > div > button.rounded-t-lg.border-gray-200') if(img2imgMode){ - img2imgMode=img2imgMode.value + img2imgMode=img2imgMode.innerText }else{ return; } @@ -30,12 +30,10 @@ function dimensionChange(e,dimname){ var targetElement = null; - if(img2imgMode=='Redraw whole image' && redrawImage){ + if(img2imgMode=='img2img' && redrawImage){ targetElement = redrawImage; - }else if(img2imgMode=='Inpaint a part of image' && inpaintImage){ + }else if(img2imgMode=='Inpaint' && inpaintImage){ targetElement = inpaintImage; - }else if(img2imgMode=='SD upscale' && redrawImage){ - targetElement = redrawImage; } if(targetElement){ @@ -119,6 +117,3 @@ onUiUpdate(function(){ }) } }); - - - From ae32b8a53fd52cb4be195c4b4c329dd81a63ada7 Mon Sep 17 00:00:00 2001 From: Prof-Cheese Date: Fri, 23 Sep 2022 01:47:43 +0900 Subject: [PATCH 04/10] Fixed directory name generation process. 'Max prompt words' has been added to config and modified to be used in the directory name generation process. --- javascript/hints.js | 1 + modules/images.py | 3 ++- modules/shared.py | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/javascript/hints.js b/javascript/hints.js index 65a67d504..9d3eecf33 100644 --- a/javascript/hints.js +++ b/javascript/hints.js @@ -59,6 +59,7 @@ titles = { "Images filename pattern": "Use following tags to define how filenames for images are chosen: [steps], [cfg], [prompt], [prompt_spaces], [width], [height], [sampler], [seed], [model_hash], [prompt_words], [date]; leave empty for default.", "Directory name pattern": "Use following tags to define how subdirectories for images and grids are chosen: [steps], [cfg], [prompt], [prompt_spaces], [width], [height], [sampler], [seed], [model_hash], [prompt_words], [date]; leave empty for default.", + "Max prompt words": "Set the maximum number of words to be used in the [prompt_words] option; ATTENTION: If the words are too long, they may exceed the maximum length of the file path that the system can handle", "Loopback": "Process an image, use it as an input, repeat.", "Loops": "How many times to repeat processing an image and using it as input for the next iteration", diff --git a/modules/images.py b/modules/images.py index d17072632..4926d800c 100644 --- a/modules/images.py +++ b/modules/images.py @@ -249,7 +249,6 @@ invalid_filename_prefix = ' ' invalid_filename_postfix = ' .' re_nonletters = re.compile(r'[\s'+string.punctuation+']+') max_filename_part_length = 128 -max_prompt_words = 8 def sanitize_filename_part(text, replace_spaces=True): @@ -263,6 +262,8 @@ def sanitize_filename_part(text, replace_spaces=True): def apply_filename_pattern(x, p, seed, prompt): + max_prompt_words = opts.directories_max_prompt_words + if seed is not None: x = x.replace("[seed]", str(seed)) diff --git a/modules/shared.py b/modules/shared.py index 5ffaefc55..2918efbd3 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -116,6 +116,7 @@ class Options: "save_to_dirs": OptionInfo(False, "Save images to a subdirectory"), "grid_save_to_dirs": OptionInfo(False, "Save grids to subdirectory"), "directories_filename_pattern": OptionInfo("", "Directory name pattern"), + "directories_max_prompt_words": OptionInfo(8, "Max prompt words", gr.Slider, {"minimum": 1, "maximum": 20, "step": 1}), "outdir_samples": OptionInfo("", "Output directory for images; if empty, defaults to two directories below", component_args=hide_dirs), "outdir_txt2img_samples": OptionInfo("outputs/txt2img-images", 'Output directory for txt2img images', component_args=hide_dirs), "outdir_img2img_samples": OptionInfo("outputs/img2img-images", 'Output directory for img2img images', component_args=hide_dirs), From dec7584903d80eb794863a10a4dcdb77c36dd408 Mon Sep 17 00:00:00 2001 From: DepFA <35278260+dfaker@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:24:50 +0100 Subject: [PATCH 05/10] Add Section keys and headers to settings --- modules/shared.py | 94 ++++++++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/modules/shared.py b/modules/shared.py index 2918efbd3..96d78b454 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -99,6 +99,10 @@ def realesrgan_models_names(): import modules.realesrgan_model return [x.name for x in modules.realesrgan_model.get_realesrgan_models()] +def optionsSection(sectionIdentifer,optionsDict): + for k,v in optionsDict.items(): + v.section = sectionIdentifer + return optionsDict class Options: class OptionInfo: @@ -111,41 +115,11 @@ class Options: data = None hide_dirs = {"visible": False} if cmd_opts.hide_ui_dir_config else None - data_labels = { - "samples_filename_pattern": OptionInfo("", "Images filename pattern"), - "save_to_dirs": OptionInfo(False, "Save images to a subdirectory"), - "grid_save_to_dirs": OptionInfo(False, "Save grids to subdirectory"), - "directories_filename_pattern": OptionInfo("", "Directory name pattern"), - "directories_max_prompt_words": OptionInfo(8, "Max prompt words", gr.Slider, {"minimum": 1, "maximum": 20, "step": 1}), - "outdir_samples": OptionInfo("", "Output directory for images; if empty, defaults to two directories below", component_args=hide_dirs), - "outdir_txt2img_samples": OptionInfo("outputs/txt2img-images", 'Output directory for txt2img images', component_args=hide_dirs), - "outdir_img2img_samples": OptionInfo("outputs/img2img-images", 'Output directory for img2img images', component_args=hide_dirs), - "outdir_extras_samples": OptionInfo("outputs/extras-images", 'Output directory for images from extras tab', component_args=hide_dirs), - "outdir_grids": OptionInfo("", "Output directory for grids; if empty, defaults to two directories below", component_args=hide_dirs), - "outdir_txt2img_grids": OptionInfo("outputs/txt2img-grids", 'Output directory for txt2img grids', component_args=hide_dirs), - "outdir_img2img_grids": OptionInfo("outputs/img2img-grids", 'Output directory for img2img grids', component_args=hide_dirs), - "outdir_save": OptionInfo("log/images", "Directory for saving images using the Save button", component_args=hide_dirs), - "samples_save": OptionInfo(True, "Always save all generated images"), - "samples_log_stdout": OptionInfo(False, "Always print all generation info to standard output"), - "save_selected_only": OptionInfo(False, "When using 'Save' button, only save a single selected image"), - "samples_format": OptionInfo('png', 'File format for individual samples'), + + data_labels.update(optionsSection((0,"General"),{ "filter_nsfw": OptionInfo(False, "Filter NSFW content"), - "grid_save": OptionInfo(True, "Always save all generated image grids"), - "return_grid": OptionInfo(True, "Show grid in results for web"), - "grid_format": OptionInfo('png', 'File format for grids'), - "grid_extended_filename": OptionInfo(False, "Add extended info (seed, prompt) to filename when saving grid"), - "grid_only_if_multiple": OptionInfo(True, "Do not save grids consisting of one picture"), - "n_rows": OptionInfo(-1, "Grid row count; use -1 for autodetect and 0 for it to be same as batch size", gr.Slider, {"minimum": -1, "maximum": 16, "step": 1}), - "jpeg_quality": OptionInfo(80, "Quality for saved jpeg images", gr.Slider, {"minimum": 1, "maximum": 100, "step": 1}), - "export_for_4chan": OptionInfo(True, "If PNG image is larger than 4MB or any dimension is larger than 4000, downscale and save copy as JPG"), "enable_pnginfo": OptionInfo(True, "Save text information about generation parameters as chunks to png files"), "add_model_hash_to_info": OptionInfo(False, "Add model hash to generation information"), - "img2img_color_correction": OptionInfo(False, "Apply color correction to img2img results to match original colors."), - "img2img_fix_steps": OptionInfo(False, "With img2img, do exactly the amount of steps the slider specifies (normally you'd do less with less denoising)."), - "enable_quantization": OptionInfo(False, "Enable quantization in K samplers for sharper and cleaner results. This may change existing seeds. Requires restart to apply."), - "font": OptionInfo("", "Font for image grids that have text"), - "enable_emphasis": OptionInfo(True, "Use (text) to make model pay more attention to text and [text] to make it pay less attention"), - "enable_batch_seeds": OptionInfo(True, "Make K-diffusion samplers produce same images in a batch as when making a single image"), "save_txt": OptionInfo(False, "Create a text file next to every image with generation parameters."), "ESRGAN_tile": OptionInfo(192, "Tile size for ESRGAN upscalers. 0 = no tiling.", gr.Slider, {"minimum": 0, "maximum": 512, "step": 16}), "ESRGAN_tile_overlap": OptionInfo(8, "Tile overlap, in pixels for ESRGAN upscalers. Low values = visible seam.", gr.Slider, {"minimum": 0, "maximum": 48, "step": 1}), @@ -165,17 +139,63 @@ class Options: "code_former_weight": OptionInfo(0.5, "CodeFormer weight parameter; 0 = maximum effect; 1 = minimum effect", gr.Slider, {"minimum": 0, "maximum": 1, "step": 0.01}), "save_images_before_face_restoration": OptionInfo(False, "Save a copy of image before doing face restoration."), "face_restoration_unload": OptionInfo(False, "Move face restoration model from VRAM into RAM after processing"), + "sd_model_checkpoint": OptionInfo(None, "Stable Diffusion checkpoint", gr.Radio, lambda: {"choices": [x.title for x in modules.sd_models.checkpoints_list.values()]}), + "js_modal_lightbox": OptionInfo(True, "Enable full page image viewer"), + "js_modal_lightbox_initialy_zoomed": OptionInfo(True, "Show images zoomed in by default in full page image viewer"), + "use_original_name_batch": OptionInfo(False, "Use original name for output filename during batch process"), + })) + + data_labels.update(optionsSection((1,"File and Folder Locations"),{ + "samples_filename_pattern": OptionInfo("", "Images filename pattern"), + "save_to_dirs": OptionInfo(False, "Save images to a subdirectory"), + "grid_save_to_dirs": OptionInfo(False, "Save grids to subdirectory"), + "directories_filename_pattern": OptionInfo("", "Directory name pattern"), + "directories_max_prompt_words": OptionInfo(8, "Max prompt words", gr.Slider, {"minimum": 1, "maximum": 20, "step": 1}), + "outdir_samples": OptionInfo("", "Output directory for images; if empty, defaults to two directories below", component_args=hide_dirs), + "outdir_txt2img_samples": OptionInfo("outputs/txt2img-images", 'Output directory for txt2img images', component_args=hide_dirs), + "outdir_img2img_samples": OptionInfo("outputs/img2img-images", 'Output directory for img2img images', component_args=hide_dirs), + "outdir_extras_samples": OptionInfo("outputs/extras-images", 'Output directory for images from extras tab', component_args=hide_dirs), + "outdir_grids": OptionInfo("", "Output directory for grids; if empty, defaults to two directories below", component_args=hide_dirs), + "outdir_txt2img_grids": OptionInfo("outputs/txt2img-grids", 'Output directory for txt2img grids', component_args=hide_dirs), + "outdir_img2img_grids": OptionInfo("outputs/img2img-grids", 'Output directory for img2img grids', component_args=hide_dirs), + "outdir_save": OptionInfo("log/images", "Directory for saving images using the Save button", component_args=hide_dirs), + "jpeg_quality": OptionInfo(80, "Quality for saved jpeg images", gr.Slider, {"minimum": 1, "maximum": 100, "step": 1}), + "export_for_4chan": OptionInfo(True, "If PNG image is larger than 4MB or any dimension is larger than 4000, downscale and save copy as JPG"), + })) + + data_labels.update(optionsSection((2,"Sampling Options"),{ + "samples_save": OptionInfo(True, "Always save all generated images"), + "samples_log_stdout": OptionInfo(False, "Always print all generation info to standard output"), + "save_selected_only": OptionInfo(False, "When using 'Save' button, only save a single selected image"), + "samples_format": OptionInfo('png', 'File format for individual samples'), + })) + + data_labels.update(optionsSection((3,"Grid Options"),{ + "grid_save": OptionInfo(True, "Always save all generated image grids"), + "return_grid": OptionInfo(True, "Show grid in results for web"), + "grid_format": OptionInfo('png', 'File format for grids'), + "grid_extended_filename": OptionInfo(False, "Add extended info (seed, prompt) to filename when saving grid"), + "grid_only_if_multiple": OptionInfo(True, "Do not save grids consisting of one picture"), + "n_rows": OptionInfo(-1, "Grid row count; use -1 for autodetect and 0 for it to be same as batch size", gr.Slider, {"minimum": -1, "maximum": 16, "step": 1}), + })) + + data_labels.update(optionsSection((4,"Model Options"),{ + "img2img_color_correction": OptionInfo(False, "Apply color correction to img2img results to match original colors."), + "img2img_fix_steps": OptionInfo(False, "With img2img, do exactly the amount of steps the slider specifies (normally you'd do less with less denoising)."), + "enable_quantization": OptionInfo(False, "Enable quantization in K samplers for sharper and cleaner results. This may change existing seeds. Requires restart to apply."), + "font": OptionInfo("", "Font for image grids that have text"), + "enable_emphasis": OptionInfo(True, "Use (text) to make model pay more attention to text and [text] to make it pay less attention"), + "enable_batch_seeds": OptionInfo(True, "Make K-diffusion samplers produce same images in a batch as when making a single image"), + })) + + data_labels.update(optionsSection((5,"Interrogate Options"),{ "interrogate_keep_models_in_memory": OptionInfo(False, "Interrogate: keep models in VRAM"), "interrogate_use_builtin_artists": OptionInfo(True, "Interrogate: use artists from artists.csv"), "interrogate_clip_num_beams": OptionInfo(1, "Interrogate: num_beams for BLIP", gr.Slider, {"minimum": 1, "maximum": 16, "step": 1}), "interrogate_clip_min_length": OptionInfo(24, "Interrogate: minimum description length (excluding artists, etc..)", gr.Slider, {"minimum": 1, "maximum": 128, "step": 1}), "interrogate_clip_max_length": OptionInfo(48, "Interrogate: maximum description length", gr.Slider, {"minimum": 1, "maximum": 256, "step": 1}), "interrogate_clip_dict_limit": OptionInfo(1500, "Interrogate: maximum number of lines in text file (0 = No limit)"), - "sd_model_checkpoint": OptionInfo(None, "Stable Diffusion checkpoint", gr.Radio, lambda: {"choices": [x.title for x in modules.sd_models.checkpoints_list.values()]}), - "js_modal_lightbox": OptionInfo(True, "Enable full page image viewer"), - "js_modal_lightbox_initialy_zoomed": OptionInfo(True, "Show images zoomed in by default in full page image viewer"), - "use_original_name_batch": OptionInfo(False, "Use original name for output filename during batch process"), - } + })) def __init__(self): self.data = {k: v.default for k, v in self.data_labels.items()} From 6d1c01c9557577573df84489c08581c405e7bdc6 Mon Sep 17 00:00:00 2001 From: DepFA <35278260+dfaker@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:26:26 +0100 Subject: [PATCH 06/10] Add section splitting to settings ui --- modules/ui.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index 8925fbcbc..0d9f4c097 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -9,6 +9,7 @@ import random import sys import time import traceback +import itertools import numpy as np import torch @@ -842,14 +843,22 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo): settings_submit = gr.Button(value="Apply settings", variant='primary') result = gr.HTML() - with gr.Row(elem_id="settings").style(equal_height=False): - for colno in range(settings_cols): - with gr.Column(variant='panel'): - for rowno in range(items_per_col): - index = rowno + colno * items_per_col + sortedKeys = sorted([(opts.data_labels[key].section,key) for key in keys],key=lambda x:x[0]) + groupedKeys = itertools.groupby(sortedKeys,key=lambda x:x[0]) - if index < len(keys): - components.append(create_setting_component(keys[index])) + for (sectionNumber,sectionName),sectionGroup in groupedKeys: + with gr.Row(elem_id="settings_header_{}".format(sectionNumber)).style(equal_height=False): + gr.HTML(elem_id="settings_header_text_{}".format(sectionNumber), value='

{}

'.format(sectionName)) + + with gr.Row(elem_id="settings_{}".format(sectionNumber)).style(equal_height=False): + columnLookup = {} + for colNum,element in zip(itertools.cycle(range(settings_cols)),sectionGroup): + columnLookup.setdefault(colNum,[]).append(element) + + for colno,elements in sorted(columnLookup.items()): + with gr.Column(variant='panel'): + for _,keyElement in elements: + components.append(create_setting_component(keyElement)) settings_submit.click( fn=run_settings, From 75b90a5e403b7037430b6c9db956844d2d1c1c4d Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Thu, 22 Sep 2022 20:41:22 +0300 Subject: [PATCH 07/10] emergency fix for the settings screen breaking the program --- modules/shared.py | 197 ++++++++++++++++++++++++---------------------- 1 file changed, 103 insertions(+), 94 deletions(-) diff --git a/modules/shared.py b/modules/shared.py index 96d78b454..009a4940d 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -99,103 +99,112 @@ def realesrgan_models_names(): import modules.realesrgan_model return [x.name for x in modules.realesrgan_model.get_realesrgan_models()] -def optionsSection(sectionIdentifer,optionsDict): - for k,v in optionsDict.items(): - v.section = sectionIdentifer - return optionsDict + +class OptionInfo: + def __init__(self, default=None, label="", component=None, component_args=None, onchange=None): + self.default = default + self.label = label + self.component = component + self.component_args = component_args + self.onchange = onchange + + +def options_section(section_identifer, options_dict): + for k, v in options_dict.items(): + v.section = section_identifer + + return options_dict + + +hide_dirs = {"visible": False} if cmd_opts.hide_ui_dir_config else None + +options_templates = {} + +options_templates.update(options_section((0, "General"), { + "filter_nsfw": OptionInfo(False, "Filter NSFW content"), + "enable_pnginfo": OptionInfo(True, "Save text information about generation parameters as chunks to png files"), + "add_model_hash_to_info": OptionInfo(False, "Add model hash to generation information"), + "save_txt": OptionInfo(False, "Create a text file next to every image with generation parameters."), + "ESRGAN_tile": OptionInfo(192, "Tile size for ESRGAN upscalers. 0 = no tiling.", gr.Slider, {"minimum": 0, "maximum": 512, "step": 16}), + "ESRGAN_tile_overlap": OptionInfo(8, "Tile overlap, in pixels for ESRGAN upscalers. Low values = visible seam.", gr.Slider, {"minimum": 0, "maximum": 48, "step": 1}), + "realesrgan_enabled_models": OptionInfo(["Real-ESRGAN 4x plus", "Real-ESRGAN 4x plus anime 6B"], "Select which RealESRGAN models to show in the web UI. (Requires restart)", gr.CheckboxGroup, lambda: {"choices": realesrgan_models_names()}), + "SWIN_tile": OptionInfo(192, "Tile size for all SwinIR.", gr.Slider, {"minimum": 16, "maximum": 512, "step": 16}), + "SWIN_tile_overlap": OptionInfo(8, "Tile overlap, in pixels for SwinIR. Low values = visible seam.", gr.Slider, {"minimum": 0, "maximum": 48, "step": 1}), + "ldsr_steps": OptionInfo(100, "LDSR processing steps. Lower = faster", gr.Slider, {"minimum": 1, "maximum": 200, "step": 1}), + "ldsr_pre_down": OptionInfo(1, "LDSR Pre-process downssample scale. 1 = no down-sampling, 4 = 1/4 scale.", gr.Slider, {"minimum": 1, "maximum": 4, "step": 1}), + "ldsr_post_down": OptionInfo(1, "LDSR Post-process down-sample scale. 1 = no down-sampling, 4 = 1/4 scale.", gr.Slider, {"minimum": 1, "maximum": 4, "step": 1}), + "random_artist_categories": OptionInfo([], "Allowed categories for random artists selection when using the Roll button", gr.CheckboxGroup, {"choices": artist_db.categories()}), + "upscaler_for_hires_fix": OptionInfo(None, "Upscaler for highres. fix", gr.Radio, lambda: {"choices": [x.name for x in sd_upscalers]}), + "show_progressbar": OptionInfo(True, "Show progressbar"), + "show_progress_every_n_steps": OptionInfo(0, "Show show image creation progress every N sampling steps. Set 0 to disable.", gr.Slider, {"minimum": 0, "maximum": 32, "step": 1}), + "multiple_tqdm": OptionInfo(True, "Add a second progress bar to the console that shows progress for an entire job. Broken in PyCharm console."), + "memmon_poll_rate": OptionInfo(8, "VRAM usage polls per second during generation. Set to 0 to disable.", gr.Slider, {"minimum": 0, "maximum": 40, "step": 1}), + "face_restoration_model": OptionInfo(None, "Face restoration model", gr.Radio, lambda: {"choices": [x.name() for x in face_restorers]}), + "code_former_weight": OptionInfo(0.5, "CodeFormer weight parameter; 0 = maximum effect; 1 = minimum effect", gr.Slider, {"minimum": 0, "maximum": 1, "step": 0.01}), + "save_images_before_face_restoration": OptionInfo(False, "Save a copy of image before doing face restoration."), + "face_restoration_unload": OptionInfo(False, "Move face restoration model from VRAM into RAM after processing"), + "sd_model_checkpoint": OptionInfo(None, "Stable Diffusion checkpoint", gr.Radio, lambda: {"choices": [x.title for x in modules.sd_models.checkpoints_list.values()]}), + "js_modal_lightbox": OptionInfo(True, "Enable full page image viewer"), + "js_modal_lightbox_initialy_zoomed": OptionInfo(True, "Show images zoomed in by default in full page image viewer"), + "use_original_name_batch": OptionInfo(False, "Use original name for output filename during batch process"), +})) + +options_templates.update(options_section((1, "File and Folder Locations"), { + "samples_filename_pattern": OptionInfo("", "Images filename pattern"), + "save_to_dirs": OptionInfo(False, "Save images to a subdirectory"), + "grid_save_to_dirs": OptionInfo(False, "Save grids to subdirectory"), + "directories_filename_pattern": OptionInfo("", "Directory name pattern"), + "directories_max_prompt_words": OptionInfo(8, "Max prompt words", gr.Slider, {"minimum": 1, "maximum": 20, "step": 1}), + "outdir_samples": OptionInfo("", "Output directory for images; if empty, defaults to two directories below", component_args=hide_dirs), + "outdir_txt2img_samples": OptionInfo("outputs/txt2img-images", 'Output directory for txt2img images', component_args=hide_dirs), + "outdir_img2img_samples": OptionInfo("outputs/img2img-images", 'Output directory for img2img images', component_args=hide_dirs), + "outdir_extras_samples": OptionInfo("outputs/extras-images", 'Output directory for images from extras tab', component_args=hide_dirs), + "outdir_grids": OptionInfo("", "Output directory for grids; if empty, defaults to two directories below", component_args=hide_dirs), + "outdir_txt2img_grids": OptionInfo("outputs/txt2img-grids", 'Output directory for txt2img grids', component_args=hide_dirs), + "outdir_img2img_grids": OptionInfo("outputs/img2img-grids", 'Output directory for img2img grids', component_args=hide_dirs), + "outdir_save": OptionInfo("log/images", "Directory for saving images using the Save button", component_args=hide_dirs), + "jpeg_quality": OptionInfo(80, "Quality for saved jpeg images", gr.Slider, {"minimum": 1, "maximum": 100, "step": 1}), + "export_for_4chan": OptionInfo(True, "If PNG image is larger than 4MB or any dimension is larger than 4000, downscale and save copy as JPG"), +})) + +options_templates.update(options_section((2, "Sampling Options"), { + "samples_save": OptionInfo(True, "Always save all generated images"), + "samples_log_stdout": OptionInfo(False, "Always print all generation info to standard output"), + "save_selected_only": OptionInfo(False, "When using 'Save' button, only save a single selected image"), + "samples_format": OptionInfo('png', 'File format for individual samples'), +})) + +options_templates.update(options_section((3, "Grid Options"), { + "grid_save": OptionInfo(True, "Always save all generated image grids"), + "return_grid": OptionInfo(True, "Show grid in results for web"), + "grid_format": OptionInfo('png', 'File format for grids'), + "grid_extended_filename": OptionInfo(False, "Add extended info (seed, prompt) to filename when saving grid"), + "grid_only_if_multiple": OptionInfo(True, "Do not save grids consisting of one picture"), + "n_rows": OptionInfo(-1, "Grid row count; use -1 for autodetect and 0 for it to be same as batch size", gr.Slider, {"minimum": -1, "maximum": 16, "step": 1}), +})) + +options_templates.update(options_section((4, "Model Options"), { + "img2img_color_correction": OptionInfo(False, "Apply color correction to img2img results to match original colors."), + "img2img_fix_steps": OptionInfo(False, "With img2img, do exactly the amount of steps the slider specifies (normally you'd do less with less denoising)."), + "enable_quantization": OptionInfo(False, "Enable quantization in K samplers for sharper and cleaner results. This may change existing seeds. Requires restart to apply."), + "font": OptionInfo("", "Font for image grids that have text"), + "enable_emphasis": OptionInfo(True, "Use (text) to make model pay more attention to text and [text] to make it pay less attention"), + "enable_batch_seeds": OptionInfo(True, "Make K-diffusion samplers produce same images in a batch as when making a single image"), +})) + +options_templates.update(options_section((5, "Interrogate Options"), { + "interrogate_keep_models_in_memory": OptionInfo(False, "Interrogate: keep models in VRAM"), + "interrogate_use_builtin_artists": OptionInfo(True, "Interrogate: use artists from artists.csv"), + "interrogate_clip_num_beams": OptionInfo(1, "Interrogate: num_beams for BLIP", gr.Slider, {"minimum": 1, "maximum": 16, "step": 1}), + "interrogate_clip_min_length": OptionInfo(24, "Interrogate: minimum description length (excluding artists, etc..)", gr.Slider, {"minimum": 1, "maximum": 128, "step": 1}), + "interrogate_clip_max_length": OptionInfo(48, "Interrogate: maximum description length", gr.Slider, {"minimum": 1, "maximum": 256, "step": 1}), + "interrogate_clip_dict_limit": OptionInfo(1500, "Interrogate: maximum number of lines in text file (0 = No limit)"), +})) + class Options: - class OptionInfo: - def __init__(self, default=None, label="", component=None, component_args=None, onchange=None): - self.default = default - self.label = label - self.component = component - self.component_args = component_args - self.onchange = onchange - data = None - hide_dirs = {"visible": False} if cmd_opts.hide_ui_dir_config else None - - data_labels.update(optionsSection((0,"General"),{ - "filter_nsfw": OptionInfo(False, "Filter NSFW content"), - "enable_pnginfo": OptionInfo(True, "Save text information about generation parameters as chunks to png files"), - "add_model_hash_to_info": OptionInfo(False, "Add model hash to generation information"), - "save_txt": OptionInfo(False, "Create a text file next to every image with generation parameters."), - "ESRGAN_tile": OptionInfo(192, "Tile size for ESRGAN upscalers. 0 = no tiling.", gr.Slider, {"minimum": 0, "maximum": 512, "step": 16}), - "ESRGAN_tile_overlap": OptionInfo(8, "Tile overlap, in pixels for ESRGAN upscalers. Low values = visible seam.", gr.Slider, {"minimum": 0, "maximum": 48, "step": 1}), - "realesrgan_enabled_models": OptionInfo(["Real-ESRGAN 4x plus", "Real-ESRGAN 4x plus anime 6B"], "Select which RealESRGAN models to show in the web UI. (Requires restart)", gr.CheckboxGroup, lambda: {"choices": realesrgan_models_names()}), - "SWIN_tile": OptionInfo(192, "Tile size for all SwinIR.", gr.Slider, {"minimum": 16, "maximum": 512, "step": 16}), - "SWIN_tile_overlap": OptionInfo(8, "Tile overlap, in pixels for SwinIR. Low values = visible seam.", gr.Slider, {"minimum": 0, "maximum": 48, "step": 1}), - "ldsr_steps": OptionInfo(100, "LDSR processing steps. Lower = faster", gr.Slider, {"minimum": 1, "maximum": 200, "step": 1}), - "ldsr_pre_down":OptionInfo(1, "LDSR Pre-process downssample scale. 1 = no down-sampling, 4 = 1/4 scale.", gr.Slider, {"minimum": 1, "maximum": 4, "step": 1}), - "ldsr_post_down":OptionInfo(1, "LDSR Post-process down-sample scale. 1 = no down-sampling, 4 = 1/4 scale.", gr.Slider, {"minimum": 1, "maximum": 4, "step": 1}), - "random_artist_categories": OptionInfo([], "Allowed categories for random artists selection when using the Roll button", gr.CheckboxGroup, {"choices": artist_db.categories()}), - "upscaler_for_hires_fix": OptionInfo(None, "Upscaler for highres. fix", gr.Radio, lambda: {"choices": [x.name for x in sd_upscalers]}), - "show_progressbar": OptionInfo(True, "Show progressbar"), - "show_progress_every_n_steps": OptionInfo(0, "Show show image creation progress every N sampling steps. Set 0 to disable.", gr.Slider, {"minimum": 0, "maximum": 32, "step": 1}), - "multiple_tqdm": OptionInfo(True, "Add a second progress bar to the console that shows progress for an entire job. Broken in PyCharm console."), - "memmon_poll_rate": OptionInfo(8, "VRAM usage polls per second during generation. Set to 0 to disable.", gr.Slider, {"minimum": 0, "maximum": 40, "step":1}), - "face_restoration_model": OptionInfo(None, "Face restoration model", gr.Radio, lambda: {"choices": [x.name() for x in face_restorers]}), - "code_former_weight": OptionInfo(0.5, "CodeFormer weight parameter; 0 = maximum effect; 1 = minimum effect", gr.Slider, {"minimum": 0, "maximum": 1, "step": 0.01}), - "save_images_before_face_restoration": OptionInfo(False, "Save a copy of image before doing face restoration."), - "face_restoration_unload": OptionInfo(False, "Move face restoration model from VRAM into RAM after processing"), - "sd_model_checkpoint": OptionInfo(None, "Stable Diffusion checkpoint", gr.Radio, lambda: {"choices": [x.title for x in modules.sd_models.checkpoints_list.values()]}), - "js_modal_lightbox": OptionInfo(True, "Enable full page image viewer"), - "js_modal_lightbox_initialy_zoomed": OptionInfo(True, "Show images zoomed in by default in full page image viewer"), - "use_original_name_batch": OptionInfo(False, "Use original name for output filename during batch process"), - })) - - data_labels.update(optionsSection((1,"File and Folder Locations"),{ - "samples_filename_pattern": OptionInfo("", "Images filename pattern"), - "save_to_dirs": OptionInfo(False, "Save images to a subdirectory"), - "grid_save_to_dirs": OptionInfo(False, "Save grids to subdirectory"), - "directories_filename_pattern": OptionInfo("", "Directory name pattern"), - "directories_max_prompt_words": OptionInfo(8, "Max prompt words", gr.Slider, {"minimum": 1, "maximum": 20, "step": 1}), - "outdir_samples": OptionInfo("", "Output directory for images; if empty, defaults to two directories below", component_args=hide_dirs), - "outdir_txt2img_samples": OptionInfo("outputs/txt2img-images", 'Output directory for txt2img images', component_args=hide_dirs), - "outdir_img2img_samples": OptionInfo("outputs/img2img-images", 'Output directory for img2img images', component_args=hide_dirs), - "outdir_extras_samples": OptionInfo("outputs/extras-images", 'Output directory for images from extras tab', component_args=hide_dirs), - "outdir_grids": OptionInfo("", "Output directory for grids; if empty, defaults to two directories below", component_args=hide_dirs), - "outdir_txt2img_grids": OptionInfo("outputs/txt2img-grids", 'Output directory for txt2img grids', component_args=hide_dirs), - "outdir_img2img_grids": OptionInfo("outputs/img2img-grids", 'Output directory for img2img grids', component_args=hide_dirs), - "outdir_save": OptionInfo("log/images", "Directory for saving images using the Save button", component_args=hide_dirs), - "jpeg_quality": OptionInfo(80, "Quality for saved jpeg images", gr.Slider, {"minimum": 1, "maximum": 100, "step": 1}), - "export_for_4chan": OptionInfo(True, "If PNG image is larger than 4MB or any dimension is larger than 4000, downscale and save copy as JPG"), - })) - - data_labels.update(optionsSection((2,"Sampling Options"),{ - "samples_save": OptionInfo(True, "Always save all generated images"), - "samples_log_stdout": OptionInfo(False, "Always print all generation info to standard output"), - "save_selected_only": OptionInfo(False, "When using 'Save' button, only save a single selected image"), - "samples_format": OptionInfo('png', 'File format for individual samples'), - })) - - data_labels.update(optionsSection((3,"Grid Options"),{ - "grid_save": OptionInfo(True, "Always save all generated image grids"), - "return_grid": OptionInfo(True, "Show grid in results for web"), - "grid_format": OptionInfo('png', 'File format for grids'), - "grid_extended_filename": OptionInfo(False, "Add extended info (seed, prompt) to filename when saving grid"), - "grid_only_if_multiple": OptionInfo(True, "Do not save grids consisting of one picture"), - "n_rows": OptionInfo(-1, "Grid row count; use -1 for autodetect and 0 for it to be same as batch size", gr.Slider, {"minimum": -1, "maximum": 16, "step": 1}), - })) - - data_labels.update(optionsSection((4,"Model Options"),{ - "img2img_color_correction": OptionInfo(False, "Apply color correction to img2img results to match original colors."), - "img2img_fix_steps": OptionInfo(False, "With img2img, do exactly the amount of steps the slider specifies (normally you'd do less with less denoising)."), - "enable_quantization": OptionInfo(False, "Enable quantization in K samplers for sharper and cleaner results. This may change existing seeds. Requires restart to apply."), - "font": OptionInfo("", "Font for image grids that have text"), - "enable_emphasis": OptionInfo(True, "Use (text) to make model pay more attention to text and [text] to make it pay less attention"), - "enable_batch_seeds": OptionInfo(True, "Make K-diffusion samplers produce same images in a batch as when making a single image"), - })) - - data_labels.update(optionsSection((5,"Interrogate Options"),{ - "interrogate_keep_models_in_memory": OptionInfo(False, "Interrogate: keep models in VRAM"), - "interrogate_use_builtin_artists": OptionInfo(True, "Interrogate: use artists from artists.csv"), - "interrogate_clip_num_beams": OptionInfo(1, "Interrogate: num_beams for BLIP", gr.Slider, {"minimum": 1, "maximum": 16, "step": 1}), - "interrogate_clip_min_length": OptionInfo(24, "Interrogate: minimum description length (excluding artists, etc..)", gr.Slider, {"minimum": 1, "maximum": 128, "step": 1}), - "interrogate_clip_max_length": OptionInfo(48, "Interrogate: maximum description length", gr.Slider, {"minimum": 1, "maximum": 256, "step": 1}), - "interrogate_clip_dict_limit": OptionInfo(1500, "Interrogate: maximum number of lines in text file (0 = No limit)"), - })) + data_labels = options_templates def __init__(self): self.data = {k: v.default for k, v in self.data_labels.items()} From 77cf346d9356b676abb1d101eb255b457466914a Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Thu, 22 Sep 2022 21:32:44 +0300 Subject: [PATCH 08/10] settings categories split to columns, remade categories --- modules/shared.py | 108 ++++++++++++++++++++++++++-------------------- modules/ui.py | 55 +++++++++++++---------- 2 files changed, 93 insertions(+), 70 deletions(-) diff --git a/modules/shared.py b/modules/shared.py index 009a4940d..7befbdcfd 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -107,6 +107,7 @@ class OptionInfo: self.component = component self.component_args = component_args self.onchange = onchange + self.section = None def options_section(section_identifer, options_dict): @@ -120,11 +121,45 @@ hide_dirs = {"visible": False} if cmd_opts.hide_ui_dir_config else None options_templates = {} -options_templates.update(options_section((0, "General"), { - "filter_nsfw": OptionInfo(False, "Filter NSFW content"), +options_templates.update(options_section(('saving-images', "Saving images/grids"), { + "samples_save": OptionInfo(True, "Always save all generated images"), + "samples_format": OptionInfo('png', 'File format for images'), + "samples_filename_pattern": OptionInfo("", "Images filename pattern"), + + "grid_save": OptionInfo(True, "Always save all generated image grids"), + "grid_format": OptionInfo('png', 'File format for grids'), + "grid_extended_filename": OptionInfo(False, "Add extended info (seed, prompt) to filename when saving grid"), + "grid_only_if_multiple": OptionInfo(True, "Do not save grids consisting of one picture"), + "n_rows": OptionInfo(-1, "Grid row count; use -1 for autodetect and 0 for it to be same as batch size", gr.Slider, {"minimum": -1, "maximum": 16, "step": 1}), + "enable_pnginfo": OptionInfo(True, "Save text information about generation parameters as chunks to png files"), - "add_model_hash_to_info": OptionInfo(False, "Add model hash to generation information"), "save_txt": OptionInfo(False, "Create a text file next to every image with generation parameters."), + "save_images_before_face_restoration": OptionInfo(False, "Save a copy of image before doing face restoration."), + "jpeg_quality": OptionInfo(80, "Quality for saved jpeg images", gr.Slider, {"minimum": 1, "maximum": 100, "step": 1}), + "export_for_4chan": OptionInfo(True, "If PNG image is larger than 4MB or any dimension is larger than 4000, downscale and save copy as JPG"), + + "use_original_name_batch": OptionInfo(False, "Use original name for output filename during batch process in extras tab"), +})) + +options_templates.update(options_section(('saving-paths', "Paths for saving"), { + "outdir_samples": OptionInfo("", "Output directory for images; if empty, defaults to three directories below", component_args=hide_dirs), + "outdir_txt2img_samples": OptionInfo("outputs/txt2img-images", 'Output directory for txt2img images', component_args=hide_dirs), + "outdir_img2img_samples": OptionInfo("outputs/img2img-images", 'Output directory for img2img images', component_args=hide_dirs), + "outdir_extras_samples": OptionInfo("outputs/extras-images", 'Output directory for images from extras tab', component_args=hide_dirs), + "outdir_grids": OptionInfo("", "Output directory for grids; if empty, defaults to two directories below", component_args=hide_dirs), + "outdir_txt2img_grids": OptionInfo("outputs/txt2img-grids", 'Output directory for txt2img grids', component_args=hide_dirs), + "outdir_img2img_grids": OptionInfo("outputs/img2img-grids", 'Output directory for img2img grids', component_args=hide_dirs), + "outdir_save": OptionInfo("log/images", "Directory for saving images using the Save button", component_args=hide_dirs), +})) + +options_templates.update(options_section(('saving-to-dirs', "Saving to a directory"), { + "save_to_dirs": OptionInfo(False, "Save images to a subdirectory"), + "grid_save_to_dirs": OptionInfo(False, "Save grids to subdirectory"), + "directories_filename_pattern": OptionInfo("", "Directory name pattern"), + "directories_max_prompt_words": OptionInfo(8, "Max prompt words", gr.Slider, {"minimum": 1, "maximum": 20, "step": 1}), +})) + +options_templates.update(options_section(('upscaling', "Upscaling"), { "ESRGAN_tile": OptionInfo(192, "Tile size for ESRGAN upscalers. 0 = no tiling.", gr.Slider, {"minimum": 0, "maximum": 512, "step": 16}), "ESRGAN_tile_overlap": OptionInfo(8, "Tile overlap, in pixels for ESRGAN upscalers. Low values = visible seam.", gr.Slider, {"minimum": 0, "maximum": 48, "step": 1}), "realesrgan_enabled_models": OptionInfo(["Real-ESRGAN 4x plus", "Real-ESRGAN 4x plus anime 6B"], "Select which RealESRGAN models to show in the web UI. (Requires restart)", gr.CheckboxGroup, lambda: {"choices": realesrgan_models_names()}), @@ -133,66 +168,35 @@ options_templates.update(options_section((0, "General"), { "ldsr_steps": OptionInfo(100, "LDSR processing steps. Lower = faster", gr.Slider, {"minimum": 1, "maximum": 200, "step": 1}), "ldsr_pre_down": OptionInfo(1, "LDSR Pre-process downssample scale. 1 = no down-sampling, 4 = 1/4 scale.", gr.Slider, {"minimum": 1, "maximum": 4, "step": 1}), "ldsr_post_down": OptionInfo(1, "LDSR Post-process down-sample scale. 1 = no down-sampling, 4 = 1/4 scale.", gr.Slider, {"minimum": 1, "maximum": 4, "step": 1}), - "random_artist_categories": OptionInfo([], "Allowed categories for random artists selection when using the Roll button", gr.CheckboxGroup, {"choices": artist_db.categories()}), + "upscaler_for_hires_fix": OptionInfo(None, "Upscaler for highres. fix", gr.Radio, lambda: {"choices": [x.name for x in sd_upscalers]}), - "show_progressbar": OptionInfo(True, "Show progressbar"), - "show_progress_every_n_steps": OptionInfo(0, "Show show image creation progress every N sampling steps. Set 0 to disable.", gr.Slider, {"minimum": 0, "maximum": 32, "step": 1}), - "multiple_tqdm": OptionInfo(True, "Add a second progress bar to the console that shows progress for an entire job. Broken in PyCharm console."), - "memmon_poll_rate": OptionInfo(8, "VRAM usage polls per second during generation. Set to 0 to disable.", gr.Slider, {"minimum": 0, "maximum": 40, "step": 1}), +})) + +options_templates.update(options_section(('face-restoration', "Face restoration"), { "face_restoration_model": OptionInfo(None, "Face restoration model", gr.Radio, lambda: {"choices": [x.name() for x in face_restorers]}), "code_former_weight": OptionInfo(0.5, "CodeFormer weight parameter; 0 = maximum effect; 1 = minimum effect", gr.Slider, {"minimum": 0, "maximum": 1, "step": 0.01}), - "save_images_before_face_restoration": OptionInfo(False, "Save a copy of image before doing face restoration."), "face_restoration_unload": OptionInfo(False, "Move face restoration model from VRAM into RAM after processing"), - "sd_model_checkpoint": OptionInfo(None, "Stable Diffusion checkpoint", gr.Radio, lambda: {"choices": [x.title for x in modules.sd_models.checkpoints_list.values()]}), - "js_modal_lightbox": OptionInfo(True, "Enable full page image viewer"), - "js_modal_lightbox_initialy_zoomed": OptionInfo(True, "Show images zoomed in by default in full page image viewer"), - "use_original_name_batch": OptionInfo(False, "Use original name for output filename during batch process"), -})) - -options_templates.update(options_section((1, "File and Folder Locations"), { - "samples_filename_pattern": OptionInfo("", "Images filename pattern"), - "save_to_dirs": OptionInfo(False, "Save images to a subdirectory"), - "grid_save_to_dirs": OptionInfo(False, "Save grids to subdirectory"), - "directories_filename_pattern": OptionInfo("", "Directory name pattern"), - "directories_max_prompt_words": OptionInfo(8, "Max prompt words", gr.Slider, {"minimum": 1, "maximum": 20, "step": 1}), - "outdir_samples": OptionInfo("", "Output directory for images; if empty, defaults to two directories below", component_args=hide_dirs), - "outdir_txt2img_samples": OptionInfo("outputs/txt2img-images", 'Output directory for txt2img images', component_args=hide_dirs), - "outdir_img2img_samples": OptionInfo("outputs/img2img-images", 'Output directory for img2img images', component_args=hide_dirs), - "outdir_extras_samples": OptionInfo("outputs/extras-images", 'Output directory for images from extras tab', component_args=hide_dirs), - "outdir_grids": OptionInfo("", "Output directory for grids; if empty, defaults to two directories below", component_args=hide_dirs), - "outdir_txt2img_grids": OptionInfo("outputs/txt2img-grids", 'Output directory for txt2img grids', component_args=hide_dirs), - "outdir_img2img_grids": OptionInfo("outputs/img2img-grids", 'Output directory for img2img grids', component_args=hide_dirs), - "outdir_save": OptionInfo("log/images", "Directory for saving images using the Save button", component_args=hide_dirs), - "jpeg_quality": OptionInfo(80, "Quality for saved jpeg images", gr.Slider, {"minimum": 1, "maximum": 100, "step": 1}), - "export_for_4chan": OptionInfo(True, "If PNG image is larger than 4MB or any dimension is larger than 4000, downscale and save copy as JPG"), -})) - -options_templates.update(options_section((2, "Sampling Options"), { - "samples_save": OptionInfo(True, "Always save all generated images"), - "samples_log_stdout": OptionInfo(False, "Always print all generation info to standard output"), "save_selected_only": OptionInfo(False, "When using 'Save' button, only save a single selected image"), - "samples_format": OptionInfo('png', 'File format for individual samples'), })) -options_templates.update(options_section((3, "Grid Options"), { - "grid_save": OptionInfo(True, "Always save all generated image grids"), - "return_grid": OptionInfo(True, "Show grid in results for web"), - "grid_format": OptionInfo('png', 'File format for grids'), - "grid_extended_filename": OptionInfo(False, "Add extended info (seed, prompt) to filename when saving grid"), - "grid_only_if_multiple": OptionInfo(True, "Do not save grids consisting of one picture"), - "n_rows": OptionInfo(-1, "Grid row count; use -1 for autodetect and 0 for it to be same as batch size", gr.Slider, {"minimum": -1, "maximum": 16, "step": 1}), +options_templates.update(options_section(('system', "System"), { + "memmon_poll_rate": OptionInfo(8, "VRAM usage polls per second during generation. Set to 0 to disable.", gr.Slider, {"minimum": 0, "maximum": 40, "step": 1}), + "samples_log_stdout": OptionInfo(False, "Always print all generation info to standard output"), + "multiple_tqdm": OptionInfo(True, "Add a second progress bar to the console that shows progress for an entire job. Broken in PyCharm console."), })) -options_templates.update(options_section((4, "Model Options"), { +options_templates.update(options_section(('sd', "Stable Diffusion"), { + "sd_model_checkpoint": OptionInfo(None, "Stable Diffusion checkpoint", gr.Radio, lambda: {"choices": [x.title for x in modules.sd_models.checkpoints_list.values()]}), "img2img_color_correction": OptionInfo(False, "Apply color correction to img2img results to match original colors."), "img2img_fix_steps": OptionInfo(False, "With img2img, do exactly the amount of steps the slider specifies (normally you'd do less with less denoising)."), "enable_quantization": OptionInfo(False, "Enable quantization in K samplers for sharper and cleaner results. This may change existing seeds. Requires restart to apply."), - "font": OptionInfo("", "Font for image grids that have text"), "enable_emphasis": OptionInfo(True, "Use (text) to make model pay more attention to text and [text] to make it pay less attention"), "enable_batch_seeds": OptionInfo(True, "Make K-diffusion samplers produce same images in a batch as when making a single image"), + "filter_nsfw": OptionInfo(False, "Filter NSFW content"), + "random_artist_categories": OptionInfo([], "Allowed categories for random artists selection when using the Roll button", gr.CheckboxGroup, {"choices": artist_db.categories()}), })) -options_templates.update(options_section((5, "Interrogate Options"), { +options_templates.update(options_section(('interrogate', "Interrogate Options"), { "interrogate_keep_models_in_memory": OptionInfo(False, "Interrogate: keep models in VRAM"), "interrogate_use_builtin_artists": OptionInfo(True, "Interrogate: use artists from artists.csv"), "interrogate_clip_num_beams": OptionInfo(1, "Interrogate: num_beams for BLIP", gr.Slider, {"minimum": 1, "maximum": 16, "step": 1}), @@ -201,6 +205,16 @@ options_templates.update(options_section((5, "Interrogate Options"), { "interrogate_clip_dict_limit": OptionInfo(1500, "Interrogate: maximum number of lines in text file (0 = No limit)"), })) +options_templates.update(options_section(('ui', "User interface"), { + "show_progressbar": OptionInfo(True, "Show progressbar"), + "show_progress_every_n_steps": OptionInfo(0, "Show show image creation progress every N sampling steps. Set 0 to disable.", gr.Slider, {"minimum": 0, "maximum": 32, "step": 1}), + "return_grid": OptionInfo(True, "Show grid in results for web"), + "add_model_hash_to_info": OptionInfo(True, "Add model hash to generation information"), + "font": OptionInfo("", "Font for image grids that have text"), + "js_modal_lightbox": OptionInfo(True, "Enable full page image viewer"), + "js_modal_lightbox_initialy_zoomed": OptionInfo(True, "Show images zoomed in by default in full page image viewer"), +})) + class Options: data = None diff --git a/modules/ui.py b/modules/ui.py index 0d9f4c097..036f2ed3a 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -9,7 +9,6 @@ import random import sys import time import traceback -import itertools import numpy as np import torch @@ -23,7 +22,6 @@ from modules.paths import script_path from modules.shared import opts, cmd_opts import modules.shared as shared from modules.sd_samplers import samplers, samplers_for_img2img -import modules.realesrgan_model as realesrgan import modules.ldsr_model import modules.scripts import modules.gfpgan_model @@ -815,9 +813,6 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo): return comp(label=info.label, value=fun, **(args or {})) components = [] - keys = list(opts.data_labels.keys()) - settings_cols = 3 - items_per_col = math.ceil(len(keys) / settings_cols) def run_settings(*args): up = [] @@ -843,28 +838,33 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo): settings_submit = gr.Button(value="Apply settings", variant='primary') result = gr.HTML() - sortedKeys = sorted([(opts.data_labels[key].section,key) for key in keys],key=lambda x:x[0]) - groupedKeys = itertools.groupby(sortedKeys,key=lambda x:x[0]) + settings_cols = 3 + items_per_col = int(len(opts.data_labels) * 0.9 / settings_cols) - for (sectionNumber,sectionName),sectionGroup in groupedKeys: - with gr.Row(elem_id="settings_header_{}".format(sectionNumber)).style(equal_height=False): - gr.HTML(elem_id="settings_header_text_{}".format(sectionNumber), value='

{}

'.format(sectionName)) + cols_displayed = 0 + items_displayed = 0 + previous_section = None + column = None + with gr.Row(elem_id="settings").style(equal_height=False): + for i, (k, item) in enumerate(opts.data_labels.items()): - with gr.Row(elem_id="settings_{}".format(sectionNumber)).style(equal_height=False): - columnLookup = {} - for colNum,element in zip(itertools.cycle(range(settings_cols)),sectionGroup): - columnLookup.setdefault(colNum,[]).append(element) + if previous_section != item.section: + if cols_displayed < settings_cols and (items_displayed >= items_per_col or previous_section is None): + if column is not None: + column.__exit__() - for colno,elements in sorted(columnLookup.items()): - with gr.Column(variant='panel'): - for _,keyElement in elements: - components.append(create_setting_component(keyElement)) + column = gr.Column(variant='panel') + column.__enter__() - settings_submit.click( - fn=run_settings, - inputs=components, - outputs=[result] - ) + items_displayed = 0 + cols_displayed += 1 + + previous_section = item.section + + gr.HTML(elem_id="settings_header_text_{}".format(item.section[0]), value='

{}

'.format(item.section[1])) + + components.append(create_setting_component(k)) + items_displayed += 1 request_notifications = gr.Button(value='Request browser notifications', elem_id="request_notifications") request_notifications.click( @@ -874,6 +874,15 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo): _js='function(){}' ) + if column is not None: + column.__exit__() + + settings_submit.click( + fn=run_settings, + inputs=components, + outputs=[result] + ) + interfaces = [ (txt2img_interface, "txt2img", "txt2img"), (img2img_interface, "img2img", "img2img"), From e16b9dc8192bc42cd13c7bdfc7d5719c102bc295 Mon Sep 17 00:00:00 2001 From: Connum Date: Thu, 22 Sep 2022 19:37:57 +0200 Subject: [PATCH 09/10] resize mask canvases to fit underlying image (fixes #668) --- javascript/imageMaskFix.js | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 javascript/imageMaskFix.js diff --git a/javascript/imageMaskFix.js b/javascript/imageMaskFix.js new file mode 100644 index 000000000..3d77bfe9b --- /dev/null +++ b/javascript/imageMaskFix.js @@ -0,0 +1,45 @@ +/** + * temporary fix for https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/668 + * @see https://github.com/gradio-app/gradio/issues/1721 + */ +window.addEventListener( 'resize', () => imageMaskResize()); +function imageMaskResize() { + const canvases = gradioApp().querySelectorAll('#img2maskimg .touch-none canvas'); + if ( ! canvases.length ) { + canvases_fixed = false; + window.removeEventListener( 'resize', imageMaskResize ); + return; + } + + const wrapper = canvases[0].closest('.touch-none'); + const previewImage = wrapper.previousElementSibling; + + if ( ! previewImage.complete ) { + previewImage.addEventListener( 'load', () => imageMaskResize()); + return; + } + + const w = previewImage.width; + const h = previewImage.height; + const nw = previewImage.naturalWidth; + const nh = previewImage.naturalHeight; + const portrait = nh > nw; + const factor = portrait; + + const wW = Math.min(w, portrait ? h/nh*nw : w/nw*nw); + const wH = Math.min(h, portrait ? h/nh*nh : w/nw*nh); + + wrapper.style.width = `${wW}px`; + wrapper.style.height = `${wH}px`; + wrapper.style.left = `${(w-wW)/2}px`; + wrapper.style.top = `${(h-wH)/2}px`; + + canvases.forEach( c => { + c.style.width = c.style.height = ''; + c.style.maxWidth = '100%'; + c.style.maxHeight = '100%'; + c.style.objectFit = 'contain'; + }); + } + + onUiUpdate(() => imageMaskResize()); \ No newline at end of file From 19fc3e82794245b663467a9be076271f6ae33f26 Mon Sep 17 00:00:00 2001 From: C43H66N12O12S2 <36072735+C43H66N12O12S2@users.noreply.github.com> Date: Thu, 22 Sep 2022 23:44:22 +0300 Subject: [PATCH 10/10] credit parlance-zz as they requested it --- scripts/outpainting_mk_2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/outpainting_mk_2.py b/scripts/outpainting_mk_2.py index 08851f427..9719bb8f9 100644 --- a/scripts/outpainting_mk_2.py +++ b/scripts/outpainting_mk_2.py @@ -11,7 +11,7 @@ from modules import images, processing, devices from modules.processing import Processed, process_images from modules.shared import opts, cmd_opts, state - +# https://github.com/parlance-zz/g-diffuser-bot def expand(x, dir, amount, power=0.75): is_left = dir == 3 is_right = dir == 1