From fcfe2e9ffd9b9ee8af63926a002602503f1ad71a Mon Sep 17 00:00:00 2001 From: Andrew Savchyn Date: Fri, 30 Sep 2022 10:51:05 +0200 Subject: [PATCH 1/4] Configurable launch script --- webui-user.sh | 3 +++ webui.sh | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/webui-user.sh b/webui-user.sh index 0ce41d3f0..11c316cbf 100644 --- a/webui-user.sh +++ b/webui-user.sh @@ -21,6 +21,9 @@ export COMMANDLINE_ARGS="" # python3 venv without trailing slash (defaults to ${install_dir}/${clone_dir}/venv) #venv_dir="venv" +# script to launch to start the app +#export launch_script="launch.py" + # install command for torch #export TORCH_COMMAND="pip install torch==1.12.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113" diff --git a/webui.sh b/webui.sh index 8355c9dff..6e27a4a6a 100755 --- a/webui.sh +++ b/webui.sh @@ -41,6 +41,11 @@ then venv_dir="venv" fi +if [[ -z "${launch_script}" ]] +then + launch_script="launch.py" +fi + # Disable sentry logging export ERROR_REPORTING=FALSE @@ -133,4 +138,4 @@ fi printf "\n%s\n" "${delimiter}" printf "Launching launch.py..." printf "\n%s\n" "${delimiter}" -"${python_cmd}" launch.py +"${python_cmd}" "${launch_script}" From d18daafb8b0b0b7c5f8dc179de7cc0717465297b Mon Sep 17 00:00:00 2001 From: Andrew Savchyn Date: Fri, 30 Sep 2022 11:44:08 +0200 Subject: [PATCH 2/4] Uppercase for env var LAUNCH_SCRIPT --- webui-user.sh | 2 +- webui.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/webui-user.sh b/webui-user.sh index 11c316cbf..30646f5c3 100644 --- a/webui-user.sh +++ b/webui-user.sh @@ -22,7 +22,7 @@ export COMMANDLINE_ARGS="" #venv_dir="venv" # script to launch to start the app -#export launch_script="launch.py" +#export LAUNCH_SCRIPT="launch.py" # install command for torch #export TORCH_COMMAND="pip install torch==1.12.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113" diff --git a/webui.sh b/webui.sh index 6e27a4a6a..05ca497d2 100755 --- a/webui.sh +++ b/webui.sh @@ -41,9 +41,9 @@ then venv_dir="venv" fi -if [[ -z "${launch_script}" ]] +if [[ -z "${LAUNCH_SCRIPT}" ]] then - launch_script="launch.py" + LAUNCH_SCRIPT="launch.py" fi # Disable sentry logging @@ -138,4 +138,4 @@ fi printf "\n%s\n" "${delimiter}" printf "Launching launch.py..." printf "\n%s\n" "${delimiter}" -"${python_cmd}" "${launch_script}" +"${python_cmd}" "${LAUNCH_SCRIPT}" From ff4df06c573c7054f736e0b5a35c24fad2427ab0 Mon Sep 17 00:00:00 2001 From: RnDMonkey Date: Thu, 29 Sep 2022 20:01:32 -0700 Subject: [PATCH 3/4] refined [styles] pattern and added [prompt_no_styles] --- javascript/hints.js | 4 ++-- modules/images.py | 8 +++++++- modules/styles.py | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/javascript/hints.js b/javascript/hints.js index 96cd24d5d..84694eeb3 100644 --- a/javascript/hints.js +++ b/javascript/hints.js @@ -58,8 +58,8 @@ titles = { "Interrogate": "Reconstruct prompt from existing image and put it into the prompt field.", - "Images filename pattern": "Use following tags to define how filenames for images are chosen: [steps], [cfg], [prompt], [prompt_spaces], [width], [height], [styles], [sampler], [seed], [model_hash], [prompt_words], [date], [datetime], [job_timestamp]; 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], [styles], [sampler], [seed], [model_hash], [prompt_words], [date], [datetime], [job_timestamp]; leave empty for default.", + "Images filename pattern": "Use following tags to define how filenames for images are chosen: [steps], [cfg], [prompt], [prompt_no_styles], [prompt_spaces], [width], [height], [styles], [sampler], [seed], [model_hash], [prompt_words], [date], [datetime], [job_timestamp]; leave empty for default.", + "Directory name pattern": "Use following tags to define how subdirectories for images and grids are chosen: [steps], [cfg], [prompt], [prompt_no_styles], [prompt_spaces], [width], [height], [styles], [sampler], [seed], [model_hash], [prompt_words], [date], [datetime], [job_timestamp]; 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.", diff --git a/modules/images.py b/modules/images.py index 2e8305ed8..87a4caf68 100644 --- a/modules/images.py +++ b/modules/images.py @@ -287,6 +287,12 @@ def apply_filename_pattern(x, p, seed, prompt): if prompt is not None: x = x.replace("[prompt]", sanitize_filename_part(prompt)) + if "[prompt_no_styles]" in x: + prompt_no_style = prompt + for style in shared.prompt_styles.get_style_prompts(p.styles): + prompt_no_style = prompt_no_style.replace(style.replace("{prompt}", ""), "") + x = x.replace("[prompt_no_styles]", sanitize_filename_part(prompt_no_style, replace_spaces=False)) + x = x.replace("[prompt_spaces]", sanitize_filename_part(prompt, replace_spaces=False)) if "[prompt_words]" in x: words = [x for x in re_nonletters.split(prompt or "") if len(x) > 0] @@ -299,7 +305,7 @@ def apply_filename_pattern(x, p, seed, prompt): x = x.replace("[cfg]", str(p.cfg_scale)) x = x.replace("[width]", str(p.width)) x = x.replace("[height]", str(p.height)) - x = x.replace("[styles]", sanitize_filename_part(", ".join(p.styles), replace_spaces=False)) + x = x.replace("[styles]", sanitize_filename_part(", ".join([x for x in p.styles if not x == "None"]), replace_spaces=False)) x = x.replace("[sampler]", sanitize_filename_part(sd_samplers.samplers[p.sampler_index].name, replace_spaces=False)) x = x.replace("[model_hash]", shared.sd_model.sd_model_hash) diff --git a/modules/styles.py b/modules/styles.py index eeedcd087..d44dfc1ad 100644 --- a/modules/styles.py +++ b/modules/styles.py @@ -53,6 +53,12 @@ class StyleDatabase: negative_prompt = row.get("negative_prompt", "") self.styles[row["name"]] = PromptStyle(row["name"], prompt, negative_prompt) + def get_style_prompts(self, styles): + return [self.styles.get(x, self.no_style).prompt for x in styles] + + def get_negative_style_prompts(self, styles): + return [self.styles.get(x, self.no_style).negative_prompt for x in styles] + def apply_styles_to_prompt(self, prompt, styles): return apply_styles_to_prompt(prompt, [self.styles.get(x, self.no_style).prompt for x in styles]) From 5c0c778a65c8f89a85395fb10e32d3b35ea57196 Mon Sep 17 00:00:00 2001 From: RnDMonkey Date: Fri, 30 Sep 2022 00:37:18 -0700 Subject: [PATCH 4/4] fixed so that {prompt} can be anywhere in style --- modules/images.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/images.py b/modules/images.py index 87a4caf68..169e19e64 100644 --- a/modules/images.py +++ b/modules/images.py @@ -290,7 +290,11 @@ def apply_filename_pattern(x, p, seed, prompt): if "[prompt_no_styles]" in x: prompt_no_style = prompt for style in shared.prompt_styles.get_style_prompts(p.styles): - prompt_no_style = prompt_no_style.replace(style.replace("{prompt}", ""), "") + if len(style) > 0: + style_parts = [y for y in style.split("{prompt}")] + for part in style_parts: + prompt_no_style = prompt_no_style.replace(part, "").replace(", ,", ",").strip().strip(',') + prompt_no_style = prompt_no_style.replace(style, "").strip().strip(',').strip() x = x.replace("[prompt_no_styles]", sanitize_filename_part(prompt_no_style, replace_spaces=False)) x = x.replace("[prompt_spaces]", sanitize_filename_part(prompt, replace_spaces=False))