-
Notifications
You must be signed in to change notification settings - Fork 4
/
__init__.py
366 lines (322 loc) · 10.4 KB
/
__init__.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
def do_install():
import importlib, os
spec = importlib.util.spec_from_file_location("unprompted_install", os.path.join(os.path.dirname(__file__), "install.py"))
unprompted_install = importlib.util.module_from_spec(spec)
spec.loader.exec_module(unprompted_install)
do_install()
# Prep main object
import inspect, os, sys, time
import unprompted.lib_unprompted.shared
module_path = os.path.dirname(os.path.dirname(inspect.getfile(unprompted.lib_unprompted.shared.Unprompted)))
# Add the directory to your system's path
sys.path.insert(0, f"{module_path}")
Unprompted = unprompted.lib_unprompted.shared.Unprompted(module_path)
Unprompted.webui = "comfy"
Unprompted.NODE_VERSION = "0.3.0"
class UnpromptedNode:
"""
A example node
Class methods
-------------
INPUT_TYPES (dict):
Tell the main program input parameters of nodes.
IS_CHANGED:
optional method to control when the node is re executed.
Attributes
----------
RETURN_TYPES (`tuple`):
The type of each element in the output tulple.
RETURN_NAMES (`tuple`):
Optional: The name of each output in the output tulple.
FUNCTION (`str`):
The name of the entry-point method. For example, if `FUNCTION = "execute"` then it will run Example().execute()
OUTPUT_NODE ([`bool`]):
If this node is an output node that outputs a result/image from the graph. The SaveImage node is an example.
The backend iterates on these output nodes and tries to execute all their parents if their parent graph is properly connected.
Assumed to be False if not present.
CATEGORY (`str`):
The category the node should appear in the UI.
execute(s) -> tuple || None:
The entry point method. The name of this method must be the same as the value of property `FUNCTION`.
For example, if `FUNCTION = "execute"` then this method's name must be `execute`, if `FUNCTION = "foo"` then it must be `foo`.
"""
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
# wildcard trick is taken from pythongossss's
class AnyType(str):
def __ne__(self, __value: object) -> bool:
return False
"""
Return a dictionary which contains config for all input fields.
"""
return {
"required": {
"string_field": (
"STRING",
{
"multiline": True, # True if you want the field to look like the one on the ClipTextEncode node
}),
},
"optional": {
"anything": (AnyType("*"), {
"default": None
}),
"set_anything_to": ("STRING", {
"default": "comfy_var"
}),
"return_image_var": ("STRING", {
"default": "comfy_var",
}),
"always_rerun": ("BOOLEAN", {
"default": False
}),
"goodbye_routines": ("BOOLEAN", {
"default": False
}),
"string_prefix": ("STRING", {
"forceInput": True,
"default": ""
}),
"string_suffix": ("STRING", {
"forceInput": True,
"default": ""
}),
}
}
RETURN_TYPES = (
"STRING",
"IMAGE",
)
#RETURN_NAMES = ("image_output_name",)
FUNCTION = "do_unprompted"
#OUTPUT_NODE = False
CATEGORY = "unprompted"
def do_unprompted(self, **kwargs):
if kwargs.get("anything") is not None:
Unprompted.shortcode_user_vars[kwargs.get("set_anything_to")] = kwargs.get("anything")
result = Unprompted.start(kwargs.get("string_prefix", "") + kwargs.get("string_field", "") + kwargs.get("string_suffix", ""))
image_result = None
if kwargs.get("return_image_var"):
image_var = kwargs.get("return_image_var")
if image_var in Unprompted.shortcode_user_vars:
image_result = Unprompted.shortcode_user_vars[image_var]
if kwargs.get("goodbye_routines"):
# Cleanup routines
Unprompted.shortcode_user_vars = {}
Unprompted.cleanup()
Unprompted.goodbye()
return (
result,
image_result,
)
"""
The node will always be re executed if any of the inputs change but
this method can be used to force the node to execute again even when the inputs don't change.
You can make this node return a number or a string. This value will be compared to the one returned the last time the node was
executed, if it is different the node will be executed again.
This method is used in the core repo for the LoadImage node where they return the image hash as a string, if the image hash
changes between executions the LoadImage node is executed again.
"""
#@classmethod
def IS_CHANGED(**kwargs):
if kwargs.get("always_rerun") is True:
return str(time.time())
class UnpromptedSetRack:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
# wildcard trick is taken from pythongossss's
class AnyType(str):
def __ne__(self, __value: object) -> bool:
return False
"""
Return a dictionary which contains config for all input fields.
"""
return {
"optional": {
"input_a": (AnyType("*"), {
"default": None
}),
"input_b": (AnyType("*"), {
"default": None
}),
"input_c": (AnyType("*"), {
"default": None
}),
"input_d": (AnyType("*"), {
"default": None
}),
"input_e": (AnyType("*"), {
"default": None
}),
"input_f": (AnyType("*"), {
"default": None
}),
"input_g": (AnyType("*"), {
"default": None
}),
"input_h": (AnyType("*"), {
"default": None
}),
"input_i": (AnyType("*"), {
"default": None
}),
"input_j": (AnyType("*"), {
"default": None
}),
"input_k": (AnyType("*"), {
"default": None
}),
"input_l": (AnyType("*"), {
"default": None
}),
"input_m": (AnyType("*"), {
"default": None
}),
"input_n": (AnyType("*"), {
"default": None
}),
"input_o": (AnyType("*"), {
"default": None
}),
"input_p": (AnyType("*"), {
"default": None
}),
"input_q": (AnyType("*"), {
"default": None
}),
"input_r": (AnyType("*"), {
"default": None
}),
"input_s": (AnyType("*"), {
"default": None
}),
"input_t": (AnyType("*"), {
"default": None
}),
"input_u": (AnyType("*"), {
"default": None
}),
"input_v": (AnyType("*"), {
"default": None
}),
"input_w": (AnyType("*"), {
"default": None
}),
"input_x": (AnyType("*"), {
"default": None
}),
"input_y": (AnyType("*"), {
"default": None
}),
"input_z": (AnyType("*"), {
"default": None
}),
"var_a": ("STRING", {
"default": "var_a"
}),
"var_b": ("STRING", {
"default": "var_b"
}),
"var_c": ("STRING", {
"default": "var_c"
}),
"var_d": ("STRING", {
"default": "var_d"
}),
"var_e": ("STRING", {
"default": "var_e"
}),
"var_f": ("STRING", {
"default": "var_f"
}),
"var_g": ("STRING", {
"default": "var_g"
}),
"var_h": ("STRING", {
"default": "var_h"
}),
"var_i": ("STRING", {
"default": "var_i"
}),
"var_j": ("STRING", {
"default": "var_j"
}),
"var_k": ("STRING", {
"default": "var_k"
}),
"var_l": ("STRING", {
"default": "var_l"
}),
"var_m": ("STRING", {
"default": "var_m"
}),
"var_n": ("STRING", {
"default": "var_n"
}),
"var_o": ("STRING", {
"default": "var_o"
}),
"var_p": ("STRING", {
"default": "var_p"
}),
"var_q": ("STRING", {
"default": "var_q"
}),
"var_r": ("STRING", {
"default": "var_r"
}),
"var_s": ("STRING", {
"default": "var_s"
}),
"var_t": ("STRING", {
"default": "var_t"
}),
"var_u": ("STRING", {
"default": "var_u"
}),
"var_v": ("STRING", {
"default": "var_v"
}),
"var_w": ("STRING", {
"default": "var_w"
}),
"var_x": ("STRING", {
"default": "var_x"
}),
"var_y": ("STRING", {
"default": "var_y"
}),
"var_z": ("STRING", {
"default": "var_z"
}),
}
}
CATEGORY = "unprompted"
RETURN_TYPES = ("STRING", )
#RETURN_NAMES = ("image_output_name",)
FUNCTION = "set_unprompted"
def set_unprompted(self, **kwargs):
for key in ["input_a", "input_b", "input_c", "input_d", "input_e", "input_f", "input_g", "input_h", "input_i", "input_j", "input_k", "input_l", "input_m", "input_n", "input_o", "input_p", "input_q", "input_r", "input_s", "input_t", "input_u", "input_v", "input_w", "input_x", "input_y", "input_z"]:
# Match the input to the var
if kwargs.get(key) is not None:
Unprompted.shortcode_user_vars[kwargs.get(f"var_{key[-1]}")] = kwargs.get(key)
image_result = None
if kwargs.get("return_image_var"):
image_var = kwargs.get("return_image_var")
if image_var in Unprompted.shortcode_user_vars:
image_result = Unprompted.shortcode_user_vars[image_var]
return ("")
# Set the web directory, any .js file in that directory will be loaded by the frontend as a frontend extension
# WEB_DIRECTORY = "./somejs"
# A dictionary that contains all nodes you want to export with their names
# NOTE: names should be globally unique
NODE_CLASS_MAPPINGS = {
"Unprompted": UnpromptedNode,
"UnpromptedSetRack": UnpromptedSetRack,
}
# A dictionary that contains the friendly/humanly readable titles for the nodes
NODE_DISPLAY_NAME_MAPPINGS = {"Unprompted": f"Unprompted v{Unprompted.NODE_VERSION}", "UnpromptedSetRack": "Set Variable Rack"}