mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2026-04-05 06:35:15 +00:00
Autosave generated text in the Notebook tab (#7079)
This commit is contained in:
parent
d0befe0729
commit
faae4dc1b0
9 changed files with 325 additions and 52 deletions
|
|
@ -1,22 +1,33 @@
|
|||
from pathlib import Path
|
||||
|
||||
from modules import shared, utils
|
||||
from modules.text_generation import get_encoded_length
|
||||
|
||||
|
||||
def load_prompt(fname):
|
||||
if fname in ['None', '']:
|
||||
return ''
|
||||
else:
|
||||
file_path = Path(f'user_data/prompts/{fname}.txt')
|
||||
if not file_path.exists():
|
||||
return ''
|
||||
if not fname:
|
||||
# Create new file
|
||||
new_name = utils.current_time()
|
||||
prompt_path = Path("user_data/logs/notebook") / f"{new_name}.txt"
|
||||
prompt_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
initial_content = "In this story,"
|
||||
prompt_path.write_text(initial_content, encoding='utf-8')
|
||||
|
||||
# Update settings to point to new file
|
||||
shared.settings['prompt-notebook'] = new_name
|
||||
|
||||
return initial_content
|
||||
|
||||
file_path = Path(f'user_data/logs/notebook/{fname}.txt')
|
||||
if file_path.exists():
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
text = f.read()
|
||||
if text[-1] == '\n':
|
||||
if len(text) > 0 and text[-1] == '\n':
|
||||
text = text[:-1]
|
||||
|
||||
return text
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
def count_tokens(text):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue