Merge the Default and Notebook tabs into a single Notebook tab (#7078)

This commit is contained in:
oobabooga 2025-06-16 13:19:29 -03:00 committed by GitHub
parent db67d69ddc
commit de24b3bb31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 46 additions and 12 deletions

View file

@ -11,6 +11,7 @@ def create_ui():
with gr.Column():
gr.Markdown("## Settings")
shared.gradio['toggle_dark_mode'] = gr.Button('Toggle light/dark theme 💡', elem_classes='refresh-button')
shared.gradio['show_two_notebook_columns'] = gr.Checkbox(label='Show two columns in the Notebook tab', value=shared.settings['show_two_notebook_columns'])
shared.gradio['paste_to_attachment'] = gr.Checkbox(label='Turn long pasted text into attachments in the Chat tab', value=shared.settings['paste_to_attachment'], elem_id='paste_to_attachment')
shared.gradio['include_past_attachments'] = gr.Checkbox(label='Include attachments/search results from previous messages in the chat prompt', value=shared.settings['include_past_attachments'])
@ -34,6 +35,12 @@ def create_ui():
lambda x: 'dark' if x == 'light' else 'light', gradio('theme_state'), gradio('theme_state')).then(
None, None, None, js=f'() => {{{ui.dark_theme_js}; toggleDarkMode(); localStorage.setItem("theme", document.body.classList.contains("dark") ? "dark" : "light")}}')
shared.gradio['show_two_notebook_columns'].change(
handle_default_to_notebook_change,
gradio('show_two_notebook_columns', 'textbox-default', 'output_textbox', 'prompt_menu-default', 'textbox-notebook', 'prompt_menu-notebook'),
gradio('default-tab', 'notebook-tab', 'textbox-default', 'output_textbox', 'prompt_menu-default', 'textbox-notebook', 'prompt_menu-notebook')
)
# Reset interface event
shared.gradio['reset_interface'].click(
set_interface_arguments, gradio('extensions_menu', 'bool_menu'), None).then(
@ -50,6 +57,31 @@ def handle_save_settings(state, preset, extensions, show_controls, theme):
]
def handle_default_to_notebook_change(show_two_columns, default_input, default_output, default_prompt, notebook_input, notebook_prompt):
if show_two_columns:
# Notebook to default
return [
gr.update(visible=True),
gr.update(visible=False),
notebook_input,
notebook_input,
gr.update(value=notebook_prompt, choices=utils.get_available_prompts()),
gr.update(),
gr.update(),
]
else:
# Default to notebook
return [
gr.update(visible=False),
gr.update(visible=True),
gr.update(),
gr.update(),
gr.update(),
default_input,
gr.update(value=default_prompt, choices=utils.get_available_prompts())
]
def set_interface_arguments(extensions, bool_active):
shared.args.extensions = extensions