jnkr36 commited on
Commit
97eff49
1 Parent(s): ca22ec0

Upload example_node.py.example

Browse files
custom_nodes/example_node.py.example ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class Example:
2
+ """
3
+ A example node
4
+
5
+ Class methods
6
+ -------------
7
+ INPUT_TYPES (dict):
8
+ Tell the main program input parameters of nodes.
9
+
10
+ Attributes
11
+ ----------
12
+ RETURN_TYPES (`tuple`):
13
+ The type of each element in the output tulple.
14
+ RETURN_NAMES (`tuple`):
15
+ Optional: The name of each output in the output tulple.
16
+ FUNCTION (`str`):
17
+ The name of the entry-point method. For example, if `FUNCTION = "execute"` then it will run Example().execute()
18
+ OUTPUT_NODE ([`bool`]):
19
+ If this node is an output node that outputs a result/image from the graph. The SaveImage node is an example.
20
+ The backend iterates on these output nodes and tries to execute all their parents if their parent graph is properly connected.
21
+ Assumed to be False if not present.
22
+ CATEGORY (`str`):
23
+ The category the node should appear in the UI.
24
+ execute(s) -> tuple || None:
25
+ The entry point method. The name of this method must be the same as the value of property `FUNCTION`.
26
+ For example, if `FUNCTION = "execute"` then this method's name must be `execute`, if `FUNCTION = "foo"` then it must be `foo`.
27
+ """
28
+ def __init__(self):
29
+ pass
30
+
31
+ @classmethod
32
+ def INPUT_TYPES(s):
33
+ """
34
+ Return a dictionary which contains config for all input fields.
35
+ Some types (string): "MODEL", "VAE", "CLIP", "CONDITIONING", "LATENT", "IMAGE", "INT", "STRING", "FLOAT".
36
+ Input types "INT", "STRING" or "FLOAT" are special values for fields on the node.
37
+ The type can be a list for selection.
38
+
39
+ Returns: `dict`:
40
+ - Key input_fields_group (`string`): Can be either required, hidden or optional. A node class must have property `required`
41
+ - Value input_fields (`dict`): Contains input fields config:
42
+ * Key field_name (`string`): Name of a entry-point method's argument
43
+ * Value field_config (`tuple`):
44
+ + First value is a string indicate the type of field or a list for selection.
45
+ + Secound value is a config for type "INT", "STRING" or "FLOAT".
46
+ """
47
+ return {
48
+ "required": {
49
+ "image": ("IMAGE",),
50
+ "int_field": ("INT", {
51
+ "default": 0,
52
+ "min": 0, #Minimum value
53
+ "max": 4096, #Maximum value
54
+ "step": 64 #Slider's step
55
+ }),
56
+ "float_field": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}),
57
+ "print_to_screen": (["enable", "disable"],),
58
+ "string_field": ("STRING", {
59
+ "multiline": False, #True if you want the field to look like the one on the ClipTextEncode node
60
+ "default": "Hello World!"
61
+ }),
62
+ },
63
+ }
64
+
65
+ RETURN_TYPES = ("IMAGE",)
66
+ #RETURN_NAMES = ("image_output_name",)
67
+
68
+ FUNCTION = "test"
69
+
70
+ #OUTPUT_NODE = False
71
+
72
+ CATEGORY = "Example"
73
+
74
+ def test(self, image, string_field, int_field, float_field, print_to_screen):
75
+ if print_to_screen == "enable":
76
+ print(f"""Your input contains:
77
+ string_field aka input text: {string_field}
78
+ int_field: {int_field}
79
+ float_field: {float_field}
80
+ """)
81
+ #do some processing on the image, in this example I just invert it
82
+ image = 1.0 - image
83
+ return (image,)
84
+
85
+
86
+ # A dictionary that contains all nodes you want to export with their names
87
+ # NOTE: names should be globally unique
88
+ NODE_CLASS_MAPPINGS = {
89
+ "Example": Example
90
+ }