From 0e673a7a4278deaedb3513b4e406cdcc45b19b4e Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Sat, 4 Jan 2025 11:40:24 -0800 Subject: [PATCH] UI: reduce the size of HTML sent to the UI during streaming --- modules/html_generator.py | 130 +++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 72 deletions(-) diff --git a/modules/html_generator.py b/modules/html_generator.py index e61fc558..1f12d77a 100644 --- a/modules/html_generator.py +++ b/modules/html_generator.py @@ -268,29 +268,24 @@ def generate_instruct_html(history): for i, _row in enumerate(history): row = [convert_to_markdown_wrapped(entry, use_cache=i != len(history) - 1) for entry in _row] - if row[0]: # don't display empty user messages - output += f""" -
-
-
- {row[0]} -
-
-
- """ + if row[0]: # Don't display empty user messages + output += ( + f'
' + f'
' + f'
{row[0]}
' + f'
' + f'
' + ) - output += f""" -
-
-
- {row[1]} -
-
-
- """ + output += ( + f'
' + f'
' + f'
{row[1]}
' + f'
' + f'
' + ) output += "" - return output @@ -298,44 +293,39 @@ def generate_cai_chat_html(history, name1, name2, style, character, reset_cache= output = f'
' # We use ?character and ?time.time() to force the browser to reset caches - img_bot = f'' if Path("cache/pfp_character_thumb.png").exists() else '' - img_me = f'' if Path("cache/pfp_me.png").exists() else '' + img_bot = ( + f'' + if Path("cache/pfp_character_thumb.png").exists() else '' + ) + + img_me = ( + f'' + if Path("cache/pfp_me.png").exists() else '' + ) for i, _row in enumerate(history): row = [convert_to_markdown_wrapped(entry, use_cache=i != len(history) - 1) for entry in _row] - if row[0]: # don't display empty user messages - output += f""" -
-
- {img_me} -
-
-
- {name1} -
-
- {row[0]} -
-
-
- """ + if row[0]: # Don't display empty user messages + output += ( + f'
' + f'
{img_me}
' + f'
' + f'
{name1}
' + f'
{row[0]}
' + f'
' + f'
' + ) - output += f""" -
-
- {img_bot} -
-
-
- {name2} -
-
- {row[1]} -
-
-
- """ + output += ( + f'
' + f'
{img_bot}
' + f'
' + f'
{name2}
' + f'
{row[1]}
' + f'
' + f'
' + ) output += "
" return output @@ -347,26 +337,22 @@ def generate_chat_html(history, name1, name2, reset_cache=False): for i, _row in enumerate(history): row = [convert_to_markdown_wrapped(entry, use_cache=i != len(history) - 1) for entry in _row] - if row[0]: # don't display empty user messages - output += f""" -
-
-
- {row[0]} -
-
-
- """ + if row[0]: # Don't display empty user messages + output += ( + f'
' + f'
' + f'
{row[0]}
' + f'
' + f'
' + ) - output += f""" -
-
-
- {row[1]} -
-
-
- """ + output += ( + f'
' + f'
' + f'
{row[1]}
' + f'
' + f'
' + ) output += "" return output