From e1525c88a2e71fdb3a2853516b0ff75c7804cedc Mon Sep 17 00:00:00 2001 From: AIrjen Date: Sat, 26 Oct 2024 15:21:21 +0200 Subject: [PATCH] Update build_dynamic_prompt.py fix for possibly empty lists --- build_dynamic_prompt.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/build_dynamic_prompt.py b/build_dynamic_prompt.py index 70d5c54..22afd05 100644 --- a/build_dynamic_prompt.py +++ b/build_dynamic_prompt.py @@ -3333,7 +3333,11 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all for i in range(len(completeprompt_list) - len("-heshe-") + 1): if "".join(completeprompt_list[i:i+len("-heshe-")]) == "-heshe-": # Replace -heshe- with a value from the shuffled list - replacement = samehumanreplacementlist.pop() + if(samehumanreplacementlist): + replacement = samehumanreplacementlist.pop() + else: + replacement = "-heshe-" + completeprompt_list[i:i+len("-heshe-")] = replacement # Convert the list back to a string @@ -3350,7 +3354,11 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all for i in range(len(completeprompt_list) - len("-heshe-") + 1): if "".join(completeprompt_list[i:i+len("-heshe-")]) == "-heshe-": # Replace -heshe- with a value from the shuffled list - replacement = sameobjectreplacementlist.pop() + if(sameobjectreplacementlist): + replacement = sameobjectreplacementlist.pop() + else: + replacement = "-heshe-" + completeprompt_list[i:i+len("-heshe-")] = replacement # Convert the list back to a string completeprompt = "".join(completeprompt_list) @@ -3431,7 +3439,11 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all for i in range(len(completeprompt_list) - len("-color-") + 1): if "".join(completeprompt_list[i:i+len("-color-")]) == "-color-": # Replace -heshe- with a value from the shuffled list - replacement = colorreplacementlist.pop() + if(colorreplacementlist): + replacement = colorreplacementlist.pop() + else: + replacement = "-color-" + completeprompt_list[i:i+len("-color-")] = replacement # Convert the list back to a string @@ -3451,7 +3463,11 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all for i in range(len(completeprompt_list) - len("-material-") + 1): if "".join(completeprompt_list[i:i+len("-material-")]) == "-material-": # Replace -heshe- with a value from the shuffled list - replacement = materialreplacementlist.pop() + if(materialreplacementlist): + replacement = materialreplacementlist.pop() + else: + replacement = "-material-" + completeprompt_list[i:i+len("-material-")] = replacement # Convert the list back to a string