mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-22 16:17:57 +01:00
Change the filenames for caches and histories
This commit is contained in:
parent
2255349f19
commit
6c6a52aaad
@ -395,6 +395,7 @@ def save_history(history, path=None):
|
|||||||
p = path or Path('logs/exported_history.json')
|
p = path or Path('logs/exported_history.json')
|
||||||
if not p.parent.is_dir():
|
if not p.parent.is_dir():
|
||||||
p.parent.mkdir(parents=True)
|
p.parent.mkdir(parents=True)
|
||||||
|
|
||||||
with open(p, 'w', encoding='utf-8') as f:
|
with open(p, 'w', encoding='utf-8') as f:
|
||||||
f.write(json.dumps(history, indent=4))
|
f.write(json.dumps(history, indent=4))
|
||||||
|
|
||||||
@ -415,7 +416,7 @@ def load_history(file, history):
|
|||||||
|
|
||||||
def save_persistent_history(history, character, mode):
|
def save_persistent_history(history, character, mode):
|
||||||
if mode in ['chat', 'chat-instruct'] and character not in ['', 'None', None] and not shared.args.multi_user:
|
if mode in ['chat', 'chat-instruct'] and character not in ['', 'None', None] and not shared.args.multi_user:
|
||||||
save_history(history, path=Path(f'logs/{character}_persistent.json'))
|
save_history(history, path=Path(f'logs/persistent_{character}.json'))
|
||||||
|
|
||||||
|
|
||||||
def load_persistent_history(state):
|
def load_persistent_history(state):
|
||||||
@ -428,8 +429,15 @@ def load_persistent_history(state):
|
|||||||
|
|
||||||
character = state['character_menu']
|
character = state['character_menu']
|
||||||
greeting = replace_character_names(state['greeting'], state['name1'], state['name2'])
|
greeting = replace_character_names(state['greeting'], state['name1'], state['name2'])
|
||||||
p = Path(f'logs/{character}_persistent.json')
|
|
||||||
if not shared.args.multi_user and character not in ['None', '', None] and p.exists():
|
should_load_history = (not shared.args.multi_user and character not in ['None', '', None])
|
||||||
|
old_p = Path(f'logs/{character}_persistent.json')
|
||||||
|
p = Path(f'logs/persistent_{character}.json')
|
||||||
|
if should_load_history and old_p.exists():
|
||||||
|
logger.warning(f"Renaming {old_p} to {p}")
|
||||||
|
old_p.rename(p)
|
||||||
|
|
||||||
|
if should_load_history and p.exists():
|
||||||
f = json.loads(open(p, 'rb').read())
|
f = json.loads(open(p, 'rb').read())
|
||||||
if 'internal' in f and 'visible' in f:
|
if 'internal' in f and 'visible' in f:
|
||||||
history = f
|
history = f
|
||||||
|
@ -6,6 +6,7 @@ from pathlib import Path
|
|||||||
import markdown
|
import markdown
|
||||||
from PIL import Image, ImageOps
|
from PIL import Image, ImageOps
|
||||||
|
|
||||||
|
from modules.logging_colors import logger
|
||||||
from modules.utils import get_available_chat_styles
|
from modules.utils import get_available_chat_styles
|
||||||
|
|
||||||
# This is to store the paths to the thumbnails of the profile pictures
|
# This is to store the paths to the thumbnails of the profile pictures
|
||||||
@ -120,6 +121,7 @@ def generate_4chan_html(f):
|
|||||||
post = line
|
post = line
|
||||||
else:
|
else:
|
||||||
post += line
|
post += line
|
||||||
|
|
||||||
if post != '':
|
if post != '':
|
||||||
src = process_post(post, c)
|
src = process_post(post, c)
|
||||||
posts.append(src)
|
posts.append(src)
|
||||||
@ -134,13 +136,14 @@ def generate_4chan_html(f):
|
|||||||
output += f'<style>{_4chan_css}</style><div id="parent"><div id="container">'
|
output += f'<style>{_4chan_css}</style><div id="parent"><div id="container">'
|
||||||
for post in posts:
|
for post in posts:
|
||||||
output += post
|
output += post
|
||||||
|
|
||||||
output += '</div></div>'
|
output += '</div></div>'
|
||||||
output = output.split('\n')
|
output = output.split('\n')
|
||||||
for i in range(len(output)):
|
for i in range(len(output)):
|
||||||
output[i] = re.sub(r'^(>(.*?)(<br>|</div>))', r'<span class="greentext">\1</span>', output[i])
|
output[i] = re.sub(r'^(>(.*?)(<br>|</div>))', r'<span class="greentext">\1</span>', output[i])
|
||||||
output[i] = re.sub(r'^<blockquote class="message">(>(.*?)(<br>|</div>))', r'<blockquote class="message"><span class="greentext">\1</span>', output[i])
|
output[i] = re.sub(r'^<blockquote class="message">(>(.*?)(<br>|</div>))', r'<blockquote class="message"><span class="greentext">\1</span>', output[i])
|
||||||
output = '\n'.join(output)
|
|
||||||
|
|
||||||
|
output = '\n'.join(output)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
@ -160,7 +163,13 @@ def get_image_cache(path):
|
|||||||
mtime = os.stat(path).st_mtime
|
mtime = os.stat(path).st_mtime
|
||||||
if (path in image_cache and mtime != image_cache[path][0]) or (path not in image_cache):
|
if (path in image_cache and mtime != image_cache[path][0]) or (path not in image_cache):
|
||||||
img = make_thumbnail(Image.open(path))
|
img = make_thumbnail(Image.open(path))
|
||||||
output_file = Path(f'cache/{path.name}_cache.png')
|
|
||||||
|
old_p = Path(f'cache/{path.name}_cache.png')
|
||||||
|
p = Path(f'cache/cache_{path.name}.png')
|
||||||
|
if old_p.exists():
|
||||||
|
old_p.rename(p)
|
||||||
|
|
||||||
|
output_file = p
|
||||||
img.convert('RGB').save(output_file, format='PNG')
|
img.convert('RGB').save(output_file, format='PNG')
|
||||||
image_cache[path] = [mtime, output_file.as_posix()]
|
image_cache[path] = [mtime, output_file.as_posix()]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user