forked from AUTOMATIC1111/stable-diffusion-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-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.
- Loading branch information
1 parent
c9c8485
commit f3d1631
Showing
3 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |