Add support for custom chat styles (#1917)
This commit is contained in:
parent
b040b4110d
commit
b5260b24f1
15 changed files with 234 additions and 74 deletions
|
@ -31,14 +31,14 @@ def refresh_voices_dd():
|
|||
return gr.Dropdown.update(value=all_voices[0], choices=all_voices)
|
||||
|
||||
|
||||
def remove_tts_from_history(name1, name2, mode):
|
||||
def remove_tts_from_history(name1, name2, mode, style):
|
||||
for i, entry in enumerate(shared.history['internal']):
|
||||
shared.history['visible'][i] = [shared.history['visible'][i][0], entry[1]]
|
||||
|
||||
return chat_html_wrapper(shared.history['visible'], name1, name2, mode)
|
||||
return chat_html_wrapper(shared.history['visible'], name1, name2, mode, style)
|
||||
|
||||
|
||||
def toggle_text_in_history(name1, name2, mode):
|
||||
def toggle_text_in_history(name1, name2, mode, style):
|
||||
for i, entry in enumerate(shared.history['visible']):
|
||||
visible_reply = entry[1]
|
||||
if visible_reply.startswith('<audio'):
|
||||
|
@ -52,7 +52,7 @@ def toggle_text_in_history(name1, name2, mode):
|
|||
shared.history['visible'][i][0], f"{visible_reply.split('</audio>')[0]}</audio>"
|
||||
]
|
||||
|
||||
return chat_html_wrapper(shared.history['visible'], name1, name2, mode)
|
||||
return chat_html_wrapper(shared.history['visible'], name1, name2, mode, style)
|
||||
|
||||
|
||||
def remove_surrounded_chars(string):
|
||||
|
@ -161,7 +161,7 @@ def ui():
|
|||
gr.update(visible=False)], None, convert_arr
|
||||
)
|
||||
convert_confirm.click(
|
||||
remove_tts_from_history, [shared.gradio[k] for k in ['name1', 'name2', 'mode']], shared.gradio['display']
|
||||
remove_tts_from_history, [shared.gradio[k] for k in ['name1', 'name2', 'mode', 'chat_style']], shared.gradio['display']
|
||||
)
|
||||
convert_confirm.click(chat.save_history, shared.gradio['mode'], [], show_progress=False)
|
||||
convert_cancel.click(
|
||||
|
@ -178,7 +178,7 @@ def ui():
|
|||
# Toggle message text in history
|
||||
show_text.change(lambda x: params.update({"show_text": x}), show_text, None)
|
||||
show_text.change(
|
||||
toggle_text_in_history, [shared.gradio[k] for k in ['name1', 'name2', 'mode']], shared.gradio['display']
|
||||
toggle_text_in_history, [shared.gradio[k] for k in ['name1', 'name2', 'mode', 'chat_style']], shared.gradio['display']
|
||||
)
|
||||
show_text.change(chat.save_history, shared.gradio['mode'], [], show_progress=False)
|
||||
# Event functions to update the parameters in the backend
|
||||
|
|
|
@ -57,13 +57,14 @@ def load_model():
|
|||
return model
|
||||
|
||||
|
||||
def remove_tts_from_history(name1, name2, mode):
|
||||
def remove_tts_from_history(name1, name2, mode, style):
|
||||
for i, entry in enumerate(shared.history['internal']):
|
||||
shared.history['visible'][i] = [shared.history['visible'][i][0], entry[1]]
|
||||
return chat_html_wrapper(shared.history['visible'], name1, name2, mode)
|
||||
|
||||
return chat_html_wrapper(shared.history['visible'], name1, name2, mode, style)
|
||||
|
||||
|
||||
def toggle_text_in_history(name1, name2, mode):
|
||||
def toggle_text_in_history(name1, name2, mode, style):
|
||||
for i, entry in enumerate(shared.history['visible']):
|
||||
visible_reply = entry[1]
|
||||
if visible_reply.startswith('<audio'):
|
||||
|
@ -72,7 +73,8 @@ def toggle_text_in_history(name1, name2, mode):
|
|||
shared.history['visible'][i] = [shared.history['visible'][i][0], f"{visible_reply.split('</audio>')[0]}</audio>\n\n{reply}"]
|
||||
else:
|
||||
shared.history['visible'][i] = [shared.history['visible'][i][0], f"{visible_reply.split('</audio>')[0]}</audio>"]
|
||||
return chat_html_wrapper(shared.history['visible'], name1, name2, mode)
|
||||
|
||||
return chat_html_wrapper(shared.history['visible'], name1, name2, mode, style)
|
||||
|
||||
|
||||
def state_modifier(state):
|
||||
|
@ -167,13 +169,13 @@ def ui():
|
|||
convert_arr = [convert_confirm, convert, convert_cancel]
|
||||
convert.click(lambda: [gr.update(visible=True), gr.update(visible=False), gr.update(visible=True)], None, convert_arr)
|
||||
convert_confirm.click(lambda: [gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)], None, convert_arr)
|
||||
convert_confirm.click(remove_tts_from_history, [shared.gradio[k] for k in ['name1', 'name2', 'mode']], shared.gradio['display'])
|
||||
convert_confirm.click(remove_tts_from_history, [shared.gradio[k] for k in ['name1', 'name2', 'mode', 'chat_style']], shared.gradio['display'])
|
||||
convert_confirm.click(chat.save_history, shared.gradio['mode'], [], show_progress=False)
|
||||
convert_cancel.click(lambda: [gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)], None, convert_arr)
|
||||
|
||||
# Toggle message text in history
|
||||
show_text.change(lambda x: params.update({"show_text": x}), show_text, None)
|
||||
show_text.change(toggle_text_in_history, [shared.gradio[k] for k in ['name1', 'name2', 'mode']], shared.gradio['display'])
|
||||
show_text.change(toggle_text_in_history, [shared.gradio[k] for k in ['name1', 'name2', 'mode', 'chat_style']], shared.gradio['display'])
|
||||
show_text.change(chat.save_history, shared.gradio['mode'], [], show_progress=False)
|
||||
|
||||
# Event functions to update the parameters in the backend
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue