Organize chat history/character import menu (#2845)

* Organize character import menu

* Move Chat history upload/download labels
This commit is contained in:
missionfloyd 2023-06-24 06:55:02 -06:00 committed by GitHub
parent 8bb3bb39b3
commit 51a388fa34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 20 deletions

View File

@ -557,7 +557,6 @@ def upload_character(json_file, img, tavern=False):
f.write(json_file) f.write(json_file)
if img is not None: if img is not None:
img = Image.open(io.BytesIO(img))
img.save(Path(f'characters/{outfile_name}.png')) img.save(Path(f'characters/{outfile_name}.png'))
logger.info(f'New character saved to "characters/{outfile_name}.json".') logger.info(f'New character saved to "characters/{outfile_name}.json".')
@ -570,7 +569,7 @@ def upload_tavern_character(img, name1, name2):
decoded_string = base64.b64decode(_img.info['chara']) decoded_string = base64.b64decode(_img.info['chara'])
_json = json.loads(decoded_string) _json = json.loads(decoded_string)
_json = {"char_name": _json['name'], "char_persona": _json['description'], "char_greeting": _json["first_mes"], "example_dialogue": _json['mes_example'], "world_scenario": _json['scenario']} _json = {"char_name": _json['name'], "char_persona": _json['description'], "char_greeting": _json["first_mes"], "example_dialogue": _json['mes_example'], "world_scenario": _json['scenario']}
return upload_character(json.dumps(_json), img, tavern=True) return upload_character(json.dumps(_json), _img, tavern=True)
def upload_your_profile_picture(img): def upload_your_profile_picture(img):

View File

@ -577,28 +577,22 @@ def create_interface():
with gr.Tab('Chat history'): with gr.Tab('Chat history'):
with gr.Row(): with gr.Row():
with gr.Column(): with gr.Column():
gr.Markdown('### Upload') shared.gradio['upload_chat_history'] = gr.File(type='binary', file_types=['.json', '.txt'], label="Upload")
shared.gradio['upload_chat_history'] = gr.File(type='binary', file_types=['.json', '.txt'])
with gr.Column(): with gr.Column():
gr.Markdown('### Download') shared.gradio['download'] = gr.File(label="Download")
shared.gradio['download'] = gr.File() shared.gradio['download_button'] = gr.Button(value='Refresh')
shared.gradio['download_button'] = gr.Button(value='Click me')
with gr.Tab('Upload character'): with gr.Tab('Upload character'):
gr.Markdown('### JSON format') with gr.Tab('JSON'):
with gr.Row(): with gr.Row():
with gr.Column(): shared.gradio['upload_json'] = gr.File(type='binary', file_types=['.json'], label='JSON File')
gr.Markdown('1. Select the JSON file') shared.gradio['upload_img_bot'] = gr.Image(type='pil', label='Profile Picture (optional)')
shared.gradio['upload_json'] = gr.File(type='binary', file_types=['.json'])
with gr.Column(): shared.gradio['Upload character'] = gr.Button(value='Submit', interactive=False)
gr.Markdown('2. Select your character\'s profile picture (optional)') with gr.Tab('TavernAI'):
shared.gradio['upload_img_bot'] = gr.File(type='binary', file_types=['image']) shared.gradio['upload_img_tavern'] = gr.File(type='binary', file_types=['image'], label='TavernAI PNG File')
shared.gradio['Upload tavern character'] = gr.Button(value='Submit', interactive=False)
shared.gradio['Upload character'] = gr.Button(value='Submit')
gr.Markdown('### TavernAI PNG format')
shared.gradio['upload_img_tavern'] = gr.File(type='binary', file_types=['image'])
with gr.Tab("Parameters", elem_id="parameters"): with gr.Tab("Parameters", elem_id="parameters"):
create_settings_menus(default_preset) create_settings_menus(default_preset)
@ -841,11 +835,16 @@ def create_interface():
shared.gradio['download_button'].click(lambda x: chat.save_history(x, timestamp=True), shared.gradio['mode'], shared.gradio['download']) shared.gradio['download_button'].click(lambda x: chat.save_history(x, timestamp=True), shared.gradio['mode'], shared.gradio['download'])
shared.gradio['Upload character'].click(chat.upload_character, [shared.gradio['upload_json'], shared.gradio['upload_img_bot']], [shared.gradio['character_menu']]) shared.gradio['Upload character'].click(chat.upload_character, [shared.gradio['upload_json'], shared.gradio['upload_img_bot']], [shared.gradio['character_menu']])
shared.gradio['upload_json'].upload(lambda: gr.update(interactive=True), None, [shared.gradio['Upload character']])
shared.gradio['upload_json'].clear(lambda: gr.update(interactive=False), None, [shared.gradio['Upload character']])
shared.gradio['character_menu'].change( shared.gradio['character_menu'].change(
partial(chat.load_character, instruct=False), [shared.gradio[k] for k in ['character_menu', 'name1', 'name2']], [shared.gradio[k] for k in ['name1', 'name2', 'character_picture', 'greeting', 'context', 'dummy']]).then( partial(chat.load_character, instruct=False), [shared.gradio[k] for k in ['character_menu', 'name1', 'name2']], [shared.gradio[k] for k in ['name1', 'name2', 'character_picture', 'greeting', 'context', 'dummy']]).then(
chat.redraw_html, shared.reload_inputs, shared.gradio['display']) chat.redraw_html, shared.reload_inputs, shared.gradio['display'])
shared.gradio['upload_img_tavern'].upload(chat.upload_tavern_character, [shared.gradio['upload_img_tavern'], shared.gradio['name1'], shared.gradio['name2']], [shared.gradio['character_menu']]) shared.gradio['Upload tavern character'].click(chat.upload_tavern_character, [shared.gradio['upload_img_tavern'], shared.gradio['name1'], shared.gradio['name2']], [shared.gradio['character_menu']])
shared.gradio['upload_img_tavern'].upload(lambda: gr.update(interactive=True), None, [shared.gradio['Upload tavern character']])
shared.gradio['upload_img_tavern'].clear(lambda: gr.update(interactive=False), None, [shared.gradio['Upload tavern character']])
shared.gradio['your_picture'].change( shared.gradio['your_picture'].change(
chat.upload_your_profile_picture, shared.gradio['your_picture'], None).then( chat.upload_your_profile_picture, shared.gradio['your_picture'], None).then(
partial(chat.redraw_html, reset_cache=True), shared.reload_inputs, shared.gradio['display']) partial(chat.redraw_html, reset_cache=True), shared.reload_inputs, shared.gradio['display'])