mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-07-27 16:26:39 +00:00
80 lines
3.0 KiB
Python
80 lines
3.0 KiB
Python
from __future__ import annotations
|
|
|
|
import nodes
|
|
from comfy_api.v3 import io
|
|
|
|
|
|
class CLIPTextEncodeSDXL(io.ComfyNodeV3):
|
|
@classmethod
|
|
def define_schema(cls):
|
|
return io.SchemaV3(
|
|
node_id="CLIPTextEncodeSDXL_V3",
|
|
category="advanced/conditioning",
|
|
inputs=[
|
|
io.Clip.Input("clip"),
|
|
io.Int.Input("width", default=1024, min=0, max=nodes.MAX_RESOLUTION),
|
|
io.Int.Input("height", default=1024, min=0, max=nodes.MAX_RESOLUTION),
|
|
io.Int.Input("crop_w", default=0, min=0, max=nodes.MAX_RESOLUTION),
|
|
io.Int.Input("crop_h", default=0, min=0, max=nodes.MAX_RESOLUTION),
|
|
io.Int.Input("target_width", default=1024, min=0, max=nodes.MAX_RESOLUTION),
|
|
io.Int.Input("target_height", default=1024, min=0, max=nodes.MAX_RESOLUTION),
|
|
io.String.Input("text_g", multiline=True, dynamic_prompts=True),
|
|
io.String.Input("text_l", multiline=True, dynamic_prompts=True),
|
|
],
|
|
outputs=[io.Conditioning.Output()],
|
|
)
|
|
|
|
@classmethod
|
|
def execute(cls, clip, width, height, crop_w, crop_h, target_width, target_height, text_g, text_l) -> io.NodeOutput:
|
|
tokens = clip.tokenize(text_g)
|
|
tokens["l"] = clip.tokenize(text_l)["l"]
|
|
if len(tokens["l"]) != len(tokens["g"]):
|
|
empty = clip.tokenize("")
|
|
while len(tokens["l"]) < len(tokens["g"]):
|
|
tokens["l"] += empty["l"]
|
|
while len(tokens["l"]) > len(tokens["g"]):
|
|
tokens["g"] += empty["g"]
|
|
conditioning = clip.encode_from_tokens_scheduled(
|
|
tokens,
|
|
add_dict={
|
|
"width": width,
|
|
"height": height,
|
|
"crop_w": crop_w,
|
|
"crop_h": crop_h,
|
|
"target_width": target_width,
|
|
"target_height": target_height,
|
|
},
|
|
)
|
|
return io.NodeOutput(conditioning)
|
|
|
|
|
|
class CLIPTextEncodeSDXLRefiner(io.ComfyNodeV3):
|
|
@classmethod
|
|
def define_schema(cls):
|
|
return io.SchemaV3(
|
|
node_id="CLIPTextEncodeSDXLRefiner_V3",
|
|
category="advanced/conditioning",
|
|
inputs=[
|
|
io.Float.Input("ascore", default=6.0, min=0.0, max=1000.0, step=0.01),
|
|
io.Int.Input("width", default=1024, min=0, max=nodes.MAX_RESOLUTION),
|
|
io.Int.Input("height", default=1024, min=0, max=nodes.MAX_RESOLUTION),
|
|
io.String.Input("text", multiline=True, dynamic_prompts=True),
|
|
io.Clip.Input("clip"),
|
|
],
|
|
outputs=[io.Conditioning.Output()],
|
|
)
|
|
|
|
@classmethod
|
|
def execute(cls, ascore, width, height, text, clip) -> io.NodeOutput:
|
|
tokens = clip.tokenize(text)
|
|
conditioning = clip.encode_from_tokens_scheduled(
|
|
tokens, add_dict={"aesthetic_score": ascore, "width": width, "height": height}
|
|
)
|
|
return io.NodeOutput(conditioning)
|
|
|
|
|
|
NODES_LIST = [
|
|
CLIPTextEncodeSDXL,
|
|
CLIPTextEncodeSDXLRefiner,
|
|
]
|