mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-09-10 19:46:38 +00:00
convert nodes_stability.py to V3 schema (#9497)
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
from inspect import cleandoc
|
from inspect import cleandoc
|
||||||
from comfy.comfy_types.node_typing import IO
|
from typing import Optional
|
||||||
|
from typing_extensions import override
|
||||||
|
|
||||||
|
from comfy_api.latest import ComfyExtension, io as comfy_io
|
||||||
from comfy_api_nodes.apis.stability_api import (
|
from comfy_api_nodes.apis.stability_api import (
|
||||||
StabilityUpscaleConservativeRequest,
|
StabilityUpscaleConservativeRequest,
|
||||||
StabilityUpscaleCreativeRequest,
|
StabilityUpscaleCreativeRequest,
|
||||||
@@ -46,87 +49,94 @@ def get_async_dummy_status(x: StabilityResultsGetResponse):
|
|||||||
return StabilityPollStatus.in_progress
|
return StabilityPollStatus.in_progress
|
||||||
|
|
||||||
|
|
||||||
class StabilityStableImageUltraNode:
|
class StabilityStableImageUltraNode(comfy_io.ComfyNode):
|
||||||
"""
|
"""
|
||||||
Generates images synchronously based on prompt and resolution.
|
Generates images synchronously based on prompt and resolution.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RETURN_TYPES = (IO.IMAGE,)
|
|
||||||
DESCRIPTION = cleandoc(__doc__ or "") # Handle potential None value
|
|
||||||
FUNCTION = "api_call"
|
|
||||||
API_NODE = True
|
|
||||||
CATEGORY = "api node/image/Stability AI"
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def define_schema(cls):
|
||||||
return {
|
return comfy_io.Schema(
|
||||||
"required": {
|
node_id="StabilityStableImageUltraNode",
|
||||||
"prompt": (
|
display_name="Stability AI Stable Image Ultra",
|
||||||
IO.STRING,
|
category="api node/image/Stability AI",
|
||||||
{
|
description=cleandoc(cls.__doc__ or ""),
|
||||||
"multiline": True,
|
inputs=[
|
||||||
"default": "",
|
comfy_io.String.Input(
|
||||||
"tooltip": "What you wish to see in the output image. A strong, descriptive prompt that clearly defines" +
|
"prompt",
|
||||||
"What you wish to see in the output image. A strong, descriptive prompt that clearly defines" +
|
multiline=True,
|
||||||
|
default="",
|
||||||
|
tooltip="What you wish to see in the output image. A strong, descriptive prompt that clearly defines" +
|
||||||
"elements, colors, and subjects will lead to better results. " +
|
"elements, colors, and subjects will lead to better results. " +
|
||||||
"To control the weight of a given word use the format `(word:weight)`," +
|
"To control the weight of a given word use the format `(word:weight)`," +
|
||||||
"where `word` is the word you'd like to control the weight of and `weight`" +
|
"where `word` is the word you'd like to control the weight of and `weight`" +
|
||||||
"is a value between 0 and 1. For example: `The sky was a crisp (blue:0.3) and (green:0.8)`" +
|
"is a value between 0 and 1. For example: `The sky was a crisp (blue:0.3) and (green:0.8)`" +
|
||||||
"would convey a sky that was blue and green, but more green than blue."
|
"would convey a sky that was blue and green, but more green than blue.",
|
||||||
},
|
|
||||||
),
|
),
|
||||||
"aspect_ratio": ([x.value for x in StabilityAspectRatio],
|
comfy_io.Combo.Input(
|
||||||
{
|
"aspect_ratio",
|
||||||
"default": StabilityAspectRatio.ratio_1_1,
|
options=[x.value for x in StabilityAspectRatio],
|
||||||
"tooltip": "Aspect ratio of generated image.",
|
default=StabilityAspectRatio.ratio_1_1.value,
|
||||||
},
|
tooltip="Aspect ratio of generated image.",
|
||||||
),
|
),
|
||||||
"style_preset": (get_stability_style_presets(),
|
comfy_io.Combo.Input(
|
||||||
{
|
"style_preset",
|
||||||
"tooltip": "Optional desired style of generated image.",
|
options=get_stability_style_presets(),
|
||||||
},
|
tooltip="Optional desired style of generated image.",
|
||||||
),
|
),
|
||||||
"seed": (
|
comfy_io.Int.Input(
|
||||||
IO.INT,
|
"seed",
|
||||||
{
|
default=0,
|
||||||
"default": 0,
|
min=0,
|
||||||
"min": 0,
|
max=4294967294,
|
||||||
"max": 4294967294,
|
step=1,
|
||||||
"control_after_generate": True,
|
display_mode=comfy_io.NumberDisplay.number,
|
||||||
"tooltip": "The random seed used for creating the noise.",
|
control_after_generate=True,
|
||||||
},
|
tooltip="The random seed used for creating the noise.",
|
||||||
),
|
),
|
||||||
},
|
comfy_io.Image.Input(
|
||||||
"optional": {
|
"image",
|
||||||
"image": (IO.IMAGE,),
|
optional=True,
|
||||||
"negative_prompt": (
|
|
||||||
IO.STRING,
|
|
||||||
{
|
|
||||||
"default": "",
|
|
||||||
"forceInput": True,
|
|
||||||
"tooltip": "A blurb of text describing what you do not wish to see in the output image. This is an advanced feature."
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
"image_denoise": (
|
comfy_io.String.Input(
|
||||||
IO.FLOAT,
|
"negative_prompt",
|
||||||
{
|
default="",
|
||||||
"default": 0.5,
|
tooltip="A blurb of text describing what you do not wish to see in the output image. This is an advanced feature.",
|
||||||
"min": 0.0,
|
force_input=True,
|
||||||
"max": 1.0,
|
optional=True,
|
||||||
"step": 0.01,
|
|
||||||
"tooltip": "Denoise of input image; 0.0 yields image identical to input, 1.0 is as if no image was provided at all.",
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
},
|
comfy_io.Float.Input(
|
||||||
"hidden": {
|
"image_denoise",
|
||||||
"auth_token": "AUTH_TOKEN_COMFY_ORG",
|
default=0.5,
|
||||||
"comfy_api_key": "API_KEY_COMFY_ORG",
|
min=0.0,
|
||||||
},
|
max=1.0,
|
||||||
}
|
step=0.01,
|
||||||
|
tooltip="Denoise of input image; 0.0 yields image identical to input, 1.0 is as if no image was provided at all.",
|
||||||
|
optional=True,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
outputs=[
|
||||||
|
comfy_io.Image.Output(),
|
||||||
|
],
|
||||||
|
hidden=[
|
||||||
|
comfy_io.Hidden.auth_token_comfy_org,
|
||||||
|
comfy_io.Hidden.api_key_comfy_org,
|
||||||
|
comfy_io.Hidden.unique_id,
|
||||||
|
],
|
||||||
|
is_api_node=True,
|
||||||
|
)
|
||||||
|
|
||||||
async def api_call(self, prompt: str, aspect_ratio: str, style_preset: str, seed: int,
|
@classmethod
|
||||||
negative_prompt: str=None, image: torch.Tensor = None, image_denoise: float=None,
|
async def execute(
|
||||||
**kwargs):
|
cls,
|
||||||
|
prompt: str,
|
||||||
|
aspect_ratio: str,
|
||||||
|
style_preset: str,
|
||||||
|
seed: int,
|
||||||
|
image: Optional[torch.Tensor] = None,
|
||||||
|
negative_prompt: str = "",
|
||||||
|
image_denoise: Optional[float] = 0.5,
|
||||||
|
) -> comfy_io.NodeOutput:
|
||||||
validate_string(prompt, strip_whitespace=False)
|
validate_string(prompt, strip_whitespace=False)
|
||||||
# prepare image binary if image present
|
# prepare image binary if image present
|
||||||
image_binary = None
|
image_binary = None
|
||||||
@@ -144,6 +154,11 @@ class StabilityStableImageUltraNode:
|
|||||||
"image": image_binary
|
"image": image_binary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auth = {
|
||||||
|
"auth_token": cls.hidden.auth_token_comfy_org,
|
||||||
|
"comfy_api_key": cls.hidden.api_key_comfy_org,
|
||||||
|
}
|
||||||
|
|
||||||
operation = SynchronousOperation(
|
operation = SynchronousOperation(
|
||||||
endpoint=ApiEndpoint(
|
endpoint=ApiEndpoint(
|
||||||
path="/proxy/stability/v2beta/stable-image/generate/ultra",
|
path="/proxy/stability/v2beta/stable-image/generate/ultra",
|
||||||
@@ -161,7 +176,7 @@ class StabilityStableImageUltraNode:
|
|||||||
),
|
),
|
||||||
files=files,
|
files=files,
|
||||||
content_type="multipart/form-data",
|
content_type="multipart/form-data",
|
||||||
auth_kwargs=kwargs,
|
auth_kwargs=auth,
|
||||||
)
|
)
|
||||||
response_api = await operation.execute()
|
response_api = await operation.execute()
|
||||||
|
|
||||||
@@ -171,95 +186,106 @@ class StabilityStableImageUltraNode:
|
|||||||
image_data = base64.b64decode(response_api.image)
|
image_data = base64.b64decode(response_api.image)
|
||||||
returned_image = bytesio_to_image_tensor(BytesIO(image_data))
|
returned_image = bytesio_to_image_tensor(BytesIO(image_data))
|
||||||
|
|
||||||
return (returned_image,)
|
return comfy_io.NodeOutput(returned_image)
|
||||||
|
|
||||||
|
|
||||||
class StabilityStableImageSD_3_5Node:
|
class StabilityStableImageSD_3_5Node(comfy_io.ComfyNode):
|
||||||
"""
|
"""
|
||||||
Generates images synchronously based on prompt and resolution.
|
Generates images synchronously based on prompt and resolution.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RETURN_TYPES = (IO.IMAGE,)
|
@classmethod
|
||||||
DESCRIPTION = cleandoc(__doc__ or "") # Handle potential None value
|
def define_schema(cls):
|
||||||
FUNCTION = "api_call"
|
return comfy_io.Schema(
|
||||||
API_NODE = True
|
node_id="StabilityStableImageSD_3_5Node",
|
||||||
CATEGORY = "api node/image/Stability AI"
|
display_name="Stability AI Stable Diffusion 3.5 Image",
|
||||||
|
category="api node/image/Stability AI",
|
||||||
|
description=cleandoc(cls.__doc__ or ""),
|
||||||
|
inputs=[
|
||||||
|
comfy_io.String.Input(
|
||||||
|
"prompt",
|
||||||
|
multiline=True,
|
||||||
|
default="",
|
||||||
|
tooltip="What you wish to see in the output image. A strong, descriptive prompt that clearly defines elements, colors, and subjects will lead to better results.",
|
||||||
|
),
|
||||||
|
comfy_io.Combo.Input(
|
||||||
|
"model",
|
||||||
|
options=[x.value for x in Stability_SD3_5_Model],
|
||||||
|
),
|
||||||
|
comfy_io.Combo.Input(
|
||||||
|
"aspect_ratio",
|
||||||
|
options=[x.value for x in StabilityAspectRatio],
|
||||||
|
default=StabilityAspectRatio.ratio_1_1.value,
|
||||||
|
tooltip="Aspect ratio of generated image.",
|
||||||
|
),
|
||||||
|
comfy_io.Combo.Input(
|
||||||
|
"style_preset",
|
||||||
|
options=get_stability_style_presets(),
|
||||||
|
tooltip="Optional desired style of generated image.",
|
||||||
|
),
|
||||||
|
comfy_io.Float.Input(
|
||||||
|
"cfg_scale",
|
||||||
|
default=4.0,
|
||||||
|
min=1.0,
|
||||||
|
max=10.0,
|
||||||
|
step=0.1,
|
||||||
|
tooltip="How strictly the diffusion process adheres to the prompt text (higher values keep your image closer to your prompt)",
|
||||||
|
),
|
||||||
|
comfy_io.Int.Input(
|
||||||
|
"seed",
|
||||||
|
default=0,
|
||||||
|
min=0,
|
||||||
|
max=4294967294,
|
||||||
|
step=1,
|
||||||
|
display_mode=comfy_io.NumberDisplay.number,
|
||||||
|
control_after_generate=True,
|
||||||
|
tooltip="The random seed used for creating the noise.",
|
||||||
|
),
|
||||||
|
comfy_io.Image.Input(
|
||||||
|
"image",
|
||||||
|
optional=True,
|
||||||
|
),
|
||||||
|
comfy_io.String.Input(
|
||||||
|
"negative_prompt",
|
||||||
|
default="",
|
||||||
|
tooltip="Keywords of what you do not wish to see in the output image. This is an advanced feature.",
|
||||||
|
force_input=True,
|
||||||
|
optional=True,
|
||||||
|
),
|
||||||
|
comfy_io.Float.Input(
|
||||||
|
"image_denoise",
|
||||||
|
default=0.5,
|
||||||
|
min=0.0,
|
||||||
|
max=1.0,
|
||||||
|
step=0.01,
|
||||||
|
tooltip="Denoise of input image; 0.0 yields image identical to input, 1.0 is as if no image was provided at all.",
|
||||||
|
optional=True,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
outputs=[
|
||||||
|
comfy_io.Image.Output(),
|
||||||
|
],
|
||||||
|
hidden=[
|
||||||
|
comfy_io.Hidden.auth_token_comfy_org,
|
||||||
|
comfy_io.Hidden.api_key_comfy_org,
|
||||||
|
comfy_io.Hidden.unique_id,
|
||||||
|
],
|
||||||
|
is_api_node=True,
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
async def execute(
|
||||||
return {
|
cls,
|
||||||
"required": {
|
model: str,
|
||||||
"prompt": (
|
prompt: str,
|
||||||
IO.STRING,
|
aspect_ratio: str,
|
||||||
{
|
style_preset: str,
|
||||||
"multiline": True,
|
seed: int,
|
||||||
"default": "",
|
cfg_scale: float,
|
||||||
"tooltip": "What you wish to see in the output image. A strong, descriptive prompt that clearly defines elements, colors, and subjects will lead to better results."
|
image: Optional[torch.Tensor] = None,
|
||||||
},
|
negative_prompt: str = "",
|
||||||
),
|
image_denoise: Optional[float] = 0.5,
|
||||||
"model": ([x.value for x in Stability_SD3_5_Model],),
|
) -> comfy_io.NodeOutput:
|
||||||
"aspect_ratio": ([x.value for x in StabilityAspectRatio],
|
|
||||||
{
|
|
||||||
"default": StabilityAspectRatio.ratio_1_1,
|
|
||||||
"tooltip": "Aspect ratio of generated image.",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
"style_preset": (get_stability_style_presets(),
|
|
||||||
{
|
|
||||||
"tooltip": "Optional desired style of generated image.",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
"cfg_scale": (
|
|
||||||
IO.FLOAT,
|
|
||||||
{
|
|
||||||
"default": 4.0,
|
|
||||||
"min": 1.0,
|
|
||||||
"max": 10.0,
|
|
||||||
"step": 0.1,
|
|
||||||
"tooltip": "How strictly the diffusion process adheres to the prompt text (higher values keep your image closer to your prompt)",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
"seed": (
|
|
||||||
IO.INT,
|
|
||||||
{
|
|
||||||
"default": 0,
|
|
||||||
"min": 0,
|
|
||||||
"max": 4294967294,
|
|
||||||
"control_after_generate": True,
|
|
||||||
"tooltip": "The random seed used for creating the noise.",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
"optional": {
|
|
||||||
"image": (IO.IMAGE,),
|
|
||||||
"negative_prompt": (
|
|
||||||
IO.STRING,
|
|
||||||
{
|
|
||||||
"default": "",
|
|
||||||
"forceInput": True,
|
|
||||||
"tooltip": "Keywords of what you do not wish to see in the output image. This is an advanced feature."
|
|
||||||
},
|
|
||||||
),
|
|
||||||
"image_denoise": (
|
|
||||||
IO.FLOAT,
|
|
||||||
{
|
|
||||||
"default": 0.5,
|
|
||||||
"min": 0.0,
|
|
||||||
"max": 1.0,
|
|
||||||
"step": 0.01,
|
|
||||||
"tooltip": "Denoise of input image; 0.0 yields image identical to input, 1.0 is as if no image was provided at all.",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
"hidden": {
|
|
||||||
"auth_token": "AUTH_TOKEN_COMFY_ORG",
|
|
||||||
"comfy_api_key": "API_KEY_COMFY_ORG",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
async def api_call(self, model: str, prompt: str, aspect_ratio: str, style_preset: str, seed: int, cfg_scale: float,
|
|
||||||
negative_prompt: str=None, image: torch.Tensor = None, image_denoise: float=None,
|
|
||||||
**kwargs):
|
|
||||||
validate_string(prompt, strip_whitespace=False)
|
validate_string(prompt, strip_whitespace=False)
|
||||||
# prepare image binary if image present
|
# prepare image binary if image present
|
||||||
image_binary = None
|
image_binary = None
|
||||||
@@ -280,6 +306,11 @@ class StabilityStableImageSD_3_5Node:
|
|||||||
"image": image_binary
|
"image": image_binary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auth = {
|
||||||
|
"auth_token": cls.hidden.auth_token_comfy_org,
|
||||||
|
"comfy_api_key": cls.hidden.api_key_comfy_org,
|
||||||
|
}
|
||||||
|
|
||||||
operation = SynchronousOperation(
|
operation = SynchronousOperation(
|
||||||
endpoint=ApiEndpoint(
|
endpoint=ApiEndpoint(
|
||||||
path="/proxy/stability/v2beta/stable-image/generate/sd3",
|
path="/proxy/stability/v2beta/stable-image/generate/sd3",
|
||||||
@@ -300,7 +331,7 @@ class StabilityStableImageSD_3_5Node:
|
|||||||
),
|
),
|
||||||
files=files,
|
files=files,
|
||||||
content_type="multipart/form-data",
|
content_type="multipart/form-data",
|
||||||
auth_kwargs=kwargs,
|
auth_kwargs=auth,
|
||||||
)
|
)
|
||||||
response_api = await operation.execute()
|
response_api = await operation.execute()
|
||||||
|
|
||||||
@@ -310,72 +341,75 @@ class StabilityStableImageSD_3_5Node:
|
|||||||
image_data = base64.b64decode(response_api.image)
|
image_data = base64.b64decode(response_api.image)
|
||||||
returned_image = bytesio_to_image_tensor(BytesIO(image_data))
|
returned_image = bytesio_to_image_tensor(BytesIO(image_data))
|
||||||
|
|
||||||
return (returned_image,)
|
return comfy_io.NodeOutput(returned_image)
|
||||||
|
|
||||||
|
|
||||||
class StabilityUpscaleConservativeNode:
|
class StabilityUpscaleConservativeNode(comfy_io.ComfyNode):
|
||||||
"""
|
"""
|
||||||
Upscale image with minimal alterations to 4K resolution.
|
Upscale image with minimal alterations to 4K resolution.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RETURN_TYPES = (IO.IMAGE,)
|
@classmethod
|
||||||
DESCRIPTION = cleandoc(__doc__ or "") # Handle potential None value
|
def define_schema(cls):
|
||||||
FUNCTION = "api_call"
|
return comfy_io.Schema(
|
||||||
API_NODE = True
|
node_id="StabilityUpscaleConservativeNode",
|
||||||
CATEGORY = "api node/image/Stability AI"
|
display_name="Stability AI Upscale Conservative",
|
||||||
|
category="api node/image/Stability AI",
|
||||||
|
description=cleandoc(cls.__doc__ or ""),
|
||||||
|
inputs=[
|
||||||
|
comfy_io.Image.Input("image"),
|
||||||
|
comfy_io.String.Input(
|
||||||
|
"prompt",
|
||||||
|
multiline=True,
|
||||||
|
default="",
|
||||||
|
tooltip="What you wish to see in the output image. A strong, descriptive prompt that clearly defines elements, colors, and subjects will lead to better results.",
|
||||||
|
),
|
||||||
|
comfy_io.Float.Input(
|
||||||
|
"creativity",
|
||||||
|
default=0.35,
|
||||||
|
min=0.2,
|
||||||
|
max=0.5,
|
||||||
|
step=0.01,
|
||||||
|
tooltip="Controls the likelihood of creating additional details not heavily conditioned by the init image.",
|
||||||
|
),
|
||||||
|
comfy_io.Int.Input(
|
||||||
|
"seed",
|
||||||
|
default=0,
|
||||||
|
min=0,
|
||||||
|
max=4294967294,
|
||||||
|
step=1,
|
||||||
|
display_mode=comfy_io.NumberDisplay.number,
|
||||||
|
control_after_generate=True,
|
||||||
|
tooltip="The random seed used for creating the noise.",
|
||||||
|
),
|
||||||
|
comfy_io.String.Input(
|
||||||
|
"negative_prompt",
|
||||||
|
default="",
|
||||||
|
tooltip="Keywords of what you do not wish to see in the output image. This is an advanced feature.",
|
||||||
|
force_input=True,
|
||||||
|
optional=True,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
outputs=[
|
||||||
|
comfy_io.Image.Output(),
|
||||||
|
],
|
||||||
|
hidden=[
|
||||||
|
comfy_io.Hidden.auth_token_comfy_org,
|
||||||
|
comfy_io.Hidden.api_key_comfy_org,
|
||||||
|
comfy_io.Hidden.unique_id,
|
||||||
|
],
|
||||||
|
is_api_node=True,
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
async def execute(
|
||||||
return {
|
cls,
|
||||||
"required": {
|
image: torch.Tensor,
|
||||||
"image": (IO.IMAGE,),
|
prompt: str,
|
||||||
"prompt": (
|
creativity: float,
|
||||||
IO.STRING,
|
seed: int,
|
||||||
{
|
negative_prompt: str = "",
|
||||||
"multiline": True,
|
) -> comfy_io.NodeOutput:
|
||||||
"default": "",
|
|
||||||
"tooltip": "What you wish to see in the output image. A strong, descriptive prompt that clearly defines elements, colors, and subjects will lead to better results."
|
|
||||||
},
|
|
||||||
),
|
|
||||||
"creativity": (
|
|
||||||
IO.FLOAT,
|
|
||||||
{
|
|
||||||
"default": 0.35,
|
|
||||||
"min": 0.2,
|
|
||||||
"max": 0.5,
|
|
||||||
"step": 0.01,
|
|
||||||
"tooltip": "Controls the likelihood of creating additional details not heavily conditioned by the init image.",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
"seed": (
|
|
||||||
IO.INT,
|
|
||||||
{
|
|
||||||
"default": 0,
|
|
||||||
"min": 0,
|
|
||||||
"max": 4294967294,
|
|
||||||
"control_after_generate": True,
|
|
||||||
"tooltip": "The random seed used for creating the noise.",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
"optional": {
|
|
||||||
"negative_prompt": (
|
|
||||||
IO.STRING,
|
|
||||||
{
|
|
||||||
"default": "",
|
|
||||||
"forceInput": True,
|
|
||||||
"tooltip": "Keywords of what you do not wish to see in the output image. This is an advanced feature."
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
"hidden": {
|
|
||||||
"auth_token": "AUTH_TOKEN_COMFY_ORG",
|
|
||||||
"comfy_api_key": "API_KEY_COMFY_ORG",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
async def api_call(self, image: torch.Tensor, prompt: str, creativity: float, seed: int, negative_prompt: str=None,
|
|
||||||
**kwargs):
|
|
||||||
validate_string(prompt, strip_whitespace=False)
|
validate_string(prompt, strip_whitespace=False)
|
||||||
image_binary = tensor_to_bytesio(image, total_pixels=1024*1024).read()
|
image_binary = tensor_to_bytesio(image, total_pixels=1024*1024).read()
|
||||||
|
|
||||||
@@ -386,6 +420,11 @@ class StabilityUpscaleConservativeNode:
|
|||||||
"image": image_binary
|
"image": image_binary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auth = {
|
||||||
|
"auth_token": cls.hidden.auth_token_comfy_org,
|
||||||
|
"comfy_api_key": cls.hidden.api_key_comfy_org,
|
||||||
|
}
|
||||||
|
|
||||||
operation = SynchronousOperation(
|
operation = SynchronousOperation(
|
||||||
endpoint=ApiEndpoint(
|
endpoint=ApiEndpoint(
|
||||||
path="/proxy/stability/v2beta/stable-image/upscale/conservative",
|
path="/proxy/stability/v2beta/stable-image/upscale/conservative",
|
||||||
@@ -401,7 +440,7 @@ class StabilityUpscaleConservativeNode:
|
|||||||
),
|
),
|
||||||
files=files,
|
files=files,
|
||||||
content_type="multipart/form-data",
|
content_type="multipart/form-data",
|
||||||
auth_kwargs=kwargs,
|
auth_kwargs=auth,
|
||||||
)
|
)
|
||||||
response_api = await operation.execute()
|
response_api = await operation.execute()
|
||||||
|
|
||||||
@@ -411,77 +450,81 @@ class StabilityUpscaleConservativeNode:
|
|||||||
image_data = base64.b64decode(response_api.image)
|
image_data = base64.b64decode(response_api.image)
|
||||||
returned_image = bytesio_to_image_tensor(BytesIO(image_data))
|
returned_image = bytesio_to_image_tensor(BytesIO(image_data))
|
||||||
|
|
||||||
return (returned_image,)
|
return comfy_io.NodeOutput(returned_image)
|
||||||
|
|
||||||
|
|
||||||
class StabilityUpscaleCreativeNode:
|
class StabilityUpscaleCreativeNode(comfy_io.ComfyNode):
|
||||||
"""
|
"""
|
||||||
Upscale image with minimal alterations to 4K resolution.
|
Upscale image with minimal alterations to 4K resolution.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RETURN_TYPES = (IO.IMAGE,)
|
@classmethod
|
||||||
DESCRIPTION = cleandoc(__doc__ or "") # Handle potential None value
|
def define_schema(cls):
|
||||||
FUNCTION = "api_call"
|
return comfy_io.Schema(
|
||||||
API_NODE = True
|
node_id="StabilityUpscaleCreativeNode",
|
||||||
CATEGORY = "api node/image/Stability AI"
|
display_name="Stability AI Upscale Creative",
|
||||||
|
category="api node/image/Stability AI",
|
||||||
|
description=cleandoc(cls.__doc__ or ""),
|
||||||
|
inputs=[
|
||||||
|
comfy_io.Image.Input("image"),
|
||||||
|
comfy_io.String.Input(
|
||||||
|
"prompt",
|
||||||
|
multiline=True,
|
||||||
|
default="",
|
||||||
|
tooltip="What you wish to see in the output image. A strong, descriptive prompt that clearly defines elements, colors, and subjects will lead to better results.",
|
||||||
|
),
|
||||||
|
comfy_io.Float.Input(
|
||||||
|
"creativity",
|
||||||
|
default=0.3,
|
||||||
|
min=0.1,
|
||||||
|
max=0.5,
|
||||||
|
step=0.01,
|
||||||
|
tooltip="Controls the likelihood of creating additional details not heavily conditioned by the init image.",
|
||||||
|
),
|
||||||
|
comfy_io.Combo.Input(
|
||||||
|
"style_preset",
|
||||||
|
options=get_stability_style_presets(),
|
||||||
|
tooltip="Optional desired style of generated image.",
|
||||||
|
),
|
||||||
|
comfy_io.Int.Input(
|
||||||
|
"seed",
|
||||||
|
default=0,
|
||||||
|
min=0,
|
||||||
|
max=4294967294,
|
||||||
|
step=1,
|
||||||
|
display_mode=comfy_io.NumberDisplay.number,
|
||||||
|
control_after_generate=True,
|
||||||
|
tooltip="The random seed used for creating the noise.",
|
||||||
|
),
|
||||||
|
comfy_io.String.Input(
|
||||||
|
"negative_prompt",
|
||||||
|
default="",
|
||||||
|
tooltip="Keywords of what you do not wish to see in the output image. This is an advanced feature.",
|
||||||
|
force_input=True,
|
||||||
|
optional=True,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
outputs=[
|
||||||
|
comfy_io.Image.Output(),
|
||||||
|
],
|
||||||
|
hidden=[
|
||||||
|
comfy_io.Hidden.auth_token_comfy_org,
|
||||||
|
comfy_io.Hidden.api_key_comfy_org,
|
||||||
|
comfy_io.Hidden.unique_id,
|
||||||
|
],
|
||||||
|
is_api_node=True,
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
async def execute(
|
||||||
return {
|
cls,
|
||||||
"required": {
|
image: torch.Tensor,
|
||||||
"image": (IO.IMAGE,),
|
prompt: str,
|
||||||
"prompt": (
|
creativity: float,
|
||||||
IO.STRING,
|
style_preset: str,
|
||||||
{
|
seed: int,
|
||||||
"multiline": True,
|
negative_prompt: str = "",
|
||||||
"default": "",
|
) -> comfy_io.NodeOutput:
|
||||||
"tooltip": "What you wish to see in the output image. A strong, descriptive prompt that clearly defines elements, colors, and subjects will lead to better results."
|
|
||||||
},
|
|
||||||
),
|
|
||||||
"creativity": (
|
|
||||||
IO.FLOAT,
|
|
||||||
{
|
|
||||||
"default": 0.3,
|
|
||||||
"min": 0.1,
|
|
||||||
"max": 0.5,
|
|
||||||
"step": 0.01,
|
|
||||||
"tooltip": "Controls the likelihood of creating additional details not heavily conditioned by the init image.",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
"style_preset": (get_stability_style_presets(),
|
|
||||||
{
|
|
||||||
"tooltip": "Optional desired style of generated image.",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
"seed": (
|
|
||||||
IO.INT,
|
|
||||||
{
|
|
||||||
"default": 0,
|
|
||||||
"min": 0,
|
|
||||||
"max": 4294967294,
|
|
||||||
"control_after_generate": True,
|
|
||||||
"tooltip": "The random seed used for creating the noise.",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
"optional": {
|
|
||||||
"negative_prompt": (
|
|
||||||
IO.STRING,
|
|
||||||
{
|
|
||||||
"default": "",
|
|
||||||
"forceInput": True,
|
|
||||||
"tooltip": "Keywords of what you do not wish to see in the output image. This is an advanced feature."
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
"hidden": {
|
|
||||||
"auth_token": "AUTH_TOKEN_COMFY_ORG",
|
|
||||||
"comfy_api_key": "API_KEY_COMFY_ORG",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
async def api_call(self, image: torch.Tensor, prompt: str, creativity: float, style_preset: str, seed: int, negative_prompt: str=None,
|
|
||||||
**kwargs):
|
|
||||||
validate_string(prompt, strip_whitespace=False)
|
validate_string(prompt, strip_whitespace=False)
|
||||||
image_binary = tensor_to_bytesio(image, total_pixels=1024*1024).read()
|
image_binary = tensor_to_bytesio(image, total_pixels=1024*1024).read()
|
||||||
|
|
||||||
@@ -494,6 +537,11 @@ class StabilityUpscaleCreativeNode:
|
|||||||
"image": image_binary
|
"image": image_binary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auth = {
|
||||||
|
"auth_token": cls.hidden.auth_token_comfy_org,
|
||||||
|
"comfy_api_key": cls.hidden.api_key_comfy_org,
|
||||||
|
}
|
||||||
|
|
||||||
operation = SynchronousOperation(
|
operation = SynchronousOperation(
|
||||||
endpoint=ApiEndpoint(
|
endpoint=ApiEndpoint(
|
||||||
path="/proxy/stability/v2beta/stable-image/upscale/creative",
|
path="/proxy/stability/v2beta/stable-image/upscale/creative",
|
||||||
@@ -510,7 +558,7 @@ class StabilityUpscaleCreativeNode:
|
|||||||
),
|
),
|
||||||
files=files,
|
files=files,
|
||||||
content_type="multipart/form-data",
|
content_type="multipart/form-data",
|
||||||
auth_kwargs=kwargs,
|
auth_kwargs=auth,
|
||||||
)
|
)
|
||||||
response_api = await operation.execute()
|
response_api = await operation.execute()
|
||||||
|
|
||||||
@@ -525,7 +573,8 @@ class StabilityUpscaleCreativeNode:
|
|||||||
completed_statuses=[StabilityPollStatus.finished],
|
completed_statuses=[StabilityPollStatus.finished],
|
||||||
failed_statuses=[StabilityPollStatus.failed],
|
failed_statuses=[StabilityPollStatus.failed],
|
||||||
status_extractor=lambda x: get_async_dummy_status(x),
|
status_extractor=lambda x: get_async_dummy_status(x),
|
||||||
auth_kwargs=kwargs,
|
auth_kwargs=auth,
|
||||||
|
node_id=cls.hidden.unique_id,
|
||||||
)
|
)
|
||||||
response_poll: StabilityResultsGetResponse = await operation.execute()
|
response_poll: StabilityResultsGetResponse = await operation.execute()
|
||||||
|
|
||||||
@@ -535,41 +584,48 @@ class StabilityUpscaleCreativeNode:
|
|||||||
image_data = base64.b64decode(response_poll.result)
|
image_data = base64.b64decode(response_poll.result)
|
||||||
returned_image = bytesio_to_image_tensor(BytesIO(image_data))
|
returned_image = bytesio_to_image_tensor(BytesIO(image_data))
|
||||||
|
|
||||||
return (returned_image,)
|
return comfy_io.NodeOutput(returned_image)
|
||||||
|
|
||||||
|
|
||||||
class StabilityUpscaleFastNode:
|
class StabilityUpscaleFastNode(comfy_io.ComfyNode):
|
||||||
"""
|
"""
|
||||||
Quickly upscales an image via Stability API call to 4x its original size; intended for upscaling low-quality/compressed images.
|
Quickly upscales an image via Stability API call to 4x its original size; intended for upscaling low-quality/compressed images.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RETURN_TYPES = (IO.IMAGE,)
|
@classmethod
|
||||||
DESCRIPTION = cleandoc(__doc__ or "") # Handle potential None value
|
def define_schema(cls):
|
||||||
FUNCTION = "api_call"
|
return comfy_io.Schema(
|
||||||
API_NODE = True
|
node_id="StabilityUpscaleFastNode",
|
||||||
CATEGORY = "api node/image/Stability AI"
|
display_name="Stability AI Upscale Fast",
|
||||||
|
category="api node/image/Stability AI",
|
||||||
|
description=cleandoc(cls.__doc__ or ""),
|
||||||
|
inputs=[
|
||||||
|
comfy_io.Image.Input("image"),
|
||||||
|
],
|
||||||
|
outputs=[
|
||||||
|
comfy_io.Image.Output(),
|
||||||
|
],
|
||||||
|
hidden=[
|
||||||
|
comfy_io.Hidden.auth_token_comfy_org,
|
||||||
|
comfy_io.Hidden.api_key_comfy_org,
|
||||||
|
comfy_io.Hidden.unique_id,
|
||||||
|
],
|
||||||
|
is_api_node=True,
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
async def execute(cls, image: torch.Tensor) -> comfy_io.NodeOutput:
|
||||||
return {
|
|
||||||
"required": {
|
|
||||||
"image": (IO.IMAGE,),
|
|
||||||
},
|
|
||||||
"optional": {
|
|
||||||
},
|
|
||||||
"hidden": {
|
|
||||||
"auth_token": "AUTH_TOKEN_COMFY_ORG",
|
|
||||||
"comfy_api_key": "API_KEY_COMFY_ORG",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
async def api_call(self, image: torch.Tensor, **kwargs):
|
|
||||||
image_binary = tensor_to_bytesio(image, total_pixels=4096*4096).read()
|
image_binary = tensor_to_bytesio(image, total_pixels=4096*4096).read()
|
||||||
|
|
||||||
files = {
|
files = {
|
||||||
"image": image_binary
|
"image": image_binary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auth = {
|
||||||
|
"auth_token": cls.hidden.auth_token_comfy_org,
|
||||||
|
"comfy_api_key": cls.hidden.api_key_comfy_org,
|
||||||
|
}
|
||||||
|
|
||||||
operation = SynchronousOperation(
|
operation = SynchronousOperation(
|
||||||
endpoint=ApiEndpoint(
|
endpoint=ApiEndpoint(
|
||||||
path="/proxy/stability/v2beta/stable-image/upscale/fast",
|
path="/proxy/stability/v2beta/stable-image/upscale/fast",
|
||||||
@@ -580,7 +636,7 @@ class StabilityUpscaleFastNode:
|
|||||||
request=EmptyRequest(),
|
request=EmptyRequest(),
|
||||||
files=files,
|
files=files,
|
||||||
content_type="multipart/form-data",
|
content_type="multipart/form-data",
|
||||||
auth_kwargs=kwargs,
|
auth_kwargs=auth,
|
||||||
)
|
)
|
||||||
response_api = await operation.execute()
|
response_api = await operation.execute()
|
||||||
|
|
||||||
@@ -590,24 +646,20 @@ class StabilityUpscaleFastNode:
|
|||||||
image_data = base64.b64decode(response_api.image)
|
image_data = base64.b64decode(response_api.image)
|
||||||
returned_image = bytesio_to_image_tensor(BytesIO(image_data))
|
returned_image = bytesio_to_image_tensor(BytesIO(image_data))
|
||||||
|
|
||||||
return (returned_image,)
|
return comfy_io.NodeOutput(returned_image)
|
||||||
|
|
||||||
|
|
||||||
# A dictionary that contains all nodes you want to export with their names
|
class StabilityExtension(ComfyExtension):
|
||||||
# NOTE: names should be globally unique
|
@override
|
||||||
NODE_CLASS_MAPPINGS = {
|
async def get_node_list(self) -> list[type[comfy_io.ComfyNode]]:
|
||||||
"StabilityStableImageUltraNode": StabilityStableImageUltraNode,
|
return [
|
||||||
"StabilityStableImageSD_3_5Node": StabilityStableImageSD_3_5Node,
|
StabilityStableImageUltraNode,
|
||||||
"StabilityUpscaleConservativeNode": StabilityUpscaleConservativeNode,
|
StabilityStableImageSD_3_5Node,
|
||||||
"StabilityUpscaleCreativeNode": StabilityUpscaleCreativeNode,
|
StabilityUpscaleConservativeNode,
|
||||||
"StabilityUpscaleFastNode": StabilityUpscaleFastNode,
|
StabilityUpscaleCreativeNode,
|
||||||
}
|
StabilityUpscaleFastNode,
|
||||||
|
]
|
||||||
|
|
||||||
# A dictionary that contains the friendly/humanly readable titles for the nodes
|
|
||||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
async def comfy_entrypoint() -> StabilityExtension:
|
||||||
"StabilityStableImageUltraNode": "Stability AI Stable Image Ultra",
|
return StabilityExtension()
|
||||||
"StabilityStableImageSD_3_5Node": "Stability AI Stable Diffusion 3.5 Image",
|
|
||||||
"StabilityUpscaleConservativeNode": "Stability AI Upscale Conservative",
|
|
||||||
"StabilityUpscaleCreativeNode": "Stability AI Upscale Creative",
|
|
||||||
"StabilityUpscaleFastNode": "Stability AI Upscale Fast",
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user