Added Recraft Controls + Recraft Color RGB nodes (#57)

This commit is contained in:
Jedrzej Kosinski 2025-04-30 05:51:14 -05:00 committed by Robin Huang
parent 5e2962ffe5
commit b2f55ba329
2 changed files with 131 additions and 0 deletions

View File

@ -8,6 +8,68 @@ from typing import Optional
from pydantic import BaseModel, Field, conint, confloat from pydantic import BaseModel, Field, conint, confloat
class RecraftColor:
def __init__(self, r: int, g: int, b: int):
self.color = [r, g, b]
def create_api_model(self):
return RecraftColorObject(rgb=self.color)
class RecraftColorChain:
def __init__(self):
self.colors: list[RecraftColor] = []
def get_first(self):
if len(self.colors) > 0:
return self.colors[0]
return None
def add(self, color: RecraftColor):
self.colors.append(color)
def create_api_model(self):
if not self.colors:
return None
colors_api = [x.create_api_model() for x in self.colors]
return colors_api
def clone(self):
c = RecraftColorChain()
for color in self.colors:
c.add(color)
return c
def clone_and_merge(self, other: RecraftColorChain):
c = self.clone()
for color in other.colors:
c.add(color)
return c
class RecraftControls:
def __init__(self, colors: RecraftColorChain=None, background_color: RecraftColorChain=None,
artistic_level: int=None, no_text: bool=None):
self.colors = colors
self.background_color = background_color
self.artistic_level = artistic_level
self.no_text = no_text
def create_api_model(self):
if self.colors is None and self.background_color is None and self.artistic_level is None and self.no_text is None:
return None
colors_api = None
background_color_api = None
if self.colors:
colors_api = self.colors.create_api_model()
if self.background_color:
first_background = self.background_color.get_first()
background_color_api = first_background.create_api_model() if first_background else None
return RecraftControlsObject(colors=colors_api, background_color=background_color_api,
artistic_level=self.artistic_level, no_text=self.no_text)
class RecraftColor: class RecraftColor:
def __init__(self, r: int, g: int, b: int): def __init__(self, r: int, g: int, b: int):
self.color = [r, g, b] self.color = [r, g, b]

View File

@ -235,6 +235,75 @@ class RecraftControlsNode:
return (RecraftControls(colors=colors, background_color=background_color), ) return (RecraftControls(colors=colors, background_color=background_color), )
class RecraftColorRGBNode:
"""
Create Recraft Color by choosing specific RGB values.
"""
RETURN_TYPES = (RecraftIO.COLOR,)
RETURN_NAMES = ("recraft_color",)
FUNCTION = "create_color"
CATEGORY = "api node/image/Recraft"
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"r": (IO.INT, {
"default": 0,
"min": 0,
"max": 255,
"tooltip": "Red value of color."
}),
"g": (IO.INT, {
"default": 0,
"min": 0,
"max": 255,
"tooltip": "Green value of color."
}),
"b": (IO.INT, {
"default": 0,
"min": 0,
"max": 255,
"tooltip": "Blue value of color."
}),
},
"optional": {
"recraft_color": (RecraftIO.COLOR,),
}
}
def create_color(self, r: int, g: int, b: int, recraft_color: RecraftColorChain=None):
recraft_color = recraft_color.clone() if recraft_color else RecraftColorChain()
recraft_color.add(RecraftColor(r, g, b))
return (recraft_color, )
class RecraftControlsNode:
"""
Create Recraft Controls for customizing Recraft generation.
"""
RETURN_TYPES = (RecraftIO.CONTROLS,)
RETURN_NAMES = ("recraft_controls",)
FUNCTION = "create_controls"
CATEGORY = "api node/image/Recraft"
@classmethod
def INPUT_TYPES(s):
return {
"required": {
},
"optional": {
"colors": (RecraftIO.COLOR,),
"background_color": (RecraftIO.COLOR,),
}
}
def create_controls(self, colors: RecraftColorChain=None, background_color: RecraftColorChain=None):
return (RecraftControls(colors=colors, background_color=background_color), )
class RecraftStyleV3RealisticImageNode: class RecraftStyleV3RealisticImageNode:
""" """
Select realistic_image style and optional substyle. Select realistic_image style and optional substyle.