forked from filliptm/ComfyUI_Fill-Nodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fl_code_node.py
33 lines (22 loc) · 943 Bytes
/
fl_code_node.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
class AlwaysEqualProxy(str):
def __eq__(self, other):
return True
def __ne__(self, other):
return False
class FL_CodeNode:
@classmethod
def INPUT_TYPES(cls):
required = {"code_input": ("STRING", {"multiline": True})}
optional = {f"input_{i}": (AlwaysEqualProxy("*")) for i in range(4)}
return {"required": required, "optional": optional}
CATEGORY = "🏵️Fill Nodes"
RETURN_TYPES = tuple(AlwaysEqualProxy("*") for _ in range(4))
RETURN_NAMES = tuple(f"output_{i}" for i in range(4))
FUNCTION = "execute"
def execute(self, code_input, **kwargs):
outputs = {i: None for i in range(4)}
try:
exec(code_input, {"inputs": kwargs, "outputs": outputs})
except Exception as e:
raise RuntimeError(f"Error executing user code: {e}")
return tuple(outputs[i] for i in range(4))