mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-22 08:07:56 +01:00
UI: Make the file saving dialogs more robust
This commit is contained in:
parent
423372d6e7
commit
7ef2414357
@ -2,6 +2,7 @@ import gradio as gr
|
|||||||
|
|
||||||
from modules import chat, presets, shared, ui, utils
|
from modules import chat, presets, shared, ui, utils
|
||||||
from modules.utils import gradio
|
from modules.utils import gradio
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
def create_ui():
|
def create_ui():
|
||||||
@ -68,31 +69,67 @@ def create_event_handlers():
|
|||||||
shared.gradio['delete_character_cancel'].click(lambda: gr.update(visible=False), None, gradio('character_deleter'), show_progress=False)
|
shared.gradio['delete_character_cancel'].click(lambda: gr.update(visible=False), None, gradio('character_deleter'), show_progress=False)
|
||||||
|
|
||||||
|
|
||||||
|
def handle_save_preset_confirm_click(filename, contents):
|
||||||
|
try:
|
||||||
|
utils.save_file(f"presets/{filename}.yaml", contents)
|
||||||
|
available_presets = utils.get_available_presets()
|
||||||
|
output = gr.update(choices=available_presets, value=filename),
|
||||||
|
except Exception:
|
||||||
|
output = gr.update()
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
return [
|
||||||
|
output,
|
||||||
|
gr.update(visible=False)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def handle_save_confirm_click(root, filename, contents):
|
def handle_save_confirm_click(root, filename, contents):
|
||||||
utils.save_file(root + filename, contents)
|
try:
|
||||||
|
utils.save_file(root + filename, contents)
|
||||||
|
except Exception:
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
return gr.update(visible=False)
|
return gr.update(visible=False)
|
||||||
|
|
||||||
|
|
||||||
def handle_delete_confirm_click(root, filename):
|
def handle_delete_confirm_click(root, filename):
|
||||||
utils.delete_file(root + filename)
|
try:
|
||||||
|
utils.delete_file(root + filename)
|
||||||
|
except Exception:
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
return gr.update(visible=False)
|
return gr.update(visible=False)
|
||||||
|
|
||||||
|
|
||||||
def handle_save_character_confirm_click(name2, greeting, context, character_picture, filename):
|
def handle_save_character_confirm_click(name2, greeting, context, character_picture, filename):
|
||||||
chat.save_character(name2, greeting, context, character_picture, filename)
|
try:
|
||||||
available_characters = utils.get_available_characters()
|
chat.save_character(name2, greeting, context, character_picture, filename)
|
||||||
|
available_characters = utils.get_available_characters()
|
||||||
|
output = gr.update(choices=available_characters, value=filename),
|
||||||
|
except Exception:
|
||||||
|
output = gr.update()
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
return [
|
return [
|
||||||
gr.update(choices=available_characters, value=filename),
|
output,
|
||||||
gr.update(visible=False)
|
gr.update(visible=False)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def handle_delete_character_confirm_click(character):
|
def handle_delete_character_confirm_click(character):
|
||||||
index = str(utils.get_available_characters().index(character))
|
try:
|
||||||
chat.delete_character(character)
|
index = str(utils.get_available_characters().index(character))
|
||||||
output = chat.update_character_menu_after_deletion(index)
|
chat.delete_character(character)
|
||||||
return [output, gr.update(visible=False)]
|
output = chat.update_character_menu_after_deletion(index)
|
||||||
|
except Exception:
|
||||||
|
output = gr.update()
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
return [
|
||||||
|
output,
|
||||||
|
gr.update(visible=False)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def handle_save_preset_click(state):
|
def handle_save_preset_click(state):
|
||||||
@ -104,15 +141,6 @@ def handle_save_preset_click(state):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def handle_save_preset_confirm_click(filename, contents):
|
|
||||||
utils.save_file(f"presets/{filename}.yaml", contents)
|
|
||||||
available_presets = utils.get_available_presets()
|
|
||||||
return [
|
|
||||||
gr.update(choices=available_presets, value=filename),
|
|
||||||
gr.update(visible=False)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def handle_delete_preset_click(preset):
|
def handle_delete_preset_click(preset):
|
||||||
return [
|
return [
|
||||||
f"{preset}.yaml",
|
f"{preset}.yaml",
|
||||||
|
Loading…
Reference in New Issue
Block a user