Select localization in session tab

This commit is contained in:
Touch-Night 2024-08-29 11:46:55 +08:00
parent 6148e634b6
commit 88c1829b35
4 changed files with 10 additions and 9 deletions

View File

@ -28,7 +28,6 @@ gradio = {}
persistent_interface_state = {}
localizations = {}
need_restart = False
lang = 'None'
# UI defaults
settings = {
@ -65,6 +64,7 @@ settings = {
'chat-instruct_command': 'Continue the chat dialogue below. Write a single reply for the character "<|character|>".\n\n<|prompt|>',
'autoload_model': False,
'default_extensions': [],
'localization': 'None',
}
default_settings = copy.deepcopy(settings)

View File

@ -245,7 +245,7 @@ def apply_interface_values(state, use_persistent=False):
return [state[k] if k in state else gr.update() for k in elements]
def save_settings(state, preset, extensions_list, show_controls, theme_state):
def save_settings(state, preset, extensions_list, localization, show_controls, theme_state):
output = copy.deepcopy(shared.settings)
exclude = ['name2', 'greeting', 'context', 'truncation_length', 'instruction_template_str']
for k in state:
@ -257,6 +257,7 @@ def save_settings(state, preset, extensions_list, show_controls, theme_state):
output['prompt-notebook'] = state['prompt_menu-notebook']
output['character'] = state['character_menu']
output['default_extensions'] = extensions_list
output['localization'] = localization
output['seed'] = int(output['seed'])
output['show_controls'] = show_controls
output['dark_theme'] = True if theme_state == 'dark' else False

View File

@ -25,8 +25,8 @@ def create_ui():
with gr.Column():
extension_name = gr.Textbox(lines=1, label='Install or update an extension', info='Enter the GitHub URL below and press Enter. For a list of extensions, see: https://github.com/oobabooga/text-generation-webui-extensions ⚠️ WARNING ⚠️ : extensions can execute arbitrary code. Make sure to inspect their source code before activating them.', interactive=not mu)
with gr.Row():
shared.gradio['localization_menu'] = gr.Dropdown(choices=utils.get_available_localizations(), value=lambda: shared.lang, label='Localization', elem_classes='slim-dropdown')
ui.create_refresh_button(shared.gradio['localization_menu'], lambda: None, lambda: {'choices': utils.get_available_localizations()}, 'refresh-button')
shared.gradio['localization_menu'] = gr.Dropdown(choices=utils.get_available_localizations(), value=shared.settings['localization'], label='Localization', elem_classes='slim-dropdown')
ui.create_refresh_button(shared.gradio['localization_menu'], lambda: None, lambda: {'choices': utils.get_available_localizations()}, 'refresh-button', interactive=not mu)
shared.gradio['download_localization'] = gr.Button(value='Download localization template', elem_id='download_localization')
extension_status = gr.Markdown()
@ -44,9 +44,8 @@ def create_ui():
shared.gradio['save_settings'].click(
ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then(
handle_save_settings, gradio('interface_state', 'preset_menu', 'extensions_menu', 'show_controls', 'theme_state'), gradio('save_contents', 'save_filename', 'save_root', 'file_saver'), show_progress=False)
handle_save_settings, gradio('interface_state', 'preset_menu', 'extensions_menu', 'localization_menu', 'show_controls', 'theme_state'), gradio('save_contents', 'save_filename', 'save_root', 'file_saver'), show_progress=False)
# Execute download_localization js function from localization.js
shared.gradio['download_localization'].click(
None, None, None, js=f'() => {{{ui.localization_js}; download_localization()}}')
@ -54,8 +53,9 @@ def create_ui():
ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state'))
def handle_save_settings(state, preset, extensions, show_controls, theme):
contents = ui.save_settings(state, preset, extensions, show_controls, theme)
def handle_save_settings(state, preset, extensions, localization, show_controls, theme):
contents = ui.save_settings(state, preset, extensions, localization, show_controls, theme)
return [
contents,
"settings.yaml",

View File

@ -154,7 +154,7 @@ def create_interface():
if ({str(shared.settings['dark_theme']).lower()}) {{
document.getElementsByTagName('body')[0].classList.add('dark');
}}
{localization.localization_js(shared.lang)}
{localization.localization_js(shared.settings['localization'])}
{js}
{ui.localization_js}
{ui.show_controls_js}