Skip to content

Commit

Permalink
FIx
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkohole committed Dec 2, 2024
1 parent f131f60 commit 71ae413
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
30 changes: 22 additions & 8 deletions modules/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ def load_character(character, name1, name2):
context = greeting = ""
greeting_field = 'greeting'
picture = None
your_picture = None
profile_name = name1

filepath = None
for extension in ["yml", "yaml", "json"]:
Expand All @@ -754,6 +756,7 @@ def load_character(character, name1, name2):
path.unlink()

picture = generate_pfp_cache(character)
your_picture = upload_your_profile_picture(picture, profile_name)

# Finding the bot's name
for k in ['name', 'bot', '<|bot|>', 'char_name']:
Expand Down Expand Up @@ -869,18 +872,28 @@ def check_tavern_character(img):
return _json['name'], _json['description'], _json, gr.update(interactive=True)


def upload_your_profile_picture(img):
def upload_your_profile_picture(img, profile_name):
cache_folder = Path(shared.args.disk_cache_dir)
if not cache_folder.exists():
cache_folder.mkdir()

if img is None:
if Path(f"{cache_folder}/pfp_me.png").exists():
Path(f"{cache_folder}/pfp_me.png").unlink()
if profile_name is None:
if img is None:
if Path(f"{cache_folder}/pfp_me.png").exists():
Path(f"{cache_folder}/pfp_me.png").unlink()
else:
img = make_thumbnail(img)
img.save(Path(f'{cache_folder}/pfp_me.png'))
logger.info(f'Profile picture saved to "{cache_folder}/pfp_me.png"')

else:
img = make_thumbnail(img)
img.save(Path(f'{cache_folder}/pfp_me.png'))
logger.info(f'Profile picture saved to "{cache_folder}/pfp_me.png"')
for img_path in [Path(f"users/{profile_name}.{extension}") for extension in ['png', 'jpg', 'jpeg']]:
if img_path.exists():
with Image.open(img_path) as img:
img = make_thumbnail(img)
img.save(Path(f'{cache_folder}/pfp_me.png'), format='PNG')

return None


def generate_character_yaml(name, greeting, context):
Expand Down Expand Up @@ -1212,6 +1225,7 @@ def load_user_profile(profile_name):
if img_file.exists():
from PIL import Image
picture = Image.open(img_file)
upload_your_profile_picture(picture, profile_name)

return {
'name1': data.get('name', ''),
Expand Down Expand Up @@ -1289,7 +1303,7 @@ def handle_delete_template_click(template):


def handle_your_picture_change(picture, state):
upload_your_profile_picture(picture)
upload_your_profile_picture(picture, profile_name=None)
html = redraw_html(state['history'], state['name1'], state['name2'], state['mode'], state['chat_style'], state['character_menu'], reset_cache=True)

return html
Expand Down
1 change: 1 addition & 0 deletions modules/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
'skip_special_tokens': True,
'stream': True,
'character': 'Assistant',
'user': 'You',
'name1': 'You',
'user_bio': '',
'custom_system_message': '',
Expand Down

0 comments on commit 71ae413

Please sign in to comment.