Skip to content

Commit 0f34e89

Browse files
committed
Added SD3TextConditioningWithOptionsOnePrompt
1 parent 77e6506 commit 0f34e89

File tree

2 files changed

+107
-2
lines changed

2 files changed

+107
-2
lines changed

mikey_nodes.py

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5124,6 +5124,95 @@ def pad_text(self, text, length, technique, padding_character):
51245124
padded_text = padded_text.ljust(length, padding_character)
51255125
return (padded_text,)
51265126

5127+
class SD3TextConditioningWithOptionsOnePrompt:
5128+
@classmethod
5129+
def INPUT_TYPES(cls):
5130+
return {'required': {'positive_prompt': ('STRING', {'default': 'positive prompt', 'multiline': True}),
5131+
'negative_prompt': ('STRING', {'default': 'negative prompt', 'multiline': True}),
5132+
'clip': ('CLIP',),
5133+
'option_positive_clip_l': (['Unmodified','Padded','Empty'], {'default': 'Unmodified'}),
5134+
'option_positive_clip_g': (['Unmodified','Padded','Empty'], {'default': 'Unmodified'}),
5135+
'option_positive_t5xxl': (['Unmodified','Padded','Empty'], {'default': 'Unmodified'}),
5136+
'option_negative_clip_l': (['Unmodified','Padded','Empty'], {'default': 'Unmodified'}),
5137+
'option_negative_clip_g': (['Unmodified','Padded','Empty'], {'default': 'Unmodified'}),
5138+
'option_negative_t5xxl': (['Unmodified','Padded','Empty'], {'default': 'Unmodified'}),
5139+
'padding_character': ('STRING', {'default': ','})}}
5140+
5141+
RETURN_TYPES = ('CONDITIONING','CONDITIONING',)
5142+
RETURN_NAMES = ('positive_conditioning','negative_conditioning')
5143+
FUNCTION = 'process'
5144+
CATEGORY = 'Mikey/SD3/Conditioning'
5145+
5146+
def process(self, positive_prompt, negative_prompt, clip, option_positive_clip_l, option_positive_clip_g, option_positive_t5xxl, option_negative_clip_l, option_negative_clip_g, option_negative_t5xxl, padding_character):
5147+
positive_tokens = clip.tokenize(positive_prompt)
5148+
if len(positive_prompt) == 0 or option_positive_clip_g == 'Empty':
5149+
positive_tokens['g'] = []
5150+
if len(positive_tokens['g']) < 77 and option_positive_clip_l == 'Padded':
5151+
padded_g_string = positive_prompt + padding_character * (77 - len(positive_tokens['g']))
5152+
positive_tokens['g'] = clip.tokenize(padded_g_string)['g']
5153+
5154+
if len(positive_prompt) == 0 or option_positive_clip_l == 'Empty':
5155+
positive_tokens['l'] = []
5156+
elif len(positive_tokens['l']) < 77 and option_positive_clip_l == 'Padded':
5157+
padded_l_string = positive_prompt + padding_character * (77 - len(positive_tokens['l']))
5158+
positive_tokens['l'] = clip.tokenize(padded_l_string)['l']
5159+
else:
5160+
positive_tokens['l'] = clip.tokenize(positive_prompt)['l']
5161+
5162+
if len(positive_prompt) == 0 or option_positive_t5xxl == 'Empty':
5163+
positive_tokens['t5xxl'] = []
5164+
elif len(positive_tokens['t5xxl']) < 512 and option_positive_t5xxl == 'Padded':
5165+
padded_t5xxl_string = positive_prompt + padding_character * (512 - len(positive_tokens['t5xxl']))
5166+
positive_tokens['t5xxl'] = clip.tokenize(padded_t5xxl_string)['t5xxl']
5167+
else:
5168+
positive_tokens['t5xxl'] = clip.tokenize(positive_prompt)['t5xxl']
5169+
5170+
if len(positive_tokens['l']) != len(positive_tokens['g']):
5171+
empty = clip.tokenize('')
5172+
while len(positive_tokens['l']) < len(positive_tokens['g']):
5173+
positive_tokens['l'] += empty['l']
5174+
while len(positive_tokens['l']) > len(positive_tokens['g']):
5175+
positive_tokens['g'] += empty['g']
5176+
positive_conditioning, positive_pooled = clip.encode_from_tokens(positive_tokens, return_pooled=True)
5177+
5178+
# now negative
5179+
negative_tokens = clip.tokenize(negative_prompt)
5180+
if len(negative_prompt) == 0 or option_negative_clip_g == 'Empty':
5181+
negative_tokens['g'] = []
5182+
if len(negative_tokens['g']) < 77 and option_negative_clip_l == 'Padded':
5183+
padded_g_string = negative_prompt + padding_character * (77 - len(negative_tokens['g']))
5184+
negative_tokens['g'] = clip.tokenize(padded_g_string)['g']
5185+
5186+
if len(negative_prompt) == 0 or option_negative_clip_l == 'Empty':
5187+
negative_tokens['l'] = []
5188+
elif len(negative_tokens['l']) < 77 and option_negative_clip_l == 'Padded':
5189+
padded_l_string = negative_prompt + padding_character * (75 - len(negative_tokens['l']))
5190+
negative_tokens['l'] = clip.tokenize(padded_l_string)['l']
5191+
else:
5192+
negative_tokens['l'] = clip.tokenize(negative_prompt)['l']
5193+
5194+
if len(negative_prompt) == 0 or option_negative_t5xxl == 'Empty':
5195+
negative_tokens['t5xxl'] = []
5196+
elif len(negative_tokens['t5xxl']) < 512 and option_negative_t5xxl == 'Padded':
5197+
padded_t5xxl_string = negative_prompt + padding_character * (512 - len(negative_tokens['t5xxl']))
5198+
negative_tokens['t5xxl'] = clip.tokenize(padded_t5xxl_string)['t5xxl']
5199+
else:
5200+
negative_tokens['t5xxl'] = clip.tokenize(negative_prompt)['t5xxl']
5201+
5202+
if len(negative_tokens['l']) != len(negative_tokens['g']):
5203+
empty = clip.tokenize('')
5204+
while len(negative_tokens['l']) < len(negative_tokens['g']):
5205+
negative_tokens['l'] += empty['l']
5206+
while len(negative_tokens['l']) > len(negative_tokens['g']):
5207+
negative_tokens['g'] += empty['g']
5208+
negative_conditioning, negative_pooled = clip.encode_from_tokens(negative_tokens, return_pooled=True)
5209+
5210+
return (
5211+
[[positive_conditioning, {'pooled_output': positive_pooled}]],
5212+
[[negative_conditioning, {'pooled_output': negative_pooled}]],
5213+
)
5214+
5215+
51275216
NODE_CLASS_MAPPINGS = {
51285217
'Wildcard Processor': WildcardProcessor,
51295218
'Empty Latent Ratio Select SDXL': EmptyLatentRatioSelector,
@@ -5191,7 +5280,8 @@ def pad_text(self, text, length, technique, padding_character):
51915280
'CinematicLook': CinematicLook,
51925281
'MosaicExpandImage': MosaicExpandImage,
51935282
'GetSubdirectories': GetSubdirectories,
5194-
'TextPadderMikey': TextPadderMikey
5283+
'TextPadderMikey': TextPadderMikey,
5284+
'SD3TextConditioningWithOptionsOnePrompt': SD3TextConditioningWithOptionsOnePrompt
51955285
}
51965286

