From 5ea27f3d0c53b2d63b05a070528ed1e04d059144 Mon Sep 17 00:00:00 2001 From: Tony Beeman Date: Thu, 8 Sep 2022 22:58:25 -0700 Subject: [PATCH 1/3] Streamlit: Allow user defaults to be specified in a userconfig_streamlit.yaml file. --- .gitignore | 4 ++++ configs/webui/webui_streamlit.yaml | 2 ++ scripts/webui/util/imports.py | 3 +++ scripts/webui_streamlit.py | 3 +++ 4 files changed, 12 insertions(+) diff --git a/.gitignore b/.gitignore index 46597f4..a00f76d 100644 --- a/.gitignore +++ b/.gitignore @@ -47,11 +47,15 @@ MANIFEST .env_updated condaenv.*.requirements.txt +# Visual Studio directories +.vs/ +.vscode/ # =========================================================================== # # Repo-specific # =========================================================================== # /custom-conda-path.txt +/userconfig_streamlit.yaml /src/* /outputs/* /log/**/*.png diff --git a/configs/webui/webui_streamlit.yaml b/configs/webui/webui_streamlit.yaml index bceaa4f..0aeccae 100644 --- a/configs/webui/webui_streamlit.yaml +++ b/configs/webui/webui_streamlit.yaml @@ -1,5 +1,7 @@ # UI defaults configuration file. It is automatically loaded if located at configs/webui/webui_streamlit.yaml. # Any changes made here will be available automatically on the web app without having to stop it. +# You may add overrides in a file named "userconfig_streamlit.yaml" in the root directory of this project, +# which can contain any subset of the properties below. general: gpu: 0 outdir: outputs diff --git a/scripts/webui/util/imports.py b/scripts/webui/util/imports.py index e13ed1d..791e3bb 100644 --- a/scripts/webui/util/imports.py +++ b/scripts/webui/util/imports.py @@ -53,6 +53,9 @@ except: warnings.filterwarnings("ignore", category=DeprecationWarning) defaults = OmegaConf.load("configs/webui/webui_streamlit.yaml") +if (os.path.exists("userconfig_streamlit.yaml")): + user_defaults = OmegaConf.load("userconfig_streamlit.yaml"); + defaults = OmegaConf.merge(defaults, user_defaults) # this is a fix for Windows users. Without it, javascript files will be served with text/html content-type and the bowser will not show any UI mimetypes.init() diff --git a/scripts/webui_streamlit.py b/scripts/webui_streamlit.py index 7d8b35d..011391f 100644 --- a/scripts/webui_streamlit.py +++ b/scripts/webui_streamlit.py @@ -61,6 +61,9 @@ except: warnings.filterwarnings("ignore", category=DeprecationWarning) defaults = OmegaConf.load("configs/webui/webui_streamlit.yaml") +if (os.path.exists("userconfig_streamlit.yaml")): + user_defaults = OmegaConf.load("userconfig_streamlit.yaml"); + defaults = OmegaConf.merge(defaults, user_defaults) # this is a fix for Windows users. Without it, javascript files will be served with text/html content-type and the bowser will not show any UI mimetypes.init() From ca8ee265cdfa52aca30c0fadfd03d0f6bdda9602 Mon Sep 17 00:00:00 2001 From: Tony Beeman Date: Thu, 8 Sep 2022 23:50:33 -0700 Subject: [PATCH 2/3] Made sure img2txt and img2img checkboxes respect YAML defaults --- configs/webui/webui_streamlit.yaml | 2 ++ scripts/webui/ui/layout.py | 18 +++++++++--------- scripts/webui_streamlit.py | 18 +++++++++--------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/configs/webui/webui_streamlit.yaml b/configs/webui/webui_streamlit.yaml index 0aeccae..5bdc510 100644 --- a/configs/webui/webui_streamlit.yaml +++ b/configs/webui/webui_streamlit.yaml @@ -53,6 +53,7 @@ txt2img: RealESRGAN_model: "RealESRGAN_x4plus" variant_amount: 0.0 variant_seed: "" + write_info_files: True txt2vid: prompt: @@ -125,6 +126,7 @@ img2img: RealESRGAN_model: "RealESRGAN_x4plus" variant_amount: 0.0 variant_seed: "" + write_info_files: True gfpgan: strength: 100 \ No newline at end of file diff --git a/scripts/webui/ui/layout.py b/scripts/webui/ui/layout.py index d144184..57d9075 100644 --- a/scripts/webui/ui/layout.py +++ b/scripts/webui/ui/layout.py @@ -105,13 +105,13 @@ def layout(): with st.expander("Advanced"): separate_prompts = st.checkbox("Create Prompt Matrix.", value=False, help="Separate multiple prompts using the `|` character, and get all combinations of them.") - normalize_prompt_weights = st.checkbox("Normalize Prompt Weights.", value=True, help="Ensure the sum of all weights add up to 1.0") - save_individual_images = st.checkbox("Save individual images.", value=True, help="Save each image generated before any filter or enhancement is applied.") - save_grid = st.checkbox("Save grid",value=True, help="Save a grid with all the images generated into a single image.") - group_by_prompt = st.checkbox("Group results by prompt", value=True, + normalize_prompt_weights = st.checkbox("Normalize Prompt Weights.", value=defaults.txt2img.normalize_prompt_weights, help="Ensure the sum of all weights add up to 1.0") + save_individual_images = st.checkbox("Save individual images.", value=defaults.txt2img.save_individual_images, help="Save each image generated before any filter or enhancement is applied.") + save_grid = st.checkbox("Save grid",value=defaults.txt2img.save_grid, help="Save a grid with all the images generated into a single image.") + group_by_prompt = st.checkbox("Group results by prompt", value=defaults.txt2img.group_by_prompt, help="Saves all the images with the same prompt into the same folder. When using a prompt matrix each prompt combination will have its own folder.") - write_info_files = st.checkbox("Write Info file", value=True, help="Save a file next to the image with informartion about the generation.") - save_as_jpg = st.checkbox("Save samples as jpg", value=False, help="Saves the images as jpg instead of png.") + write_info_files = st.checkbox("Write Info file", value=defaults.txt2img.write_info_files, help="Save a file next to the image with informartion about the generation.") + save_as_jpg = st.checkbox("Save samples as jpg", value=defaults.txt2img.save_as_jpg, help="Saves the images as jpg instead of png.") if GFPGAN_available: use_GFPGAN = st.checkbox("Use GFPGAN", value=defaults.txt2img.use_GFPGAN, help="Uses the GFPGAN model to improve faces after the generation. This greatly improve the quality and consistency of faces but uses extra VRAM. Disable if you need the extra VRAM.") @@ -187,12 +187,12 @@ def layout(): normalize_prompt_weights = st.checkbox("Normalize Prompt Weights.", value=defaults.img2img.normalize_prompt_weights, help="Ensure the sum of all weights add up to 1.0") loopback = st.checkbox("Loopback.", value=defaults.img2img.loopback, help="Use images from previous batch when creating next batch.") random_seed_loopback = st.checkbox("Random loopback seed.", value=defaults.img2img.random_seed_loopback, help="Random loopback seed") - save_individual_images = st.checkbox("Save individual images.", value=True, help="Save each image generated before any filter or enhancement is applied.") + save_individual_images = st.checkbox("Save individual images.", value=defaults.img2img.save_individual_images, help="Save each image generated before any filter or enhancement is applied.") save_grid = st.checkbox("Save grid",value=defaults.img2img.save_grid, help="Save a grid with all the images generated into a single image.") group_by_prompt = st.checkbox("Group results by prompt", value=defaults.img2img.group_by_prompt, help="Saves all the images with the same prompt into the same folder. When using a prompt matrix each prompt combination will have its own folder.") - write_info_files = st.checkbox("Write Info file", value=True, help="Save a file next to the image with informartion about the generation.") - save_as_jpg = st.checkbox("Save samples as jpg", value=False, help="Saves the images as jpg instead of png.") + write_info_files = st.checkbox("Write Info file", value=defaults.img2img.write_info_files, help="Save a file next to the image with informartion about the generation.") + save_as_jpg = st.checkbox("Save samples as jpg", value=defaults.img2img.save_as_jpg, help="Saves the images as jpg instead of png.") if GFPGAN_available: use_GFPGAN = st.checkbox("Use GFPGAN", value=defaults.img2img.use_GFPGAN, help="Uses the GFPGAN model to improve faces after the generation.\ diff --git a/scripts/webui_streamlit.py b/scripts/webui_streamlit.py index 011391f..92d3ef5 100644 --- a/scripts/webui_streamlit.py +++ b/scripts/webui_streamlit.py @@ -1827,13 +1827,13 @@ def layout(): with st.expander("Advanced"): separate_prompts = st.checkbox("Create Prompt Matrix.", value=False, help="Separate multiple prompts using the `|` character, and get all combinations of them.") - normalize_prompt_weights = st.checkbox("Normalize Prompt Weights.", value=True, help="Ensure the sum of all weights add up to 1.0") - save_individual_images = st.checkbox("Save individual images.", value=True, help="Save each image generated before any filter or enhancement is applied.") - save_grid = st.checkbox("Save grid",value=True, help="Save a grid with all the images generated into a single image.") - group_by_prompt = st.checkbox("Group results by prompt", value=True, + normalize_prompt_weights = st.checkbox("Normalize Prompt Weights.", value=defaults.txt2img.normalize_prompt_weights, help="Ensure the sum of all weights add up to 1.0") + save_individual_images = st.checkbox("Save individual images.", value=defaults.txt2img.save_individual_images, help="Save each image generated before any filter or enhancement is applied.") + save_grid = st.checkbox("Save grid",value=defaults.txt2img.save_grid, help="Save a grid with all the images generated into a single image.") + group_by_prompt = st.checkbox("Group results by prompt", value=defaults.txt2img.group_by_prompt, help="Saves all the images with the same prompt into the same folder. When using a prompt matrix each prompt combination will have its own folder.") - write_info_files = st.checkbox("Write Info file", value=True, help="Save a file next to the image with informartion about the generation.") - save_as_jpg = st.checkbox("Save samples as jpg", value=False, help="Saves the images as jpg instead of png.") + write_info_files = st.checkbox("Write Info file", value=defaults.txt2img.write_info_files, help="Save a file next to the image with informartion about the generation.") + save_as_jpg = st.checkbox("Save samples as jpg", value=defaults.txt2img.save_as_jpg, help="Saves the images as jpg instead of png.") if GFPGAN_available: use_GFPGAN = st.checkbox("Use GFPGAN", value=defaults.txt2img.use_GFPGAN, help="Uses the GFPGAN model to improve faces after the generation. This greatly improve the quality and consistency of faces but uses extra VRAM. Disable if you need the extra VRAM.") @@ -1929,12 +1929,12 @@ def layout(): normalize_prompt_weights = st.checkbox("Normalize Prompt Weights.", value=defaults.img2img.normalize_prompt_weights, help="Ensure the sum of all weights add up to 1.0") loopback = st.checkbox("Loopback.", value=defaults.img2img.loopback, help="Use images from previous batch when creating next batch.") random_seed_loopback = st.checkbox("Random loopback seed.", value=defaults.img2img.random_seed_loopback, help="Random loopback seed") - save_individual_images = st.checkbox("Save individual images.", value=True, help="Save each image generated before any filter or enhancement is applied.") + save_individual_images = st.checkbox("Save individual images.", value=defaults.img2img.save_individual_images, help="Save each image generated before any filter or enhancement is applied.") save_grid = st.checkbox("Save grid",value=defaults.img2img.save_grid, help="Save a grid with all the images generated into a single image.") group_by_prompt = st.checkbox("Group results by prompt", value=defaults.img2img.group_by_prompt, help="Saves all the images with the same prompt into the same folder. When using a prompt matrix each prompt combination will have its own folder.") - write_info_files = st.checkbox("Write Info file", value=True, help="Save a file next to the image with informartion about the generation.") - save_as_jpg = st.checkbox("Save samples as jpg", value=False, help="Saves the images as jpg instead of png.") + write_info_files = st.checkbox("Write Info file", value=defaults.img2img.write_info_files, help="Save a file next to the image with informartion about the generation.") + save_as_jpg = st.checkbox("Save samples as jpg", value=defaults.img2img.save_as_jpg, help="Saves the images as jpg instead of png.") if GFPGAN_available: use_GFPGAN = st.checkbox("Use GFPGAN", value=defaults.img2img.use_GFPGAN, help="Uses the GFPGAN model to improve faces after the generation.\ From 417188200706e25401d84dc69582c1bc21d9e3dc Mon Sep 17 00:00:00 2001 From: Tony Beeman Date: Fri, 9 Sep 2022 00:44:35 -0700 Subject: [PATCH 3/3] Move location of user file to configs/webui folder --- .gitignore | 2 +- configs/webui/webui_streamlit.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index a00f76d..2e15597 100644 --- a/.gitignore +++ b/.gitignore @@ -54,8 +54,8 @@ condaenv.*.requirements.txt # =========================================================================== # # Repo-specific # =========================================================================== # +/configs/webui/userconfig_streamlit.yaml /custom-conda-path.txt -/userconfig_streamlit.yaml /src/* /outputs/* /log/**/*.png diff --git a/configs/webui/webui_streamlit.yaml b/configs/webui/webui_streamlit.yaml index 5bdc510..9060546 100644 --- a/configs/webui/webui_streamlit.yaml +++ b/configs/webui/webui_streamlit.yaml @@ -1,7 +1,7 @@ # UI defaults configuration file. It is automatically loaded if located at configs/webui/webui_streamlit.yaml. # Any changes made here will be available automatically on the web app without having to stop it. -# You may add overrides in a file named "userconfig_streamlit.yaml" in the root directory of this project, -# which can contain any subset of the properties below. +# You may add overrides in a file named "userconfig_streamlit.yaml" in this folder, which can contain any subset +# of the properties below. general: gpu: 0 outdir: outputs