Use --disk-cache-dir for all caches

This commit is contained in:
Alberto Cano 2024-01-04 04:27:26 +01:00 committed by GitHub
parent 7965f6045e
commit 37eff915d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 12 deletions

View File

@ -560,17 +560,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
@ -594,8 +594,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()
@ -713,17 +714,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):

View File

@ -8,6 +8,7 @@ import markdown
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 = {}
@ -170,7 +171,7 @@ 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()
@ -178,8 +179,8 @@ def get_image_cache(path):
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)