From 7c0a17962d1404d181d69319bdcb6d60f0dc3c39 Mon Sep 17 00:00:00 2001 From: Lounger <4087076+TheLounger@users.noreply.github.com> Date: Mon, 4 Dec 2023 02:45:50 +0100 Subject: [PATCH 1/7] Gallery improvements (#4789) --- extensions/gallery/script.js | 7 +++++++ extensions/gallery/script.py | 34 +++++++++++++++++++++++++++++----- modules/chat.py | 8 ++++---- modules/html_generator.py | 10 +++++----- modules/shared.py | 2 ++ modules/ui_chat.py | 4 ++-- settings-template.yaml | 2 ++ 7 files changed, 51 insertions(+), 16 deletions(-) diff --git a/extensions/gallery/script.js b/extensions/gallery/script.js index 4ff23afc..9717aa67 100644 --- a/extensions/gallery/script.js +++ b/extensions/gallery/script.js @@ -5,6 +5,13 @@ let extensions_block = document.getElementById('extensions'); let extensions_block_size = extensions_block.childNodes.length; let gallery_only = (extensions_block_size == 5); +function gotoFirstPage() { + const firstPageButton = gallery_element.querySelector('.paginate > button'); + if (firstPageButton) { + firstPageButton.click(); + } +} + document.querySelector('.header_bar').addEventListener('click', function(event) { if (event.target.tagName === 'BUTTON') { const buttonText = event.target.textContent.trim(); diff --git a/extensions/gallery/script.py b/extensions/gallery/script.py index efe96ba9..d520abb5 100644 --- a/extensions/gallery/script.py +++ b/extensions/gallery/script.py @@ -3,11 +3,17 @@ from pathlib import Path import gradio as gr from modules.html_generator import get_image_cache -from modules.shared import gradio +from modules.shared import gradio, settings + +cards = [] def generate_css(): css = """ + .highlighted-border { + border-color: rgb(249, 115, 22) !important; + } + .character-gallery > .gallery { margin: 1rem 0; display: grid !important; @@ -58,6 +64,7 @@ def generate_css(): def generate_html(): + global cards cards = [] # Iterate through files in image folder for file in sorted(Path("characters").glob("*")): @@ -78,6 +85,14 @@ def generate_html(): return cards +def filter_cards(filter_str=''): + if filter_str == '': + return cards + + filter_upper = filter_str.upper() + return [k for k in cards if filter_upper in k[1].upper()] + + def select_character(evt: gr.SelectData): return (evt.value[1]) @@ -88,16 +103,25 @@ def custom_js(): def ui(): - with gr.Accordion("Character gallery", open=False, elem_id='gallery-extension'): - update = gr.Button("Refresh") + with gr.Accordion("Character gallery", open=settings["gallery-open"], elem_id='gallery-extension'): gr.HTML(value="") + with gr.Row(): + filter_box = gr.Textbox(label='', placeholder='Filter', lines=1, max_lines=1, container=False, elem_id='gallery-filter-box') + gr.ClearButton(filter_box, value='🗑️', elem_classes='refresh-button') + update = gr.Button("Refresh", elem_classes='refresh-button') gallery = gr.Dataset( components=[gr.HTML(visible=False)], label="", samples=generate_html(), elem_classes=["character-gallery"], - samples_per_page=50 + samples_per_page=settings["gallery-items_per_page"] ) - update.click(generate_html, [], gallery) + filter_box.change(lambda: None, None, None, _js=f'() => {{{custom_js()}; gotoFirstPage()}}').success( + filter_cards, filter_box, gallery).then( + lambda x: gr.update(elem_classes='highlighted-border' if x != '' else ''), filter_box, filter_box, show_progress=False) + + update.click(generate_html, [], None).success( + filter_cards, filter_box, gallery) + gallery.select(select_character, None, gradio['character_menu']) diff --git a/modules/chat.py b/modules/chat.py index 22b5bf9a..e126a428 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -281,7 +281,7 @@ def chatbot_wrapper(text, state, regenerate=False, _continue=False, loading_mess def impersonate_wrapper(text, state): - static_output = chat_html_wrapper(state['history'], state['name1'], state['name2'], state['mode'], state['chat_style']) + static_output = chat_html_wrapper(state['history'], state['name1'], state['name2'], state['mode'], state['chat_style'], state['character_menu']) if shared.model_name == 'None' or shared.model is None: logger.error("No model is loaded! Select one in the Model tab.") @@ -340,7 +340,7 @@ def generate_chat_reply_wrapper(text, state, regenerate=False, _continue=False): send_dummy_reply(state['start_with'], state) for i, history in enumerate(generate_chat_reply(text, state, regenerate, _continue, loading_message=True)): - yield chat_html_wrapper(history, state['name1'], state['name2'], state['mode'], state['chat_style']), history + yield chat_html_wrapper(history, state['name1'], state['name2'], state['mode'], state['chat_style'], state['character_menu']), history def remove_last_message(history): @@ -390,8 +390,8 @@ def send_dummy_reply(text, state): return history -def redraw_html(history, name1, name2, mode, style, reset_cache=False): - return chat_html_wrapper(history, name1, name2, mode, style, reset_cache=reset_cache) +def redraw_html(history, name1, name2, mode, style, character, reset_cache=False): + return chat_html_wrapper(history, name1, name2, mode, style, character, reset_cache=reset_cache) def start_new_chat(state): diff --git a/modules/html_generator.py b/modules/html_generator.py index 2a6509b3..789cf639 100644 --- a/modules/html_generator.py +++ b/modules/html_generator.py @@ -221,11 +221,11 @@ def generate_instruct_html(history): return output -def generate_cai_chat_html(history, name1, name2, style, reset_cache=False): +def generate_cai_chat_html(history, name1, name2, style, character, reset_cache=False): output = f'
' - # We use ?name2 and ?time.time() to force the browser to reset caches - img_bot = f'' if Path("cache/pfp_character_thumb.png").exists() else '' + # 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 '' for i, _row in enumerate(history): @@ -299,10 +299,10 @@ def generate_chat_html(history, name1, name2, reset_cache=False): return output -def chat_html_wrapper(history, name1, name2, mode, style, 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']) elif style == 'wpp': return generate_chat_html(history['visible'], name1, name2) else: - return generate_cai_chat_html(history['visible'], name1, name2, style, reset_cache) + return generate_cai_chat_html(history['visible'], name1, name2, style, character, reset_cache) diff --git a/modules/shared.py b/modules/shared.py index 3ef9e4fa..66703a5e 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -58,6 +58,8 @@ settings = { 'custom_system_message': '', 'chat-instruct_command': 'Continue the chat dialogue below. Write a single reply for the character "<|character|>".\n\n<|prompt|>', 'autoload_model': False, + 'gallery-items_per_page': 50, + 'gallery-open': False, 'default_extensions': ['gallery'], } diff --git a/modules/ui_chat.py b/modules/ui_chat.py index 40c8d71c..83073dcc 100644 --- a/modules/ui_chat.py +++ b/modules/ui_chat.py @@ -11,7 +11,7 @@ from modules.text_generation import stop_everything_event from modules.utils import gradio inputs = ('Chat input', 'interface_state') -reload_arr = ('history', 'name1', 'name2', 'mode', 'chat_style') +reload_arr = ('history', 'name1', 'name2', 'mode', 'chat_style', 'character_menu') clear_arr = ('delete_chat-confirm', 'delete_chat', 'delete_chat-cancel') @@ -25,7 +25,7 @@ def create_ui(): with gr.Tab('Chat', elem_id='chat-tab', elem_classes=("old-ui" if shared.args.chat_buttons else None)): with gr.Row(): with gr.Column(elem_id='chat-col'): - shared.gradio['display'] = gr.HTML(value=chat_html_wrapper({'internal': [], 'visible': []}, '', '', 'chat', 'cai-chat')) + shared.gradio['display'] = gr.HTML(value=chat_html_wrapper({'internal': [], 'visible': []}, '', '', 'chat', 'cai-chat', '')) with gr.Row(elem_id="chat-input-row"): with gr.Column(scale=1, elem_id='gr-hover-container'): diff --git a/settings-template.yaml b/settings-template.yaml index 12eb38f8..4ca84223 100644 --- a/settings-template.yaml +++ b/settings-template.yaml @@ -30,5 +30,7 @@ chat-instruct_command: |- <|prompt|> autoload_model: false +gallery-items_per_page: 50 +gallery-open: false default_extensions: - gallery From 06cc9a85f79c585a5eb3dad9b8b82f3281ba1f52 Mon Sep 17 00:00:00 2001 From: Ikko Eltociear Ashimine Date: Mon, 4 Dec 2023 10:46:34 +0900 Subject: [PATCH 2/7] README: minor typo fix (#4793) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d08a9c57..22f2d9f9 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ conda install -y -c "nvidia/label/cuda-11.8.0" cuda-runtime ##### Manual install -The requirments*.txt above contain various precompiled wheels. If you wish to compile things manually, or if you need to because no suitable wheels are available for your hardware, you can use `requirements_nowheels.txt` and then install your desired loaders manually. +The requirements*.txt above contain various precompiled wheels. If you wish to compile things manually, or if you need to because no suitable wheels are available for your hardware, you can use `requirements_nowheels.txt` and then install your desired loaders manually. ### Alternative: Docker From 2e83844f35dd754fcfabb6237c02d2eef0330147 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 3 Dec 2023 22:50:10 -0300 Subject: [PATCH 3/7] Bump safetensors from 0.4.0 to 0.4.1 (#4750) --- requirements.txt | 2 +- requirements_amd.txt | 2 +- requirements_amd_noavx2.txt | 2 +- requirements_apple_intel.txt | 2 +- requirements_apple_silicon.txt | 2 +- requirements_cpu_only.txt | 2 +- requirements_cpu_only_noavx2.txt | 2 +- requirements_noavx2.txt | 2 +- requirements_nowheels.txt | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index 2cfc6a3a..3d25bfd7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ peft==0.6.* Pillow>=9.5.0 pyyaml requests -safetensors==0.4.0 +safetensors==0.4.1 scipy sentencepiece tensorboard diff --git a/requirements_amd.txt b/requirements_amd.txt index ebaff902..e27f3016 100644 --- a/requirements_amd.txt +++ b/requirements_amd.txt @@ -12,7 +12,7 @@ peft==0.6.* Pillow>=9.5.0 pyyaml requests -safetensors==0.4.0 +safetensors==0.4.1 scipy sentencepiece tensorboard diff --git a/requirements_amd_noavx2.txt b/requirements_amd_noavx2.txt index ed0c4167..f78832e3 100644 --- a/requirements_amd_noavx2.txt +++ b/requirements_amd_noavx2.txt @@ -12,7 +12,7 @@ peft==0.6.* Pillow>=9.5.0 pyyaml requests -safetensors==0.4.0 +safetensors==0.4.1 scipy sentencepiece tensorboard diff --git a/requirements_apple_intel.txt b/requirements_apple_intel.txt index 9a290c51..febb0609 100644 --- a/requirements_apple_intel.txt +++ b/requirements_apple_intel.txt @@ -12,7 +12,7 @@ peft==0.6.* Pillow>=9.5.0 pyyaml requests -safetensors==0.4.0 +safetensors==0.4.1 scipy sentencepiece tensorboard diff --git a/requirements_apple_silicon.txt b/requirements_apple_silicon.txt index 3aa0a106..2997c98f 100644 --- a/requirements_apple_silicon.txt +++ b/requirements_apple_silicon.txt @@ -12,7 +12,7 @@ peft==0.6.* Pillow>=9.5.0 pyyaml requests -safetensors==0.4.0 +safetensors==0.4.1 scipy sentencepiece tensorboard diff --git a/requirements_cpu_only.txt b/requirements_cpu_only.txt index 340276f8..ec0e84ff 100644 --- a/requirements_cpu_only.txt +++ b/requirements_cpu_only.txt @@ -12,7 +12,7 @@ peft==0.6.* Pillow>=9.5.0 pyyaml requests -safetensors==0.4.0 +safetensors==0.4.1 scipy sentencepiece tensorboard diff --git a/requirements_cpu_only_noavx2.txt b/requirements_cpu_only_noavx2.txt index f2812229..02e51844 100644 --- a/requirements_cpu_only_noavx2.txt +++ b/requirements_cpu_only_noavx2.txt @@ -12,7 +12,7 @@ peft==0.6.* Pillow>=9.5.0 pyyaml requests -safetensors==0.4.0 +safetensors==0.4.1 scipy sentencepiece tensorboard diff --git a/requirements_noavx2.txt b/requirements_noavx2.txt index 3ccc9363..eeff8eb7 100644 --- a/requirements_noavx2.txt +++ b/requirements_noavx2.txt @@ -12,7 +12,7 @@ peft==0.6.* Pillow>=9.5.0 pyyaml requests -safetensors==0.4.0 +safetensors==0.4.1 scipy sentencepiece tensorboard diff --git a/requirements_nowheels.txt b/requirements_nowheels.txt index 48829427..d08204fd 100644 --- a/requirements_nowheels.txt +++ b/requirements_nowheels.txt @@ -12,7 +12,7 @@ peft==0.6.* Pillow>=9.5.0 pyyaml requests -safetensors==0.4.0 +safetensors==0.4.1 scipy sentencepiece tensorboard From 0bfd5090be93bd88b736902419d5c7cca08190f8 Mon Sep 17 00:00:00 2001 From: Song Fuchang Date: Mon, 4 Dec 2023 09:51:18 +0800 Subject: [PATCH 4/7] Import accelerate very early to make Intel GPU happy (#4704) --- server.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server.py b/server.py index cdd82e1d..d4c4c8e3 100644 --- a/server.py +++ b/server.py @@ -1,3 +1,5 @@ +import accelerate; + import os import warnings From 427a1655976f638e34a5e350a0ce32b1e299389c Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 4 Dec 2023 07:21:56 -0800 Subject: [PATCH 5/7] Bump TTS version in coqui_tts --- extensions/coqui_tts/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/coqui_tts/requirements.txt b/extensions/coqui_tts/requirements.txt index edb3670c..747f99a0 100644 --- a/extensions/coqui_tts/requirements.txt +++ b/extensions/coqui_tts/requirements.txt @@ -1 +1 @@ -TTS==0.20.* \ No newline at end of file +TTS==0.21.* \ No newline at end of file From 0931ed501b1a0dfd62534b452afb02256dfc57cc Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 4 Dec 2023 07:25:18 -0800 Subject: [PATCH 6/7] Minor changes --- extensions/gallery/script.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/gallery/script.py b/extensions/gallery/script.py index d520abb5..739d5841 100644 --- a/extensions/gallery/script.py +++ b/extensions/gallery/script.py @@ -5,6 +5,7 @@ import gradio as gr from modules.html_generator import get_image_cache from modules.shared import gradio, settings + cards = [] @@ -109,6 +110,7 @@ def ui(): filter_box = gr.Textbox(label='', placeholder='Filter', lines=1, max_lines=1, container=False, elem_id='gallery-filter-box') gr.ClearButton(filter_box, value='🗑️', elem_classes='refresh-button') update = gr.Button("Refresh", elem_classes='refresh-button') + gallery = gr.Dataset( components=[gr.HTML(visible=False)], label="", From 3f993280e4670ffd6b97e47c7e208f3d9963962f Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 4 Dec 2023 07:27:44 -0800 Subject: [PATCH 7/7] Minor changes --- server.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server.py b/server.py index d4c4c8e3..ae4eceb9 100644 --- a/server.py +++ b/server.py @@ -1,8 +1,7 @@ -import accelerate; - import os import warnings +import accelerate # This early import makes Intel GPUs happy import modules.one_click_installer_check from modules.block_requests import OpenMonkeyPatch, RequestBlocker from modules.logging_colors import logger