From 24ea1de497a9dc0abee30f8a78c3b5156434b4fd Mon Sep 17 00:00:00 2001 From: jstit Date: Thu, 16 Jan 2025 10:20:47 +0700 Subject: [PATCH] first commit --- __init__.py | 4 +- nodes/agenticflow_ai_variable.py | 77 ++++++++++++++++++++++++++++++++ nodes/image_crop_circle.py | 58 ------------------------ requirements.txt | 3 +- 4 files changed, 81 insertions(+), 61 deletions(-) create mode 100644 nodes/agenticflow_ai_variable.py delete mode 100644 nodes/image_crop_circle.py diff --git a/__init__.py b/__init__.py index 6b3f3a7..4ff3106 100644 --- a/__init__.py +++ b/__init__.py @@ -1,7 +1,7 @@ from .nodes import ( - image_crop_circle, + agenticflow_ai_variable, ) NODE_CLASS_MAPPINGS = { - **image_crop_circle.NODE_CLASS_MAPPINGS, + **agenticflow_ai_variable.NODE_CLASS_MAPPINGS, } diff --git a/nodes/agenticflow_ai_variable.py b/nodes/agenticflow_ai_variable.py new file mode 100644 index 0000000..76ee4a1 --- /dev/null +++ b/nodes/agenticflow_ai_variable.py @@ -0,0 +1,77 @@ +import numpy as np +import torch + + +class AgenticflowAIVariable: + """A node that handles variable values and provides type conversions. + + This node takes a variable input and a fallback value, attempting to convert the input + into multiple data types (string, integer, and float). If the variable is empty or + wrapped in curly braces (indicating an unresolved variable), it uses the fallback value. + + Attributes: + INPUT_TYPES: Defines the input parameters - variable and fallback string + RETURN_TYPES: Returns the value as (string, integer, float) tuple + FUNCTION: The main processing function name + CATEGORY: Node category in the ComfyUI interface + """ + + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "variable": ( + [ + "", + ], + ), + "fallback": ( + "STRING", + { + "default": "", + "single_line": True, + }, + ), + } + } + + RETURN_TYPES = ("STRING", "INT", "FLOAT") + FUNCTION = "do_it" + + CATEGORY = "agenticflowai/variables" + + # @classmethod + # def VALIDATE_INPUTS(cls, variable: str, fallback: str): + # # Since we populate dynamically, comfy will report invalid inputs. Override to always return True + # return True + + def do_it(self, variable: str, fallback: str): + variable = variable.strip() + fallback = fallback.strip() + if variable == "" or (variable.startswith("{") and variable.endswith("}")): + variable = fallback + + int_val = 0 + float_val = 0.0 + string_val = f"{variable}" + try: + int_val = int(variable) + except Exception as _: + pass + try: + float_val = float(variable) + except Exception as _: + pass + return (string_val, int_val, float_val) + + +# A dictionary that contains all nodes you want to export with their names +# NOTE: names should be globally unique +NODE_CLASS_MAPPINGS = { + "AgenticflowAIVariable": AgenticflowAIVariable, +} + +# A dictionary that contains the friendly/humanly readable titles for the nodes +NODE_DISPLAY_NAME_MAPPINGS = { + "AgenticflowAIVariable": "AgenticflowAIVariable", +} diff --git a/nodes/image_crop_circle.py b/nodes/image_crop_circle.py deleted file mode 100644 index 7962c31..0000000 --- a/nodes/image_crop_circle.py +++ /dev/null @@ -1,58 +0,0 @@ -import numpy as np -import torch - - -class ImageCropCircle: - - @classmethod - def INPUT_TYPES(s): - return { - "required": { - "image": ("IMAGE",), - } - } - - RETURN_TYPES = ("IMAGE",) - FUNCTION = "crop_circle" - - CATEGORY = "image/crop" - - def crop_circle(self, image): - # Get dimensions from the image - _, h, w, _ = image.shape - - # Determine the size of the circle (use the smaller dimension) - size = min(h, w) - - # Calculate the crop coordinates to center the circle - x = (w - size) // 2 - y = (h - size) // 2 - - # Crop the image to a square - cropped = image[:, y : y + size, x : x + size, :] - - # Create a circular mask - center = (size // 2, size // 2) - radius = size // 2 - Y, X = np.ogrid[:size, :size] - dist_from_center = np.sqrt((X - center[0]) ** 2 + (Y - center[1]) ** 2) - mask = dist_from_center <= radius - - # Apply the mask - mask = torch.from_numpy(mask).float().unsqueeze(0).unsqueeze(-1) - mask = mask.expand_as(cropped) - result = cropped * mask - - return (result,) - - -# A dictionary that contains all nodes you want to export with their names -# NOTE: names should be globally unique -NODE_CLASS_MAPPINGS = { - "ImageCropCircle": ImageCropCircle, -} - -# A dictionary that contains the friendly/humanly readable titles for the nodes -NODE_DISPLAY_NAME_MAPPINGS = { - "ImageCropCircle": "ImageCropCircle", -} diff --git a/requirements.txt b/requirements.txt index 04747c1..454c449 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ diffusers tqdm -boto3 \ No newline at end of file +boto3 +diffusers==0.24.0 \ No newline at end of file