mirror of
https://github.com/jags111/efficiency-nodes-comfyui.git
synced 2026-03-25 15:15:45 -03:00
Add validation to prevent empty prompts causing tokenization errors
Co-authored-by: jags111 <5968619+jags111@users.noreply.github.com>
This commit is contained in:
BIN
__pycache__/efficiency_nodes.cpython-312.pyc
Normal file
BIN
__pycache__/efficiency_nodes.cpython-312.pyc
Normal file
Binary file not shown.
@@ -72,6 +72,12 @@ def encode_prompts(positive_prompt, negative_prompt, token_normalization, weight
|
|||||||
refiner_clip, refiner_clip_skip, ascore, is_sdxl, empty_latent_width, empty_latent_height,
|
refiner_clip, refiner_clip_skip, ascore, is_sdxl, empty_latent_width, empty_latent_height,
|
||||||
return_type="both"):
|
return_type="both"):
|
||||||
|
|
||||||
|
# Ensure prompts are valid strings to prevent tokenization errors
|
||||||
|
if positive_prompt is None or (isinstance(positive_prompt, str) and not positive_prompt.strip()):
|
||||||
|
positive_prompt = " "
|
||||||
|
if negative_prompt is None or (isinstance(negative_prompt, str) and not negative_prompt.strip()):
|
||||||
|
negative_prompt = " "
|
||||||
|
|
||||||
positive_encoded = negative_encoded = refiner_positive_encoded = refiner_negative_encoded = None
|
positive_encoded = negative_encoded = refiner_positive_encoded = refiner_negative_encoded = None
|
||||||
|
|
||||||
# Process base encodings if needed
|
# Process base encodings if needed
|
||||||
|
|||||||
BIN
py/__pycache__/bnk_adv_encode.cpython-312.pyc
Normal file
BIN
py/__pycache__/bnk_adv_encode.cpython-312.pyc
Normal file
Binary file not shown.
@@ -237,6 +237,9 @@ def prepareXL(embs_l, embs_g, pooled, clip_balance):
|
|||||||
return embs_g, pooled
|
return embs_g, pooled
|
||||||
|
|
||||||
def advanced_encode(clip, text, token_normalization, weight_interpretation, w_max=1.0, clip_balance=.5, apply_to_pooled=True):
|
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
|
||||||
|
if text is None or (isinstance(text, str) and not text.strip()):
|
||||||
|
text = " "
|
||||||
tokenized = clip.tokenize(text, return_word_ids=True)
|
tokenized = clip.tokenize(text, return_word_ids=True)
|
||||||
if isinstance(clip.cond_stage_model, (SDXLClipModel, SDXLRefinerClipModel, SDXLClipG)):
|
if isinstance(clip.cond_stage_model, (SDXLClipModel, SDXLRefinerClipModel, SDXLClipG)):
|
||||||
embs_l = None
|
embs_l = None
|
||||||
@@ -265,6 +268,11 @@ def advanced_encode(clip, text, token_normalization, weight_interpretation, w_ma
|
|||||||
lambda x: (clip.encode_from_tokens({'l': x}), None),
|
lambda x: (clip.encode_from_tokens({'l': x}), None),
|
||||||
w_max=w_max)
|
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):
|
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
|
||||||
|
if text1 is None or (isinstance(text1, str) and not text1.strip()):
|
||||||
|
text1 = " "
|
||||||
|
if text2 is None or (isinstance(text2, str) and not text2.strip()):
|
||||||
|
text2 = " "
|
||||||
tokenized1 = clip.tokenize(text1, return_word_ids=True)
|
tokenized1 = clip.tokenize(text1, return_word_ids=True)
|
||||||
tokenized2 = clip.tokenize(text2, return_word_ids=True)
|
tokenized2 = clip.tokenize(text2, return_word_ids=True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user