6 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
6c0c6cac4e Remove unnecessary blank line for consistent formatting
Co-authored-by: jags111 <5968619+jags111@users.noreply.github.com>
2026-02-03 23:04:29 +00:00
copilot-swe-agent[bot]
bceccbcf06 Improve documentation for normalize_prompt_text function
Co-authored-by: jags111 <5968619+jags111@users.noreply.github.com>
2026-02-03 23:03:53 +00:00
copilot-swe-agent[bot]
3fa0e8c927 Refactor validation into shared helper function and improve type handling
Co-authored-by: jags111 <5968619+jags111@users.noreply.github.com>
2026-02-03 23:03:17 +00:00
copilot-swe-agent[bot]
94c9d05e2e Remove __pycache__ files and add .gitignore
Co-authored-by: jags111 <5968619+jags111@users.noreply.github.com>
2026-02-03 23:01:33 +00:00
copilot-swe-agent[bot]
b083ff3f6c Add validation to prevent empty prompts causing tokenization errors
Co-authored-by: jags111 <5968619+jags111@users.noreply.github.com>
2026-02-03 23:01:19 +00:00
copilot-swe-agent[bot]
f9692f29ff Initial plan 2026-02-03 22:58:29 +00:00
4 changed files with 62 additions and 4 deletions

22
.gitignore vendored Normal file
View File

@@ -0,0 +1,22 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
# Virtual environments
venv/
ENV/
env/
# IDEs
.vscode/
.idea/
*.swp
*.swo
*~
# OS
.DS_Store
Thumbs.db

View File

@@ -53,6 +53,7 @@ from .py import city96_latent_upscaler
from .py import ttl_nn_latent_upscaler
from .py import bnk_tiled_samplers
from .py import bnk_adv_encode
from .py.bnk_adv_encode import normalize_prompt_text
sys.path.remove(my_dir)
from comfy import samplers
@@ -71,6 +72,9 @@ SCHEDULERS = samplers.KSampler.SCHEDULERS + ["AYS SD1", "AYS SDXL", "AYS SVD", "
def encode_prompts(positive_prompt, negative_prompt, token_normalization, weight_interpretation, clip, clip_skip,
refiner_clip, refiner_clip_skip, ascore, is_sdxl, empty_latent_width, empty_latent_height,
return_type="both"):
# Ensure prompts are valid strings to prevent tokenization errors
positive_prompt = normalize_prompt_text(positive_prompt)
negative_prompt = normalize_prompt_text(negative_prompt)
positive_encoded = negative_encoded = refiner_positive_encoded = refiner_negative_encoded = None

View File

@@ -36,6 +36,7 @@ function toggleWidget(node, widget, show = false, suffix = "") {
node.setSize([node.size[0], newHeight]);
}
const WIDGET_HEIGHT = 24;
// Use for Multiline Widget Nodes (aka Efficient Loaders)
function toggleWidget_2(node, widget, show = false, suffix = "") {
if (!widget || doesInputWithNameExist(node, widget.name)) return;
@@ -51,10 +52,8 @@ function toggleWidget_2(node, widget, show = false, suffix = "") {
widget.computeSize = show ? origProps[widget.name].origComputeSize : () => [0, -4];
if (initialized){
// Calculate the new height for the node based on its computeSize method
// This properly accounts for font size changes and ensures widgets don't overlap
const newHeight = node.computeSize()[1];
node.setSize([node.size[0], newHeight]);
const adjustment = show ? WIDGET_HEIGHT : -WIDGET_HEIGHT;
node.setSize([node.size[0], node.size[1] + adjustment]);
}
}

View File

@@ -6,6 +6,34 @@ from math import gcd
from comfy import model_management
from comfy.sdxl_clip import SDXLClipModel, SDXLRefinerClipModel, SDXLClipG
def normalize_prompt_text(text):
"""
Normalize prompt text to prevent tokenization errors.
Converts None, empty strings, or whitespace-only strings to a single space.
Ensures the input is a string type by converting non-string values.
This function is designed to handle edge cases gracefully without crashing,
which is important for ComfyUI workflows where users might have empty prompts.
Parameters:
text: The input prompt text to normalize. Can be of any type, though
string, None, or convertible types are expected.
Returns:
str: A normalized string that is safe to pass to the tokenizer.
Returns " " (single space) for None, empty, or whitespace-only inputs.
Returns the original text unchanged if it's a valid non-empty string.
Returns str(text) for non-string types.
"""
if text is None:
return " "
if not isinstance(text, str):
# Convert non-string types to string
text = str(text)
if not text.strip():
return " "
return text
def _grouper(n, iterable):
it = iter(iterable)
while True:
@@ -237,6 +265,8 @@ def prepareXL(embs_l, embs_g, pooled, clip_balance):
return embs_g, pooled
def advanced_encode(clip, text, token_normalization, weight_interpretation, w_max=1.0, clip_balance=.5, apply_to_pooled=True):
# Ensure text is a valid string to prevent tokenization errors
text = normalize_prompt_text(text)
tokenized = clip.tokenize(text, return_word_ids=True)
if isinstance(clip.cond_stage_model, (SDXLClipModel, SDXLRefinerClipModel, SDXLClipG)):
embs_l = None
@@ -265,6 +295,9 @@ def advanced_encode(clip, text, token_normalization, weight_interpretation, w_ma
lambda x: (clip.encode_from_tokens({'l': x}), None),
w_max=w_max)
def advanced_encode_XL(clip, text1, text2, token_normalization, weight_interpretation, w_max=1.0, clip_balance=.5, apply_to_pooled=True):
# Ensure texts are valid strings to prevent tokenization errors
text1 = normalize_prompt_text(text1)
text2 = normalize_prompt_text(text2)
tokenized1 = clip.tokenize(text1, return_word_ids=True)
tokenized2 = clip.tokenize(text2, return_word_ids=True)