Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--disk-cache-dir option fix #5103

Merged
merged 15 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions modules/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,17 +561,17 @@ def replace_character_names(text, name1, name2):


def generate_pfp_cache(character):
cache_folder = Path("cache")
cache_folder = Path(shared.args.disk_cache_dir)
if not cache_folder.exists():
cache_folder.mkdir()

for path in [Path(f"characters/{character}.{extension}") for extension in ['png', 'jpg', 'jpeg']]:
if path.exists():
original_img = Image.open(path)
original_img.save(Path('cache/pfp_character.png'), format='PNG')
original_img.save(Path('{cache_folder}/pfp_character.png'), format='PNG')

thumb = make_thumbnail(original_img)
thumb.save(Path('cache/pfp_character_thumb.png'), format='PNG')
thumb.save(Path('{cache_folder}/pfp_character_thumb.png'), format='PNG')

return thumb

Expand All @@ -595,8 +595,9 @@ def load_character(character, name1, name2):

file_contents = open(filepath, 'r', encoding='utf-8').read()
data = json.loads(file_contents) if extension == "json" else yaml.safe_load(file_contents)
cache_folder = Path(shared.args.disk_cache_dir)

for path in [Path("cache/pfp_character.png"), Path("cache/pfp_character_thumb.png")]:
for path in [Path("{cache_folder}/pfp_character.png"), Path("{cache_folder}/pfp_character_thumb.png")]:
if path.exists():
path.unlink()

Expand Down Expand Up @@ -714,17 +715,17 @@ def check_tavern_character(img):


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

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


def generate_character_yaml(name, greeting, context):
Expand Down
7 changes: 4 additions & 3 deletions modules/html_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from PIL import Image, ImageOps

from modules.utils import get_available_chat_styles
from modules import shared

# This is to store the paths to the thumbnails of the profile pictures
image_cache = {}
Expand Down Expand Up @@ -170,16 +171,16 @@ def make_thumbnail(image):


def get_image_cache(path):
cache_folder = Path("cache")
cache_folder = Path(shared.args.disk_cache_dir)
if not cache_folder.exists():
cache_folder.mkdir()

mtime = os.stat(path).st_mtime
if (path in image_cache and mtime != image_cache[path][0]) or (path not in image_cache):
img = make_thumbnail(Image.open(path))

old_p = Path(f'cache/{path.name}_cache.png')
p = Path(f'cache/cache_{path.name}.png')
old_p = Path(f'{cache_folder}/{path.name}_cache.png')
p = Path(f'{cache_folder}/cache_{path.name}.png')
if old_p.exists():
old_p.rename(p)

Expand Down