From f3d1631aab82d559294126a9230c979ef4c4e1d6 Mon Sep 17 00:00:00 2001 From: JaredTherriault Date: Sun, 27 Aug 2023 21:54:05 -0700 Subject: [PATCH 1/3] Offloading custom work -custom_statics works to do mass replace strings, intended for copy-pasting gen info from internet generations and replacing unsavory prompts with safer prompts for my own sanity -tried to implement this into generation_parameters_copypaste but it didn't work out this iteration, presumably because we return a string and the calling method is looking for an object type -updated webui-user.bat to set a custom temp directory (for disk space concerns) and to apply xformers (for generation speed) I probably won't be merging any of this work into the main repo since I don't want to mess with anyone else's prompts, this is just intended to keep my workspace safe from anything I don't want to see. Eventually this should be done in an extension which I could then publish, but I need to learn a lot more about the extension and callback systems in the main repo first. just uploading this to my fork for now so i don't lose the current progress. --- modules/custom_statics.py | 29 ++++++++++++++++++++++ modules/generation_parameters_copypaste.py | 8 ++++++ webui-user.bat | 4 +-- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 modules/custom_statics.py diff --git a/modules/custom_statics.py b/modules/custom_statics.py new file mode 100644 index 00000000..207bd5fb --- /dev/null +++ b/modules/custom_statics.py @@ -0,0 +1,29 @@ +import os +import gc +import re + +import modules.paths as paths + +class CustomStatics: + + @staticmethod + # loads a file with strings structured as below, on each line with a : between the search and replace strings, into a list + # search0:replace0 + # search string:replace string + # + # Then replaces all occurrences of the list's search strings with the list's replace strings in one go + def mass_replace_strings(input_string): + with open(os.path.join(paths.data_path, "custom_statics/Replacements.txt"), "r", encoding="utf8") as file: + replacements = file.readlines() + + replacement_dict = {} + for line in replacements: + search, replace = line.strip().split(":") + replacement_dict[search] = replace + + def replace(match_text): + return replacement_dict[match_text.group(0)] + + return re.sub('|'.join(r'\b%s\b' % re.escape(s) for s in replacement_dict.keys()), replace, str(input_string)) + + return str(geninfo) \ No newline at end of file diff --git a/modules/generation_parameters_copypaste.py b/modules/generation_parameters_copypaste.py index a3448be9..bd7b0018 100644 --- a/modules/generation_parameters_copypaste.py +++ b/modules/generation_parameters_copypaste.py @@ -370,6 +370,14 @@ def connect_paste(button, paste_fields, input_comp, override_settings_component, prompt = file.read() params = parse_generation_parameters(prompt) + + # This sanitizes unsavory prompt words when copying from another image + # for my own sanity. This is not intended to be contributed to the main repo, + # it's just so I don't have to see anything I'm not interested in when batch + # reproducing images from civit.ai or elsewhere when working on loras + # todo: make this work with the callback instead of forcing it here, this can be an extension when I feel like putting it together :D + from modules import custom_statics + params = custom_statics.CustomStatics.mass_replace_strings(params) script_callbacks.infotext_pasted_callback(prompt, params) res = [] diff --git a/webui-user.bat b/webui-user.bat index e5a257be..1ba2116d 100644 --- a/webui-user.bat +++ b/webui-user.bat @@ -1,8 +1,8 @@ @echo off - +set TEMP=G:\SD-temp set PYTHON= set GIT= set VENV_DIR= -set COMMANDLINE_ARGS= +set COMMANDLINE_ARGS= --xformers call webui.bat From 8f3b02f09535f55d3673aa9ea589396b8614f799 Mon Sep 17 00:00:00 2001 From: JaredTherriault Date: Sun, 3 Sep 2023 13:31:42 -0700 Subject: [PATCH 2/3] Revert "Offloading custom work" This reverts commit f3d1631aab82d559294126a9230c979ef4c4e1d6. This work has been offloaded now into an extension called Prompt Control. --- modules/custom_statics.py | 29 ---------------------- modules/generation_parameters_copypaste.py | 8 ------ webui-user.bat | 4 +-- 3 files changed, 2 insertions(+), 39 deletions(-) delete mode 100644 modules/custom_statics.py diff --git a/modules/custom_statics.py b/modules/custom_statics.py deleted file mode 100644 index 207bd5fb..00000000 --- a/modules/custom_statics.py +++ /dev/null @@ -1,29 +0,0 @@ -import os -import gc -import re - -import modules.paths as paths - -class CustomStatics: - - @staticmethod - # loads a file with strings structured as below, on each line with a : between the search and replace strings, into a list - # search0:replace0 - # search string:replace string - # - # Then replaces all occurrences of the list's search strings with the list's replace strings in one go - def mass_replace_strings(input_string): - with open(os.path.join(paths.data_path, "custom_statics/Replacements.txt"), "r", encoding="utf8") as file: - replacements = file.readlines() - - replacement_dict = {} - for line in replacements: - search, replace = line.strip().split(":") - replacement_dict[search] = replace - - def replace(match_text): - return replacement_dict[match_text.group(0)] - - return re.sub('|'.join(r'\b%s\b' % re.escape(s) for s in replacement_dict.keys()), replace, str(input_string)) - - return str(geninfo) \ No newline at end of file diff --git a/modules/generation_parameters_copypaste.py b/modules/generation_parameters_copypaste.py index bd7b0018..a3448be9 100644 --- a/modules/generation_parameters_copypaste.py +++ b/modules/generation_parameters_copypaste.py @@ -370,14 +370,6 @@ def connect_paste(button, paste_fields, input_comp, override_settings_component, prompt = file.read() params = parse_generation_parameters(prompt) - - # This sanitizes unsavory prompt words when copying from another image - # for my own sanity. This is not intended to be contributed to the main repo, - # it's just so I don't have to see anything I'm not interested in when batch - # reproducing images from civit.ai or elsewhere when working on loras - # todo: make this work with the callback instead of forcing it here, this can be an extension when I feel like putting it together :D - from modules import custom_statics - params = custom_statics.CustomStatics.mass_replace_strings(params) script_callbacks.infotext_pasted_callback(prompt, params) res = [] diff --git a/webui-user.bat b/webui-user.bat index 1ba2116d..e5a257be 100644 --- a/webui-user.bat +++ b/webui-user.bat @@ -1,8 +1,8 @@ @echo off -set TEMP=G:\SD-temp + set PYTHON= set GIT= set VENV_DIR= -set COMMANDLINE_ARGS= --xformers +set COMMANDLINE_ARGS= call webui.bat From 022639a145751d61db1c144e5e657aa6481e2bc0 Mon Sep 17 00:00:00 2001 From: JaredTherriault Date: Mon, 4 Sep 2023 17:37:48 -0700 Subject: [PATCH 3/3] Load comments from gif images to gather geninfo from gif outputs --- modules/images.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/images.py b/modules/images.py index eb644733..8c6e862f 100644 --- a/modules/images.py +++ b/modules/images.py @@ -728,6 +728,8 @@ def read_info_from_image(image: Image.Image) -> tuple[str | None, dict]: if exif_comment: items['exif comment'] = exif_comment geninfo = exif_comment + elif "comment" in items: # for gif + geninfo = items["comment"].decode('utf8', errors="ignore") for field in IGNORED_INFO_KEYS: items.pop(field, None)