diff options
author | AUTOMATIC <16777216c@gmail.com> | 2022-10-04 11:35:12 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2022-10-04 11:35:12 +0000 |
commit | d5bba20a58f43a9f984bb67b4e17f48661f6b818 (patch) | |
tree | 086854783617cafb1e0b5aa6cda6873e142930fc | |
parent | b7f3996982507c213cad0c9789e878b37a9a5816 (diff) | |
download | stable-diffusion-webui-gfx803-d5bba20a58f43a9f984bb67b4e17f48661f6b818.tar.gz stable-diffusion-webui-gfx803-d5bba20a58f43a9f984bb67b4e17f48661f6b818.tar.bz2 stable-diffusion-webui-gfx803-d5bba20a58f43a9f984bb67b4e17f48661f6b818.zip |
ignore errors in parse for purposes of token counting for #1564
-rw-r--r-- | modules/ui.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/modules/ui.py b/modules/ui.py index 55f7aa95..20dc8c37 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -386,14 +386,22 @@ def connect_reuse_seed(seed: gr.Number, reuse_seed: gr.Button, generation_info: outputs=[seed, dummy_component]
)
+
def update_token_counter(text, steps):
- prompt_schedules = get_learned_conditioning_prompt_schedules([text], steps)
+ try:
+ prompt_schedules = get_learned_conditioning_prompt_schedules([text], steps)
+ except Exception:
+ # a parsing error can happen here during typing, and we don't want to bother the user with
+ # messages related to it in console
+ prompt_schedules = [[[steps, text]]]
+
flat_prompts = reduce(lambda list1, list2: list1+list2, prompt_schedules)
- prompts = [prompt_text for step,prompt_text in flat_prompts]
+ prompts = [prompt_text for step, prompt_text in flat_prompts]
tokens, token_count, max_length = max([model_hijack.tokenize(prompt) for prompt in prompts], key=lambda args: args[1])
style_class = ' class="red"' if (token_count > max_length) else ""
return f"<span {style_class}>{token_count}/{max_length}</span>"
+
def create_toprow(is_img2img):
id_part = "img2img" if is_img2img else "txt2img"
|