Skip to content

Commit 065d855

Browse files
authored
upstream Preview Any from rgthree-comfy (comfyanonymous#7815)
* upstream Preview Any from rgthree-comfy * use IO.ANY
1 parent 5304945 commit 065d855

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

comfy_extras/nodes_preview_any.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import json
2+
from comfy.comfy_types.node_typing import IO
3+
4+
# Preview Any - original implement from
5+
# https://github.com/rgthree/rgthree-comfy/blob/main/py/display_any.py
6+
# upstream requested in https://github.com/Kosinkadink/rfcs/blob/main/rfcs/0000-corenodes.md#preview-nodes
7+
class PreviewAny():
8+
@classmethod
9+
def INPUT_TYPES(cls):
10+
return {
11+
"required": {"source": (IO.ANY, {})},
12+
}
13+
14+
RETURN_TYPES = ()
15+
FUNCTION = "main"
16+
OUTPUT_NODE = True
17+
18+
CATEGORY = "utils"
19+
20+
def main(self, source=None):
21+
value = 'None'
22+
if isinstance(source, str):
23+
value = source
24+
elif isinstance(source, (int, float, bool)):
25+
value = str(source)
26+
elif source is not None:
27+
try:
28+
value = json.dumps(source)
29+
except Exception:
30+
try:
31+
value = str(source)
32+
except Exception:
33+
value = 'source exists, but could not be serialized.'
34+
35+
return {"ui": {"text": (value,)}}
36+
37+
NODE_CLASS_MAPPINGS = {
38+
"PreviewAny": PreviewAny,
39+
}
40+
41+
NODE_DISPLAY_NAME_MAPPINGS = {
42+
"PreviewAny": "Preview Any",
43+
}

nodes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,7 @@ def init_builtin_extra_nodes():
22582258
"nodes_optimalsteps.py",
22592259
"nodes_hidream.py",
22602260
"nodes_fresca.py",
2261+
"nodes_preview_any.py",
22612262
]
22622263

22632264
api_nodes_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_api_nodes")

0 commit comments

Comments
 (0)