Add menus for saving presets/characters/instruction templates/prompts (#2621)

This commit is contained in:
oobabooga 2023-06-11 12:19:18 -03:00 committed by GitHub
parent ea0eabd266
commit 6133675e0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 220 additions and 98 deletions

View file

@ -3,6 +3,42 @@ import re
from pathlib import Path
from modules import shared
from modules.logging_colors import logger
def save_file(fname, contents):
if fname == '':
logger.error('File name is empty!')
return
root_folder = Path(__file__).resolve().parent.parent
abs_path = Path(fname).resolve()
rel_path = abs_path.relative_to(root_folder)
if rel_path.parts[0] == '..':
logger.error(f'Invalid file path: {fname}')
return
with open(abs_path, 'w', encoding='utf-8') as f:
f.write(contents)
logger.info(f'Saved {abs_path}.')
def delete_file(fname):
if fname == '':
logger.error('File name is empty!')
return
root_folder = Path(__file__).resolve().parent.parent
abs_path = Path(fname).resolve()
rel_path = abs_path.relative_to(root_folder)
if rel_path.parts[0] == '..':
logger.error(f'Invalid file path: {fname}')
return
if abs_path.exists():
abs_path.unlink()
logger.info(f'Deleted {fname}.')
def atoi(text):