Fix division by zero when using an empty prompt

This commit is contained in:
Kyle Lacy 2022-09-22 17:15:28 -07:00
parent a1739a73b4
commit 5f22a72188
No known key found for this signature in database
GPG Key ID: 82616D2392FB6605

View File

@ -65,7 +65,7 @@ def split_weighted_subprompts(text, skip_normalize=False)->list:
if weight_sum == 0: if weight_sum == 0:
print( print(
"Warning: Subprompt weights add up to zero. Discarding and using even weights instead.") "Warning: Subprompt weights add up to zero. Discarding and using even weights instead.")
equal_weight = 1 / len(parsed_prompts) equal_weight = 1 / max(len(parsed_prompts), 1)
return [(x[0], equal_weight) for x in parsed_prompts] return [(x[0], equal_weight) for x in parsed_prompts]
return [(x[0], x[1] / weight_sum) for x in parsed_prompts] return [(x[0], x[1] / weight_sum) for x in parsed_prompts]