-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshortcut_nodes.py
67 lines (54 loc) · 2.27 KB
/
shortcut_nodes.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
# import numpy as np
# from PIL import Image
# from PIL.PngImagePlugin import PngInfo
# import json
from nodes import VAEDecode, SaveImage
import os
"""
NOT WORKING
"""
class SaveVAEImageNode():
"""
DECODE and show Image sample; Also export the image as an optional param to be saved
Class methods
-------------
INPUT_TYPES (dict):
Tell the main program input parameters of nodes.
Attributes
----------
RETURN_TYPES (`tuple`):
The type of each element 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, device="cpu"):
self.device = device
self.decode_handler = VAEDecode()
self.image_handler = SaveImage()
RETURN_TYPES = ()
FUNCTION = "do_decode_and_preview"
CATEGORY = "trNodes"
OUTPUT_NODE = True
@classmethod
def INPUT_TYPES(s):
return {"required": {
"samples": ("LATENT",),
"vae": ("VAE",)}
}
def _do_decode(self, vae, samples):
return (vae.decode(samples["samples"]),)
def _do_save_image(self, image, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None):
return self.image_handler.save_images(image, filename_prefix, prompt, extra_pnginfo)
def do_decode_and_preview(self, vae, samples, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None):
image = self._do_decode(vae, samples)
ui_out = self._do_save_image(image, filename_prefix, prompt, extra_pnginfo)
return (ui_out, image)