-
Notifications
You must be signed in to change notification settings - Fork 10
/
comfyui_string_list.py
151 lines (122 loc) · 3.89 KB
/
comfyui_string_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import torch
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}
def register_node(identifier: str, display_name: str):
def decorator(cls):
NODE_CLASS_MAPPINGS[identifier] = cls
NODE_DISPLAY_NAME_MAPPINGS[identifier] = display_name
return cls
return decorator
@register_node("JWStringListFromString", "String List From String")
class _:
CATEGORY = "jamesWalker55"
INPUT_TYPES = lambda: {
"required": {
"value": ("STRING", {"default": "", "multiline": False}),
}
}
RETURN_TYPES = ("STRING_LIST",)
FUNCTION = "execute"
def execute(self, value: str):
val = [value]
return (val,)
@register_node("JWStringListFromStrings", "String List From Strings")
class _:
CATEGORY = "jamesWalker55"
INPUT_TYPES = lambda: {
"required": {
"a": ("STRING", {"default": "", "multiline": False}),
"b": ("STRING", {"default": "", "multiline": False}),
}
}
RETURN_TYPES = ("STRING_LIST",)
FUNCTION = "execute"
def execute(self, a: str, b: str):
val = [a, b]
return (val,)
@register_node("JWStringListJoin", "Join String List")
class _:
CATEGORY = "jamesWalker55"
INPUT_TYPES = lambda: {
"required": {
"a": ("STRING_LIST",),
"b": ("STRING_LIST",),
}
}
RETURN_TYPES = ("STRING_LIST",)
FUNCTION = "execute"
def execute(self, a: list[str], b: list[str]):
val = a + b
return (val,)
@register_node("JWStringListRepeat", "Repeat String List")
class _:
CATEGORY = "jamesWalker55"
INPUT_TYPES = lambda: {
"required": {
"string_list": ("STRING_LIST",),
"repeats": ("INT", {"default": 1, "min": 0}),
}
}
RETURN_TYPES = ("STRING_LIST",)
FUNCTION = "execute"
def execute(self, string_list: list[str], repeats: int):
val = string_list * repeats
return (val,)
@register_node("JWStringListToString", "String List To String")
class _:
CATEGORY = "jamesWalker55"
INPUT_TYPES = lambda: {
"required": {
"string_list": ("STRING_LIST",),
"join": (
"STRING",
{"default": "\n", "multiline": True, "dynamicPrompts": False},
),
}
}
RETURN_TYPES = ("STRING",)
FUNCTION = "execute"
def execute(self, string_list: list[str], join: str):
val = join.join(string_list)
return (val,)
@register_node("JWStringListToFormatedString", "String List To Formatted String")
class _:
CATEGORY = "jamesWalker55"
INPUT_TYPES = lambda: {
"required": {
"string_list": ("STRING_LIST",),
"template": (
"STRING",
{"default": "{}, {}, {}", "multiline": True, "dynamicPrompts": False},
),
}
}
RETURN_TYPES = ("STRING",)
FUNCTION = "execute"
def execute(self, string_list: list[str], join: str):
val = join.join(string_list)
return (val,)
@register_node("JWStringListCLIPEncode", "String List CLIP Encode")
class _:
CATEGORY = "jamesWalker55"
INPUT_TYPES = lambda: {
"required": {
"string_list": ("STRING_LIST",),
"clip": ("CLIP",),
}
}
RETURN_TYPES = ("CONDITIONING",)
FUNCTION = "execute"
def execute(self, string_list: list[str], clip):
all_cond = []
all_pooled = []
for text in string_list:
tokens = clip.tokenize(text)
cond, pooled = clip.encode_from_tokens(tokens, return_pooled=True)
# cond.shape => torch.Size([1, 77, 768])
# pooled.shape => torch.Size([1, 768])
all_cond.append(cond)
all_pooled.append(pooled)
all_cond = torch.cat(all_cond, dim=0)
all_pooled = torch.cat(all_pooled, dim=0)
return ([[all_cond, {"pooled_output": all_pooled}]],)