Merge pull request #4789 from awsr/fix-counter

Fix token estimate counter
This commit is contained in:
Vladimir Mandic
2026-04-23 13:25:23 +02:00
committed by GitHub
+2 -1
View File
@@ -507,9 +507,10 @@ def update_token_counter(text: str):
return gr.update(value=f"<span class='gr-box gr-text-input'>??/{max_length}</span>", visible=True)
token_counts = [len(group) - int(has_bos_token) - int(has_eos_token) for group in ids]
token_counts = [tc for tc in token_counts if tc > 0]
if len(token_counts) > 1:
visible = True
count_formatted = f"{token_counts}/{sum(token_counts)}"
count_formatted = f"{token_counts} {sum(token_counts)}"
elif len(token_counts) == 1 and token_counts[0] > 0:
visible = True
count_formatted = str(token_counts[0])