Spaces:
Runtime error
Runtime error
Nef Caballero
commited on
Commit
·
c95cb7c
1
Parent(s):
be23175
fix attempt for missing custom nodes error
Browse files- .gitignore +1 -1
- custom_nodes/example_node.py.example +155 -0
.gitignore
CHANGED
|
@@ -5,7 +5,7 @@ __pycache__/
|
|
| 5 |
!/input/example.png
|
| 6 |
/models/
|
| 7 |
/temp/
|
| 8 |
-
/custom_nodes
|
| 9 |
!custom_nodes/example_node.py.example
|
| 10 |
extra_model_paths.yaml
|
| 11 |
/.vs
|
|
|
|
| 5 |
!/input/example.png
|
| 6 |
/models/
|
| 7 |
/temp/
|
| 8 |
+
/custom_nodes/*
|
| 9 |
!custom_nodes/example_node.py.example
|
| 10 |
extra_model_paths.yaml
|
| 11 |
/.vs
|
custom_nodes/example_node.py.example
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
IS_CHANGED:
|
| 10 |
+
optional method to control when the node is re executed.
|
| 11 |
+
|
| 12 |
+
Attributes
|
| 13 |
+
----------
|
| 14 |
+
RETURN_TYPES (`tuple`):
|
| 15 |
+
The type of each element in the output tuple.
|
| 16 |
+
RETURN_NAMES (`tuple`):
|
| 17 |
+
Optional: The name of each output in the output tuple.
|
| 18 |
+
FUNCTION (`str`):
|
| 19 |
+
The name of the entry-point method. For example, if `FUNCTION = "execute"` then it will run Example().execute()
|
| 20 |
+
OUTPUT_NODE ([`bool`]):
|
| 21 |
+
If this node is an output node that outputs a result/image from the graph. The SaveImage node is an example.
|
| 22 |
+
The backend iterates on these output nodes and tries to execute all their parents if their parent graph is properly connected.
|
| 23 |
+
Assumed to be False if not present.
|
| 24 |
+
CATEGORY (`str`):
|
| 25 |
+
The category the node should appear in the UI.
|
| 26 |
+
DEPRECATED (`bool`):
|
| 27 |
+
Indicates whether the node is deprecated. Deprecated nodes are hidden by default in the UI, but remain
|
| 28 |
+
functional in existing workflows that use them.
|
| 29 |
+
EXPERIMENTAL (`bool`):
|
| 30 |
+
Indicates whether the node is experimental. Experimental nodes are marked as such in the UI and may be subject to
|
| 31 |
+
significant changes or removal in future versions. Use with caution in production workflows.
|
| 32 |
+
execute(s) -> tuple || None:
|
| 33 |
+
The entry point method. The name of this method must be the same as the value of property `FUNCTION`.
|
| 34 |
+
For example, if `FUNCTION = "execute"` then this method's name must be `execute`, if `FUNCTION = "foo"` then it must be `foo`.
|
| 35 |
+
"""
|
| 36 |
+
def __init__(self):
|
| 37 |
+
pass
|
| 38 |
+
|
| 39 |
+
@classmethod
|
| 40 |
+
def INPUT_TYPES(s):
|
| 41 |
+
"""
|
| 42 |
+
Return a dictionary which contains config for all input fields.
|
| 43 |
+
Some types (string): "MODEL", "VAE", "CLIP", "CONDITIONING", "LATENT", "IMAGE", "INT", "STRING", "FLOAT".
|
| 44 |
+
Input types "INT", "STRING" or "FLOAT" are special values for fields on the node.
|
| 45 |
+
The type can be a list for selection.
|
| 46 |
+
|
| 47 |
+
Returns: `dict`:
|
| 48 |
+
- Key input_fields_group (`string`): Can be either required, hidden or optional. A node class must have property `required`
|
| 49 |
+
- Value input_fields (`dict`): Contains input fields config:
|
| 50 |
+
* Key field_name (`string`): Name of a entry-point method's argument
|
| 51 |
+
* Value field_config (`tuple`):
|
| 52 |
+
+ First value is a string indicate the type of field or a list for selection.
|
| 53 |
+
+ Second value is a config for type "INT", "STRING" or "FLOAT".
|
| 54 |
+
"""
|
| 55 |
+
return {
|
| 56 |
+
"required": {
|
| 57 |
+
"image": ("IMAGE",),
|
| 58 |
+
"int_field": ("INT", {
|
| 59 |
+
"default": 0,
|
| 60 |
+
"min": 0, #Minimum value
|
| 61 |
+
"max": 4096, #Maximum value
|
| 62 |
+
"step": 64, #Slider's step
|
| 63 |
+
"display": "number", # Cosmetic only: display as "number" or "slider"
|
| 64 |
+
"lazy": True # Will only be evaluated if check_lazy_status requires it
|
| 65 |
+
}),
|
| 66 |
+
"float_field": ("FLOAT", {
|
| 67 |
+
"default": 1.0,
|
| 68 |
+
"min": 0.0,
|
| 69 |
+
"max": 10.0,
|
| 70 |
+
"step": 0.01,
|
| 71 |
+
"round": 0.001, #The value representing the precision to round to, will be set to the step value by default. Can be set to False to disable rounding.
|
| 72 |
+
"display": "number",
|
| 73 |
+
"lazy": True
|
| 74 |
+
}),
|
| 75 |
+
"print_to_screen": (["enable", "disable"],),
|
| 76 |
+
"string_field": ("STRING", {
|
| 77 |
+
"multiline": False, #True if you want the field to look like the one on the ClipTextEncode node
|
| 78 |
+
"default": "Hello World!",
|
| 79 |
+
"lazy": True
|
| 80 |
+
}),
|
| 81 |
+
},
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
RETURN_TYPES = ("IMAGE",)
|
| 85 |
+
#RETURN_NAMES = ("image_output_name",)
|
| 86 |
+
|
| 87 |
+
FUNCTION = "test"
|
| 88 |
+
|
| 89 |
+
#OUTPUT_NODE = False
|
| 90 |
+
|
| 91 |
+
CATEGORY = "Example"
|
| 92 |
+
|
| 93 |
+
def check_lazy_status(self, image, string_field, int_field, float_field, print_to_screen):
|
| 94 |
+
"""
|
| 95 |
+
Return a list of input names that need to be evaluated.
|
| 96 |
+
|
| 97 |
+
This function will be called if there are any lazy inputs which have not yet been
|
| 98 |
+
evaluated. As long as you return at least one field which has not yet been evaluated
|
| 99 |
+
(and more exist), this function will be called again once the value of the requested
|
| 100 |
+
field is available.
|
| 101 |
+
|
| 102 |
+
Any evaluated inputs will be passed as arguments to this function. Any unevaluated
|
| 103 |
+
inputs will have the value None.
|
| 104 |
+
"""
|
| 105 |
+
if print_to_screen == "enable":
|
| 106 |
+
return ["int_field", "float_field", "string_field"]
|
| 107 |
+
else:
|
| 108 |
+
return []
|
| 109 |
+
|
| 110 |
+
def test(self, image, string_field, int_field, float_field, print_to_screen):
|
| 111 |
+
if print_to_screen == "enable":
|
| 112 |
+
print(f"""Your input contains:
|
| 113 |
+
string_field aka input text: {string_field}
|
| 114 |
+
int_field: {int_field}
|
| 115 |
+
float_field: {float_field}
|
| 116 |
+
""")
|
| 117 |
+
#do some processing on the image, in this example I just invert it
|
| 118 |
+
image = 1.0 - image
|
| 119 |
+
return (image,)
|
| 120 |
+
|
| 121 |
+
"""
|
| 122 |
+
The node will always be re executed if any of the inputs change but
|
| 123 |
+
this method can be used to force the node to execute again even when the inputs don't change.
|
| 124 |
+
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
|
| 125 |
+
executed, if it is different the node will be executed again.
|
| 126 |
+
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
|
| 127 |
+
changes between executions the LoadImage node is executed again.
|
| 128 |
+
"""
|
| 129 |
+
#@classmethod
|
| 130 |
+
#def IS_CHANGED(s, image, string_field, int_field, float_field, print_to_screen):
|
| 131 |
+
# return ""
|
| 132 |
+
|
| 133 |
+
# Set the web directory, any .js file in that directory will be loaded by the frontend as a frontend extension
|
| 134 |
+
# WEB_DIRECTORY = "./somejs"
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
# Add custom API routes, using router
|
| 138 |
+
from aiohttp import web
|
| 139 |
+
from server import PromptServer
|
| 140 |
+
|
| 141 |
+
@PromptServer.instance.routes.get("/hello")
|
| 142 |
+
async def get_hello(request):
|
| 143 |
+
return web.json_response("hello")
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
# A dictionary that contains all nodes you want to export with their names
|
| 147 |
+
# NOTE: names should be globally unique
|
| 148 |
+
NODE_CLASS_MAPPINGS = {
|
| 149 |
+
"Example": Example
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
# A dictionary that contains the friendly/humanly readable titles for the nodes
|
| 153 |
+
NODE_DISPLAY_NAME_MAPPINGS = {
|
| 154 |
+
"Example": "Example Node"
|
| 155 |
+
}
|