From a3eb67e466f9cc23a6c3607842375e8bf50f2dd0 Mon Sep 17 00:00:00 2001
From: oobabooga <112222186+oobabooga@users.noreply.github.com>
Date: Sat, 30 Aug 2025 08:42:26 -0700
Subject: [PATCH] Fix the UI failing to launch if the Notebook prompt is too
long
---
modules/prompts.py | 3 +--
modules/ui_default.py | 3 +--
modules/ui_notebook.py | 3 +--
server.py | 8 ++++++++
4 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/modules/prompts.py b/modules/prompts.py
index 79d9b56e..b800af91 100644
--- a/modules/prompts.py
+++ b/modules/prompts.py
@@ -22,8 +22,7 @@ def load_prompt(fname):
if file_path.exists():
with open(file_path, 'r', encoding='utf-8') as f:
text = f.read()
- if len(text) > 0 and text[-1] == '\n':
- text = text[:-1]
+ text = text.rstrip()
return text
else:
diff --git a/modules/ui_default.py b/modules/ui_default.py
index 44af48a3..c0feae19 100644
--- a/modules/ui_default.py
+++ b/modules/ui_default.py
@@ -22,8 +22,7 @@ def create_ui():
with gr.Row():
with gr.Column():
with gr.Row():
- initial_text = load_prompt(shared.settings['prompt-notebook'])
- shared.gradio['textbox-default'] = gr.Textbox(value=initial_text, lines=27, label='Input', elem_classes=['textbox_default', 'add_scrollbar'])
+ shared.gradio['textbox-default'] = gr.Textbox(value="", lines=27, label='Input', elem_classes=['textbox_default', 'add_scrollbar'])
shared.gradio['token-counter-default'] = gr.HTML(value="0", elem_id="default-token-counter")
with gr.Row():
diff --git a/modules/ui_notebook.py b/modules/ui_notebook.py
index 939d81f7..9fab879b 100644
--- a/modules/ui_notebook.py
+++ b/modules/ui_notebook.py
@@ -30,8 +30,7 @@ def create_ui():
with gr.Column(scale=4):
with gr.Tab('Raw'):
with gr.Row():
- initial_text = load_prompt(shared.settings['prompt-notebook'])
- shared.gradio['textbox-notebook'] = gr.Textbox(label="", value=initial_text, lines=27, elem_id='textbox-notebook', elem_classes=['textbox', 'add_scrollbar'])
+ shared.gradio['textbox-notebook'] = gr.Textbox(label="", value="", lines=27, elem_id='textbox-notebook', elem_classes=['textbox', 'add_scrollbar'])
shared.gradio['token-counter-notebook'] = gr.HTML(value="0", elem_id="notebook-token-counter")
with gr.Tab('Markdown'):
diff --git a/server.py b/server.py
index 52463a3c..c804c342 100644
--- a/server.py
+++ b/server.py
@@ -6,6 +6,7 @@ from pathlib import Path
from modules import shared
from modules.block_requests import OpenMonkeyPatch, RequestBlocker
from modules.logging_colors import logger
+from modules.prompts import load_prompt
# Set up Gradio temp directory path
gradio_temp_path = Path('user_data') / 'cache' / 'gradio'
@@ -109,6 +110,13 @@ def create_interface():
'filter_by_loader': (shared.args.loader or 'All') if not shared.args.portable else 'llama.cpp'
})
+ if shared.settings['prompt-notebook']:
+ prompt = load_prompt(shared.settings['prompt-notebook'])
+ shared.persistent_interface_state.update({
+ 'textbox-default': prompt,
+ 'textbox-notebook': prompt
+ })
+
# Clear existing cache files
for cache_file in ['pfp_character.png', 'pfp_character_thumb.png']:
cache_path = Path(f"user_data/cache/{cache_file}")