mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-12-23 21:18:00 +01:00
Reload the default chat on page refresh
This commit is contained in:
parent
f1914115d3
commit
3b8cecbab7
@ -300,6 +300,10 @@ def load_history(file, name1, name2):
|
||||
shared.history['internal'] = tokenize_dialogue(file, name1, name2)
|
||||
shared.history['visible'] = copy.deepcopy(shared.history['internal'])
|
||||
|
||||
def load_default_history(name1, name2):
|
||||
if Path(f'logs/persistent.json').exists():
|
||||
load_history(open(Path(f'logs/persistent.json'), 'rb').read(), name1, name2)
|
||||
|
||||
def load_character(_character, name1, name2):
|
||||
context = ""
|
||||
shared.history['internal'] = []
|
||||
|
15
server.py
15
server.py
@ -187,8 +187,7 @@ else:
|
||||
|
||||
if shared.args.chat or shared.args.cai_chat:
|
||||
with gr.Blocks(css=ui.css+ui.chat_css, analytics_enabled=False) as interface:
|
||||
if Path(f'logs/persistent.json').exists():
|
||||
chat.load_history(open(Path(f'logs/persistent.json'), 'rb').read(), shared.settings[f'name1{suffix}'], shared.settings[f'name2{suffix}'])
|
||||
interface.load(lambda : chat.load_default_history(shared.settings[f'name1{suffix}'], shared.settings[f'name2{suffix}']), None, None)
|
||||
if shared.args.cai_chat:
|
||||
display = gr.HTML(value=generate_chat_html(shared.history['visible'], shared.settings[f'name1{suffix}'], shared.settings[f'name2{suffix}'], shared.character))
|
||||
else:
|
||||
@ -290,12 +289,12 @@ if shared.args.chat or shared.args.cai_chat:
|
||||
upload_img_me.upload(chat.upload_your_profile_picture, [upload_img_me], [])
|
||||
if shared.args.picture:
|
||||
picture_select.upload(lambda : None, [], [picture_select], show_progress=False)
|
||||
if shared.args.cai_chat:
|
||||
upload_chat_history.upload(chat.redraw_html, [name1, name2], [display])
|
||||
upload_img_me.upload(chat.redraw_html, [name1, name2], [display])
|
||||
else:
|
||||
upload_chat_history.upload(lambda : shared.history['visible'], [], [display])
|
||||
upload_img_me.upload(lambda : shared.history['visible'], [], [display])
|
||||
|
||||
reload_func = chat.redraw_html if shared.args.cai_chat else lambda : shared.history['visible']
|
||||
reload_inputs = [name1, name2] if shared.args.cai_chat else []
|
||||
upload_chat_history.upload(reload_func, reload_inputs, [display])
|
||||
upload_img_me.upload(reload_func, reload_inputs, [display])
|
||||
interface.load(reload_func, reload_inputs, [display], show_progress=False)
|
||||
|
||||
elif shared.args.notebook:
|
||||
with gr.Blocks(css=ui.css, analytics_enabled=False) as interface:
|
||||
|
Loading…
Reference in New Issue
Block a user