51975287
NODE_DISPLAY_NAME_MAPPINGS = {
@@ -5261,5 +5351,6 @@ def pad_text(self, text, length, technique, padding_character):
52615351
'CinematicLook': 'Cinematic Look (Mikey)',
52625352
'MosaicExpandImage': 'Mosaic Expand Image (Mikey)',
52635353
'GetSubdirectories': 'Get Subdirectories (Mikey)',
5264-
'TextPadderMikey': 'Text Padder (Mikey)'
5354+
'TextPadderMikey': 'Text Padder (Mikey)',
5355+
'SD3TextConditioningWithOptionsOnePrompt': 'SD3 Text Conditioning With Options. One Prompt (Mikey)'
52655356
}

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[project]
2+
name = "mikey_nodes"
3+
description = "Collection of convenient nodes. Wildcard, style, image, llm, haldclut, metadata, and more."
4+
version = "1.0.0"
5+
license = "MIT License"
6+
7+
[project.urls]
8+
Repository = "https://github.com/bash-j/mikey_nodes"
9+
# Used by Comfy Registry https://comfyregistry.org
10+
11+
[tool.comfy]
12+
PublisherId = "humblemikey"
13+
DisplayName = "mikey_nodes"
14+
Icon = ""

0 commit comments

Comments
 (0)