mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-07-27 08:16:44 +00:00
61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
from comfy_api.latest import io
|
|
|
|
|
|
class CLIPTextEncodeControlnet(io.ComfyNode):
|
|
@classmethod
|
|
def define_schema(cls) -> io.Schema:
|
|
return io.Schema(
|
|
node_id="CLIPTextEncodeControlnet_V3",
|
|
category="_for_testing/conditioning",
|
|
inputs=[
|
|
io.Clip.Input("clip"),
|
|
io.Conditioning.Input("conditioning"),
|
|
io.String.Input("text", multiline=True, dynamic_prompts=True),
|
|
],
|
|
outputs=[io.Conditioning.Output()],
|
|
)
|
|
|
|
@classmethod
|
|
def execute(cls, clip, conditioning, text) -> io.NodeOutput:
|
|
tokens = clip.tokenize(text)
|
|
cond, pooled = clip.encode_from_tokens(tokens, return_pooled=True)
|
|
c = []
|
|
for t in conditioning:
|
|
n = [t[0], t[1].copy()]
|
|
n[1]['cross_attn_controlnet'] = cond
|
|
n[1]['pooled_output_controlnet'] = pooled
|
|
c.append(n)
|
|
return io.NodeOutput(c)
|
|
|
|
|
|
class T5TokenizerOptions(io.ComfyNode):
|
|
@classmethod
|
|
def define_schema(cls) -> io.Schema:
|
|
return io.Schema(
|
|
node_id="T5TokenizerOptions_V3",
|
|
category="_for_testing/conditioning",
|
|
inputs=[
|
|
io.Clip.Input("clip"),
|
|
io.Int.Input("min_padding", default=0, min=0, max=10000, step=1),
|
|
io.Int.Input("min_length", default=0, min=0, max=10000, step=1),
|
|
],
|
|
outputs=[io.Clip.Output()],
|
|
)
|
|
|
|
@classmethod
|
|
def execute(cls, clip, min_padding, min_length) -> io.NodeOutput:
|
|
clip = clip.clone()
|
|
for t5_type in ["t5xxl", "pile_t5xl", "t5base", "mt5xl", "umt5xxl"]:
|
|
clip.set_tokenizer_option("{}_min_padding".format(t5_type), min_padding)
|
|
clip.set_tokenizer_option("{}_min_length".format(t5_type), min_length)
|
|
|
|
return io.NodeOutput(clip)
|
|
|
|
|
|
NODES_LIST: list[type[io.ComfyNode]] = [
|
|
CLIPTextEncodeControlnet,
|
|
T5TokenizerOptions,
|
|
]
|