diff --git a/css/html_instruct_style.css b/css/html_instruct_style.css index dcc19c29..fcd0558f 100644 --- a/css/html_instruct_style.css +++ b/css/html_instruct_style.css @@ -48,12 +48,14 @@ .chat .user-message { background: #f4f4f4; padding: 1.5rem 1rem; + padding-bottom: 2rem; border-radius: 0; border-bottom-right-radius: 0; } .chat .assistant-message { padding: 1.5rem 1rem; + padding-bottom: 2rem; border-radius: 0; border: 0; } diff --git a/css/main.css b/css/main.css index 9d99a876..48c6727a 100644 --- a/css/main.css +++ b/css/main.css @@ -1142,7 +1142,6 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { } .dark svg { - fill: white; color: white; } @@ -1221,3 +1220,55 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { background: var(--light-theme-gray); } } + +/* ---------------------------------------------- + Copy button for chat messages +---------------------------------------------- */ +.message .text, +.message .text-you, +.message .text-bot, +.user-message .text, +.assistant-message .text { + position: relative; +} + +.message, .user-message, .assistant-message { + position: relative; +} + +.copy-button { + position: absolute; + bottom: -23px; + left: 0; + padding: 0; + border: none; + border-radius: 3px; + cursor: pointer; + opacity: 0; + display: flex; + align-items: center; + transition: opacity 0.2s; +} + +.message:hover .copy-button, +.user-message:hover .copy-button, +.assistant-message:hover .copy-button { + opacity: 1; +} + +.copy-button svg { + stroke: rgb(156 163 175); + transition: stroke 0.2s; +} + +.copy-button:hover svg { + stroke: rgb(107 114 128); +} + +.dark .copy-button svg { + stroke: rgb(156 163 175); +} + +.dark .copy-button:hover svg { + stroke: rgb(209 213 219); +} diff --git a/modules/block_requests.py b/modules/block_requests.py index 35f983cf..29fc6633 100644 --- a/modules/block_requests.py +++ b/modules/block_requests.py @@ -3,7 +3,7 @@ import io import requests -from modules import shared +from modules import shared, ui from modules.logging_colors import logger original_open = open @@ -58,6 +58,7 @@ def my_open(*args, **kwargs): '\n ' f'\n ' '\n ' + f'\n ' '\n ' ) diff --git a/modules/html_generator.py b/modules/html_generator.py index e3550ed5..b565c63a 100644 --- a/modules/html_generator.py +++ b/modules/html_generator.py @@ -292,24 +292,34 @@ def get_image_cache(path): return image_cache[path][1] +copy_svg = '''''' +copy_button = f'' + def generate_instruct_html(history): output = f'
' - 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 + for i in range(len(history['visible'])): + row_visible = history['visible'][i] + row_internal = history['internal'][i] + converted_visible = [convert_to_markdown_wrapped(entry, use_cache=i != len(history['visible']) - 1) for entry in row_visible] + + if converted_visible[0]: # Don't display empty user messages output += ( - f'
' + f'
' f'
' - f'
{row[0]}
' + f'
{converted_visible[0]}
' + f'{copy_button}' f'
' f'
' ) output += ( - f'
' + f'
' f'
' - f'
{row[1]}
' + f'
{converted_visible[1]}
' + f'{copy_button}' f'
' f'
' ) @@ -332,26 +342,32 @@ def generate_cai_chat_html(history, name1, name2, style, character, reset_cache= 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] + for i in range(len(history['visible'])): + row_visible = history['visible'][i] + row_internal = history['internal'][i] + converted_visible = [convert_to_markdown_wrapped(entry, use_cache=i != len(history['visible']) - 1) for entry in row_visible] - if row[0]: # Don't display empty user messages + if converted_visible[0]: # Don't display empty user messages output += ( - f'
' + f'
' f'
{img_me}
' f'
' f'
{name1}
' - f'
{row[0]}
' + f'
{converted_visible[0]}
' + f'{copy_button}' f'
' f'
' ) output += ( - f'
' + f'
' f'
{img_bot}
' f'
' f'
{name2}
' - f'
{row[1]}
' + f'
{converted_visible[1]}
' + f'{copy_button}' f'
' f'
' ) @@ -363,22 +379,28 @@ def generate_cai_chat_html(history, name1, name2, style, character, reset_cache= def generate_chat_html(history, name1, name2, reset_cache=False): output = f'
' - for i, _row in enumerate(history): - row = [convert_to_markdown_wrapped(entry, use_cache=i != len(history) - 1) for entry in _row] + for i in range(len(history['visible'])): + row_visible = history['visible'][i] + row_internal = history['internal'][i] + converted_visible = [convert_to_markdown_wrapped(entry, use_cache=i != len(history['visible']) - 1) for entry in row_visible] - if row[0]: # Don't display empty user messages + if converted_visible[0]: # Don't display empty user messages output += ( - f'
' + f'
' f'
' - f'
{row[0]}
' + f'
{converted_visible[0]}
' + f'{copy_button}' f'
' f'
' ) output += ( - f'
' + f'
' f'
' - f'
{row[1]}
' + f'
{converted_visible[1]}
' + f'{copy_button}' f'
' f'
' ) @@ -389,8 +411,8 @@ def generate_chat_html(history, name1, name2, reset_cache=False): def chat_html_wrapper(history, name1, name2, mode, style, character, reset_cache=False): if mode == 'instruct': - return generate_instruct_html(history['visible']) + return generate_instruct_html(history) elif style == 'wpp': - return generate_chat_html(history['visible'], name1, name2) + return generate_chat_html(history, name1, name2) else: - return generate_cai_chat_html(history['visible'], name1, name2, style, character, reset_cache) + return generate_cai_chat_html(history, name1, name2, style, character, reset_cache) diff --git a/modules/ui.py b/modules/ui.py index 4f7ee785..df948a14 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -19,6 +19,8 @@ with open(Path(__file__).resolve().parent / '../css/highlightjs/highlightjs-copy css += f.read() with open(Path(__file__).resolve().parent / '../js/main.js', 'r') as f: js = f.read() +with open(Path(__file__).resolve().parent / '../js/global_scope_js.js', 'r') as f: + global_scope_js = f.read() with open(Path(__file__).resolve().parent / '../js/save_files.js', 'r') as f: save_files_js = f.read() with open(Path(__file__).resolve().parent / '../js/switch_tabs.js', 'r') as f: