fred-dev/comfy_ui_ali
0
1class Example:2 """3 A example node4 5 Class methods6 -------------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 Attributes13 ----------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 remain28 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 to31 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 pass38 39 @classmethod40 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 argument51 * 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 value61 "max": 4096, #Maximum value62 "step": 64, #Slider's step63 "display": "number", # Cosmetic only: display as "number" or "slider"64 "lazy": True # Will only be evaluated if check_lazy_status requires it65 }),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": True74 }),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 node78 "default": "Hello World!",79 "lazy": True80 }),81 },82 }83 84 RETURN_TYPES = ("IMAGE",)85 #RETURN_NAMES = ("image_output_name",)86 87 FUNCTION = "test"88 89 #OUTPUT_NODE = False90 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 been98 evaluated. As long as you return at least one field which has not yet been evaluated99 (and more exist), this function will be called again once the value of the requested100 field is available.101 102 Any evaluated inputs will be passed as arguments to this function. Any unevaluated103 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 it118 image = 1.0 - image119 return (image,)120 121 """122 The node will always be re executed if any of the inputs change but123 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 was125 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 hash127 changes between executions the LoadImage node is executed again.128 """129 #@classmethod130 #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 extension134# WEB_DIRECTORY = "./somejs"135 136 137# Add custom API routes, using router138from aiohttp import web139from server import PromptServer140 141@PromptServer.instance.routes.get("/hello")142async 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 names147# NOTE: names should be globally unique148NODE_CLASS_MAPPINGS = {149 "Example": Example150}151 152# A dictionary that contains the friendly/humanly readable titles for the nodes153NODE_DISPLAY_NAME_MAPPINGS = {154 "Example": "Example Node"155}156 