XY plot prompt order simplify logic

This commit is contained in:
DoTheSneedful 2022-10-04 01:07:36 -04:00 committed by AUTOMATIC1111
parent 1a6d40db35
commit 56371153b5

View File

@ -38,15 +38,21 @@ def apply_order(p, x, xs):
token_order.sort(key=lambda t: t[0]) token_order.sort(key=lambda t: t[0])
search_from_pos = 0 prompt_parts = []
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 # Split the prompt up, taking out the tokens
pos = search_from_pos + p.prompt[search_from_pos:].find(old_token) for _, token in token_order:
if original_pos >= 0: n = p.prompt.find(token)
# Avoid trying to replace what was just replaced by searching later in the prompt string prompt_parts.append(p.prompt[0:n])
p.prompt = p.prompt[0:search_from_pos] + p.prompt[search_from_pos:].replace(old_token, x[idx], 1) p.prompt = p.prompt[n + len(token):]
# Rebuild the prompt with the tokens in the order we want
prompt_tmp = ""
for idx, part in enumerate(prompt_parts):
prompt_tmp += part
prompt_tmp += x[idx]
p.prompt = prompt_tmp + p.prompt
search_from_pos = pos + len(x[idx])
samplers_dict = {} samplers_dict = {}
for i, sampler in enumerate(modules.sd_samplers.samplers): for i, sampler in enumerate(modules.sd_samplers.samplers):