first commit
This commit is contained in:
+2
-2
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
@@ -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",
|
||||
}
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
diffusers
|
||||
tqdm
|
||||
boto3
|
||||
boto3
|
||||
diffusers==0.24.0
|
||||
Reference in New Issue
Block a user