aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoTheSneedful <DoTheSneedful@outlook.com>2022-10-04 00:18:15 -0400
committerAUTOMATIC1111 <16777216c@gmail.com>2022-10-04 08:56:01 +0300
commit1a6d40db35656083d5bf9d3a3430b45fda4e85eb (patch)
tree39e28dd9e4fb1c357ef587cda1140cb4864ba69d
parent1c5604791da7e57f40880698666b6617a1754c65 (diff)
Fix token ordering in prompt order XY plot
-rw-r--r--scripts/xy_grid.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/scripts/xy_grid.py b/scripts/xy_grid.py
index 044c30e6..5bcd3921 100644
--- a/scripts/xy_grid.py
+++ b/scripts/xy_grid.py
@@ -32,24 +32,21 @@ def apply_prompt(p, x, xs):
def apply_order(p, x, xs):
token_order = []
- # Initally grab the tokens from the prompt so they can be later be replaced in order of earliest seen in the prompt
+ # Initally grab the tokens from the prompt so they can be be replaced in order of earliest seen
for token in x:
token_order.append((p.prompt.find(token), token))
token_order.sort(key=lambda t: t[0])
search_from_pos = 0
- for idx, token in enumerate(x):
- original_pos, old_token = token_order[idx]
-
+ for idx, (original_pos, old_token) in enumerate(token_order):
# Get position of the token again as it will likely change as tokens are being replaced
- pos = p.prompt.find(old_token)
+ pos = search_from_pos + p.prompt[search_from_pos:].find(old_token)
if original_pos >= 0:
# Avoid trying to replace what was just replaced by searching later in the prompt string
- p.prompt = p.prompt[0:search_from_pos] + p.prompt[search_from_pos:].replace(old_token, token, 1)
-
- search_from_pos = pos + len(token)
+ p.prompt = p.prompt[0:search_from_pos] + p.prompt[search_from_pos:].replace(old_token, x[idx], 1)
+ search_from_pos = pos + len(x[idx])
samplers_dict = {}
for i, sampler in enumerate(modules.sd_samplers.samplers):