Last active
April 25, 2023 00:45
-
-
Save opparco/0e4412bb5c320d9da245344a3202888a to your computer and use it in GitHub Desktop.
Prompt S/R for LoRA and LyCORIS arguments
This file contains hidden or 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
diff --git a/scripts/xyz_grid.py b/scripts/xyz_grid.py | |
index 3895a795..a5765c3a 100644 | |
--- a/scripts/xyz_grid.py | |
+++ b/scripts/xyz_grid.py | |
@@ -36,11 +36,24 @@ def apply_field(field): | |
def apply_prompt(p, x, xs): | |
- if xs[0] not in p.prompt and xs[0] not in p.negative_prompt: | |
- raise RuntimeError(f"Prompt S/R did not find {xs[0]} in prompt or negative prompt.") | |
+ string = xs[0] | |
+ if x == string: | |
+ return | |
- p.prompt = p.prompt.replace(xs[0], x) | |
- p.negative_prompt = p.negative_prompt.replace(xs[0], x) | |
+ if string not in p.prompt and string not in p.negative_prompt: | |
+ if string.find('?') == -1: | |
+ raise RuntimeError(f"Prompt S/R did not find {string} in prompt or negative prompt.") | |
+ | |
+ repl = string.replace('?', x) | |
+ pattern = re.compile(re.escape(string).replace(r'\?', r'.+?')) | |
+ | |
+ # lora S/R | |
+ p.prompt = pattern.sub(repl, p.prompt) | |
+ p.negative_prompt = pattern.sub(repl, p.negative_prompt) | |
+ else: | |
+ # prompt S/R | |
+ p.prompt = p.prompt.replace(string, x) | |
+ p.negative_prompt = p.negative_prompt.replace(string, x) | |
def apply_order(p, x, xs): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for LoRA
for LoRA Block Weight
for LyCORIS
for LyCORIS + LoRA Block Weight