1
- from nodes import MAX_RESOLUTION
1
+ from typing_extensions import override
2
2
3
- class CLIPTextEncodeSDXLRefiner :
3
+ import nodes
4
+ from comfy_api .latest import ComfyExtension , io
5
+
6
+
7
+ class CLIPTextEncodeSDXLRefiner (io .ComfyNode ):
4
8
@classmethod
5
- def INPUT_TYPES (s ):
6
- return {"required" : {
7
- "ascore" : ("FLOAT" , {"default" : 6.0 , "min" : 0.0 , "max" : 1000.0 , "step" : 0.01 }),
8
- "width" : ("INT" , {"default" : 1024.0 , "min" : 0 , "max" : MAX_RESOLUTION }),
9
- "height" : ("INT" , {"default" : 1024.0 , "min" : 0 , "max" : MAX_RESOLUTION }),
10
- "text" : ("STRING" , {"multiline" : True , "dynamicPrompts" : True }), "clip" : ("CLIP" , ),
11
- }}
12
- RETURN_TYPES = ("CONDITIONING" ,)
13
- FUNCTION = "encode"
14
-
15
- CATEGORY = "advanced/conditioning"
16
-
17
- def encode (self , clip , ascore , width , height , text ):
9
+ def define_schema (cls ):
10
+ return io .Schema (
11
+ node_id = "CLIPTextEncodeSDXLRefiner" ,
12
+ category = "advanced/conditioning" ,
13
+ inputs = [
14
+ io .Float .Input ("ascore" , default = 6.0 , min = 0.0 , max = 1000.0 , step = 0.01 ),
15
+ io .Int .Input ("width" , default = 1024 , min = 0 , max = nodes .MAX_RESOLUTION ),
16
+ io .Int .Input ("height" , default = 1024 , min = 0 , max = nodes .MAX_RESOLUTION ),
17
+ io .String .Input ("text" , multiline = True , dynamic_prompts = True ),
18
+ io .Clip .Input ("clip" ),
19
+ ],
20
+ outputs = [io .Conditioning .Output ()],
21
+ )
22
+
23
+ @classmethod
24
+ def execute (cls , clip , ascore , width , height , text ) -> io .NodeOutput :
18
25
tokens = clip .tokenize (text )
19
- return (clip .encode_from_tokens_scheduled (tokens , add_dict = {"aesthetic_score" : ascore , "width" : width , "height" : height }), )
26
+ return io . NodeOutput (clip .encode_from_tokens_scheduled (tokens , add_dict = {"aesthetic_score" : ascore , "width" : width , "height" : height }))
20
27
21
- class CLIPTextEncodeSDXL :
28
+ class CLIPTextEncodeSDXL ( io . ComfyNode ) :
22
29
@classmethod
23
- def INPUT_TYPES (s ):
24
- return {"required" : {
25
- "clip" : ("CLIP" , ),
26
- "width" : ("INT" , {"default" : 1024.0 , "min" : 0 , "max" : MAX_RESOLUTION }),
27
- "height" : ("INT" , {"default" : 1024.0 , "min" : 0 , "max" : MAX_RESOLUTION }),
28
- "crop_w" : ("INT" , {"default" : 0 , "min" : 0 , "max" : MAX_RESOLUTION }),
29
- "crop_h" : ("INT" , {"default" : 0 , "min" : 0 , "max" : MAX_RESOLUTION }),
30
- "target_width" : ("INT" , {"default" : 1024.0 , "min" : 0 , "max" : MAX_RESOLUTION }),
31
- "target_height" : ("INT" , {"default" : 1024.0 , "min" : 0 , "max" : MAX_RESOLUTION }),
32
- "text_g" : ("STRING" , {"multiline" : True , "dynamicPrompts" : True }),
33
- "text_l" : ("STRING" , {"multiline" : True , "dynamicPrompts" : True }),
34
- }}
35
- RETURN_TYPES = ("CONDITIONING" ,)
36
- FUNCTION = "encode"
37
-
38
- CATEGORY = "advanced/conditioning"
39
-
40
- def encode (self , clip , width , height , crop_w , crop_h , target_width , target_height , text_g , text_l ):
30
+ def define_schema (cls ):
31
+ return io .Schema (
32
+ node_id = "CLIPTextEncodeSDXL" ,
33
+ category = "advanced/conditioning" ,
34
+ inputs = [
35
+ io .Clip .Input ("clip" ),
36
+ io .Int .Input ("width" , default = 1024 , min = 0 , max = nodes .MAX_RESOLUTION ),
37
+ io .Int .Input ("height" , default = 1024 , min = 0 , max = nodes .MAX_RESOLUTION ),
38
+ io .Int .Input ("crop_w" , default = 0 , min = 0 , max = nodes .MAX_RESOLUTION ),
39
+ io .Int .Input ("crop_h" , default = 0 , min = 0 , max = nodes .MAX_RESOLUTION ),
40
+ io .Int .Input ("target_width" , default = 1024 , min = 0 , max = nodes .MAX_RESOLUTION ),
41
+ io .Int .Input ("target_height" , default = 1024 , min = 0 , max = nodes .MAX_RESOLUTION ),
42
+ io .String .Input ("text_g" , multiline = True , dynamic_prompts = True ),
43
+ io .String .Input ("text_l" , multiline = True , dynamic_prompts = True ),
44
+ ],
45
+ outputs = [io .Conditioning .Output ()],
46
+ )
47
+
48
+ @classmethod
49
+ def execute (cls , clip , width , height , crop_w , crop_h , target_width , target_height , text_g , text_l ) -> io .NodeOutput :
41
50
tokens = clip .tokenize (text_g )
42
51
tokens ["l" ] = clip .tokenize (text_l )["l" ]
43
52
if len (tokens ["l" ]) != len (tokens ["g" ]):
@@ -46,9 +55,17 @@ def encode(self, clip, width, height, crop_w, crop_h, target_width, target_heigh
46
55
tokens ["l" ] += empty ["l" ]
47
56
while len (tokens ["l" ]) > len (tokens ["g" ]):
48
57
tokens ["g" ] += empty ["g" ]
49
- return (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 }), )
58
+ return io .NodeOutput (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 }))
59
+
60
+
61
+ class ClipSdxlExtension (ComfyExtension ):
62
+ @override
63
+ async def get_node_list (self ) -> list [type [io .ComfyNode ]]:
64
+ return [
65
+ CLIPTextEncodeSDXLRefiner ,
66
+ CLIPTextEncodeSDXL ,
67
+ ]
68
+
50
69
51
- NODE_CLASS_MAPPINGS = {
52
- "CLIPTextEncodeSDXLRefiner" : CLIPTextEncodeSDXLRefiner ,
53
- "CLIPTextEncodeSDXL" : CLIPTextEncodeSDXL ,
54
- }
70
+ async def comfy_entrypoint () -> ClipSdxlExtension :
71
+ return ClipSdxlExtension ()
0 commit comments