Compare commits

...

2 Commits

Author SHA1 Message Date
bigcat88
d25d14dfb6 dev: PhotaLabs API nodes
Signed-off-by: bigcat88 <bigcat88@icloud.com>
2026-03-31 16:36:32 +03:00
Christian Byrne
55e6478526 Rename utils/string nodes with Text prefix and add search aliases (#13227)
Rename all 11 nodes in the utils/string category to include a "Text"
prefix for better discoverability and natural sorting. Regex nodes get
user-friendly names without "Regex" in the display name.

Renames:
- Concatenate → Text Concatenate
- Substring → Text Substring
- Length → Text Length
- Case Converter → Text Case Converter
- Trim → Text Trim
- Replace → Text Replace
- Contains → Text Contains
- Compare → Text Compare
- Regex Match → Text Match
- Regex Extract → Text Extract Substring
- Regex Replace → Text Replace (Regex)

All renamed nodes include their old display name as a search alias so
users can still find them by searching the original name. Regex nodes
also include "regex" as a search alias.
2026-03-29 21:02:44 -07:00
6 changed files with 522 additions and 23 deletions

View File

@@ -43,9 +43,55 @@ class UploadType(str, Enum):
model = "file_upload"
class RemoteItemSchema:
"""Describes how to map API response objects to rich dropdown items.
All *_field parameters use dot-path notation (e.g. ``"labels.gender"``).
``label_field`` additionally supports template strings with ``{field}``
placeholders (e.g. ``"{name} ({labels.accent})"``).
"""
def __init__(
self,
value_field: str,
label_field: str,
preview_url_field: str | None = None,
preview_type: Literal["image", "video", "audio"] = "image",
description_field: str | None = None,
search_fields: list[str] | None = None,
filter_field: str | None = None,
):
self.value_field = value_field
"""Dot-path to the unique identifier within each item. This value is stored in the widget and passed to execute()."""
self.label_field = label_field
"""Dot-path to the display name, or a template string with {field} placeholders."""
self.preview_url_field = preview_url_field
"""Dot-path to a preview media URL. If None, no preview is shown."""
self.preview_type = preview_type
"""How to render the preview: "image", "video", or "audio"."""
self.description_field = description_field
"""Optional dot-path or template for a subtitle line shown below the label."""
self.search_fields = search_fields
"""Dot-paths to fields included in the search index. Defaults to [label_field]."""
self.filter_field = filter_field
"""Optional dot-path to a categorical field for filter tabs."""
def as_dict(self):
return prune_dict({
"value_field": self.value_field,
"label_field": self.label_field,
"preview_url_field": self.preview_url_field,
"preview_type": self.preview_type,
"description_field": self.description_field,
"search_fields": self.search_fields,
"filter_field": self.filter_field,
})
class RemoteOptions:
def __init__(self, route: str, refresh_button: bool, control_after_refresh: Literal["first", "last"]="first",
timeout: int=None, max_retries: int=None, refresh: int=None):
timeout: int=None, max_retries: int=None, refresh: int=None,
response_key: str=None, query_params: dict[str, str]=None,
item_schema: RemoteItemSchema=None):
self.route = route
"""The route to the remote source."""
self.refresh_button = refresh_button
@@ -58,6 +104,12 @@ class RemoteOptions:
"""The maximum number of retries before aborting the request."""
self.refresh = refresh
"""The TTL of the remote input's value in milliseconds. Specifies the interval at which the remote input's value is refreshed."""
self.response_key = response_key
"""Dot-path to the items array in the response. If None, the entire response is used."""
self.query_params = query_params
"""Static query parameters appended to the request URL."""
self.item_schema = item_schema
"""When present, the frontend renders a rich dropdown with previews instead of a plain combo widget."""
def as_dict(self):
return prune_dict({
@@ -67,6 +119,9 @@ class RemoteOptions:
"timeout": self.timeout,
"max_retries": self.max_retries,
"refresh": self.refresh,
"response_key": self.response_key,
"query_params": self.query_params,
"item_schema": self.item_schema.as_dict() if self.item_schema else None,
})
@@ -2184,6 +2239,7 @@ class NodeReplace:
__all__ = [
"FolderType",
"UploadType",
"RemoteItemSchema",
"RemoteOptions",
"NumberDisplay",
"ControlAfterGenerate",

View File

@@ -0,0 +1,49 @@
from pydantic import BaseModel, Field
class PhotaGenerateRequest(BaseModel):
prompt: str = Field(...)
num_output_images: int = Field(1)
aspect_ratio: str = Field(...)
resolution: str = Field(...)
profile_ids: list[str] | None = Field(None)
class PhotaEditRequest(BaseModel):
prompt: str = Field(...)
images: list[str] = Field(...)
num_output_images: int = Field(1)
aspect_ratio: str = Field(...)
resolution: str = Field(...)
profile_ids: list[str] | None = Field(None)
class PhotaEnhanceRequest(BaseModel):
image: str = Field(...)
num_output_images: int = Field(1)
class PhotaKnownGeneratedSubjectCounts(BaseModel):
counts: dict[str, int] = Field(default_factory=dict)
class PhotoStudioResponse(BaseModel):
images: list[str] = Field(..., description="Base64-encoded PNG output images.")
known_subjects: PhotaKnownGeneratedSubjectCounts = Field(default_factory=PhotaKnownGeneratedSubjectCounts)
class PhotaAddProfileRequest(BaseModel):
image_urls: list[str] = Field(...)
class PhotaAddProfileResponse(BaseModel):
profile_id: str = Field(...)
class PhotaProfileStatusResponse(BaseModel):
profile_id: str = Field(...)
status: str = Field(
...,
description="Current profile status: VALIDATING, QUEUING, IN_PROGRESS, READY, ERROR, or INACTIVE.",
)
message: str | None = Field(default=None, description="Optional error or status message.")

View File

@@ -233,6 +233,45 @@ class ElevenLabsVoiceSelector(IO.ComfyNode):
return IO.NodeOutput(voice_id)
class ElevenLabsRichVoiceSelector(IO.ComfyNode):
@classmethod
def define_schema(cls) -> IO.Schema:
return IO.Schema(
node_id="ElevenLabsRichVoiceSelector",
display_name="ElevenLabs Voice Selector (Rich)",
category="api node/audio/ElevenLabs",
description="Select an ElevenLabs voice with audio preview and rich metadata.",
inputs=[
IO.Combo.Input(
"voice",
options=ELEVENLABS_VOICE_OPTIONS,
remote=IO.RemoteOptions(
route="http://localhost:9000/elevenlabs/voices",
refresh_button=True,
item_schema=IO.RemoteItemSchema(
value_field="voice_id",
label_field="name",
preview_url_field="preview_url",
preview_type="audio",
search_fields=["name", "labels.gender", "labels.accent"],
filter_field="labels.use_case",
),
),
tooltip="Choose a voice with audio preview.",
),
],
outputs=[
IO.Custom(ELEVENLABS_VOICE).Output(display_name="voice"),
],
is_api_node=False,
)
@classmethod
def execute(cls, voice: str) -> IO.NodeOutput:
# voice is already the voice_id from item_schema.value_field
return IO.NodeOutput(voice)
class ElevenLabsTextToSpeech(IO.ComfyNode):
@classmethod
def define_schema(cls) -> IO.Schema:
@@ -911,6 +950,7 @@ class ElevenLabsExtension(ComfyExtension):
return [
ElevenLabsSpeechToText,
ElevenLabsVoiceSelector,
ElevenLabsRichVoiceSelector,
ElevenLabsTextToSpeech,
ElevenLabsAudioIsolation,
ElevenLabsTextToSoundEffects,

View File

@@ -0,0 +1,350 @@
import base64
from io import BytesIO
from typing_extensions import override
from comfy_api.latest import IO, ComfyExtension, Input
from comfy_api_nodes.apis.phota_labs import (
PhotaAddProfileRequest,
PhotaAddProfileResponse,
PhotaEditRequest,
PhotaEnhanceRequest,
PhotaGenerateRequest,
PhotaProfileStatusResponse,
PhotoStudioResponse,
)
from comfy_api_nodes.util import (
ApiEndpoint,
bytesio_to_image_tensor,
poll_op,
sync_op,
upload_images_to_comfyapi,
upload_image_to_comfyapi,
validate_string,
)
# Direct API endpoint (comment out this class to use proxy)
class ApiEndpoint(ApiEndpoint):
"""Temporary override to use direct API instead of proxy."""
def __init__(
self,
path: str,
method: str = "GET",
*,
query_params: dict | None = None,
headers: dict | None = None,
):
self.path = path.replace("/proxy/phota/", "https://api.photalabs.com/")
self.method = method
self.query_params = query_params or {}
self.headers = headers or {}
if "api.photalabs.com" in self.path:
self.headers["X-API-Key"] = "YOUR_PHOTA_API_KEY"
PHOTA_LABS_PROFILE_ID = "PHOTA_LABS_PROFILE_ID"
class PhotaLabsGenerate(IO.ComfyNode):
@classmethod
def define_schema(cls):
return IO.Schema(
node_id="PhotaLabsGenerate",
display_name="Phota Labs Generate",
category="api node/image/Phota Labs",
description="Generate images from a text prompt using Phota Labs.",
inputs=[
IO.String.Input(
"prompt",
multiline=True,
default="",
tooltip="Text prompt describing the desired image.",
),
IO.Combo.Input(
"aspect_ratio",
options=["auto", "1:1", "3:4", "4:3", "9:16", "16:9"],
),
IO.Combo.Input(
"resolution",
options=["1K", "4K"],
),
],
outputs=[IO.Image.Output()],
hidden=[
IO.Hidden.auth_token_comfy_org,
IO.Hidden.api_key_comfy_org,
IO.Hidden.unique_id,
],
is_api_node=True,
)
@classmethod
async def execute(
cls,
prompt: str,
aspect_ratio: str,
resolution: str,
) -> IO.NodeOutput:
validate_string(prompt, strip_whitespace=False, min_length=1)
pid_list = None # list(profile_ids.values()) if profile_ids else None
response = await sync_op(
cls,
ApiEndpoint(path="/proxy/phota/v1/phota/generate", method="POST"),
response_model=PhotoStudioResponse,
data=PhotaGenerateRequest(
prompt=prompt,
aspect_ratio=aspect_ratio,
resolution=resolution,
profile_ids=pid_list or None,
),
)
return IO.NodeOutput(bytesio_to_image_tensor(BytesIO(base64.b64decode(response.images[0]))))
class PhotaLabsEdit(IO.ComfyNode):
@classmethod
def define_schema(cls):
return IO.Schema(
node_id="PhotaLabsEdit",
display_name="Phota Labs Edit",
category="api node/image/Phota Labs",
description="Edit images based on a text prompt using Phota Labs. "
"Provide input images and a prompt describing the desired edit.",
inputs=[
IO.Autogrow.Input(
"images",
template=IO.Autogrow.TemplatePrefix(
IO.Image.Input("image"),
prefix="image",
min=1,
max=10,
),
),
IO.String.Input(
"prompt",
multiline=True,
default="",
),
IO.Combo.Input(
"aspect_ratio",
options=["auto", "1:1", "3:4", "4:3", "9:16", "16:9"],
),
IO.Combo.Input(
"resolution",
options=["1K", "4K"],
),
IO.Autogrow.Input(
"profile_ids",
template=IO.Autogrow.TemplatePrefix(
IO.Custom(PHOTA_LABS_PROFILE_ID).Input("profile_id"),
prefix="profile_id",
min=0,
max=5,
),
),
],
outputs=[IO.Image.Output()],
hidden=[
IO.Hidden.auth_token_comfy_org,
IO.Hidden.api_key_comfy_org,
IO.Hidden.unique_id,
],
is_api_node=True,
)
@classmethod
async def execute(
cls,
images: IO.Autogrow.Type,
prompt: str,
aspect_ratio: str,
resolution: str,
profile_ids: IO.Autogrow.Type = None,
) -> IO.NodeOutput:
validate_string(prompt, strip_whitespace=False, min_length=1)
response = await sync_op(
cls,
ApiEndpoint(path="/proxy/phota/v1/phota/edit", method="POST"),
response_model=PhotoStudioResponse,
data=PhotaEditRequest(
prompt=prompt,
images=await upload_images_to_comfyapi(cls, list(images.values()), max_images=10),
aspect_ratio=aspect_ratio,
resolution=resolution,
profile_ids=list(profile_ids.values()) if profile_ids else None,
),
)
return IO.NodeOutput(bytesio_to_image_tensor(BytesIO(base64.b64decode(response.images[0]))))
class PhotaLabsEnhance(IO.ComfyNode):
@classmethod
def define_schema(cls):
return IO.Schema(
node_id="PhotaLabsEnhance",
display_name="Phota Labs Enhance",
category="api node/image/Phota Labs",
description="Automatically enhance a photo using Phota Labs. "
"No text prompt is required — enhancement parameters are inferred automatically.",
inputs=[
IO.Image.Input(
"image",
tooltip="Input image to enhance.",
),
IO.Autogrow.Input(
"profile_ids",
template=IO.Autogrow.TemplatePrefix(
IO.Custom(PHOTA_LABS_PROFILE_ID).Input("profile_id"),
prefix="profile_id",
min=0,
max=5,
),
),
],
outputs=[IO.Image.Output()],
hidden=[
IO.Hidden.auth_token_comfy_org,
IO.Hidden.api_key_comfy_org,
IO.Hidden.unique_id,
],
is_api_node=True,
)
@classmethod
async def execute(
cls,
image: Input.Image,
profile_ids: IO.Autogrow.Type = None,
) -> IO.NodeOutput:
response = await sync_op(
cls,
ApiEndpoint(path="/proxy/phota/v1/phota/enhance", method="POST"),
response_model=PhotoStudioResponse,
data=PhotaEnhanceRequest(
image=await upload_image_to_comfyapi(cls, image),
),
)
return IO.NodeOutput(bytesio_to_image_tensor(BytesIO(base64.b64decode(response.images[0]))))
class PhotaLabsSelectProfile(IO.ComfyNode):
@classmethod
def define_schema(cls):
return IO.Schema(
node_id="PhotaLabsSelectProfile",
display_name="Phota Labs Select Profile",
category="api node/image/Phota Labs",
description="Select a trained Phota Labs profile for use in generation.",
inputs=[
IO.Combo.Input(
"profile_id",
options=[],
remote=IO.RemoteOptions(
route="http://localhost:9000/phota/profiles",
refresh_button=True,
item_schema=IO.RemoteItemSchema(
value_field="profile_id",
label_field="profile_id",
preview_url_field="preview_url",
preview_type="image",
),
),
),
],
outputs=[IO.Custom(PHOTA_LABS_PROFILE_ID).Output(display_name="profile_id")],
hidden=[
IO.Hidden.auth_token_comfy_org,
IO.Hidden.api_key_comfy_org,
IO.Hidden.unique_id,
],
is_api_node=True,
)
@classmethod
async def execute(cls, profile_id: str) -> IO.NodeOutput:
return IO.NodeOutput(profile_id)
class PhotaLabsAddProfile(IO.ComfyNode):
@classmethod
def define_schema(cls):
return IO.Schema(
node_id="PhotaLabsAddProfile",
display_name="Phota Labs Add Profile",
category="api node/image/Phota Labs",
description="Create a training profile from 30-50 reference images using Phota Labs. "
"Uploads images and starts asynchronous training, returning the profile ID once training is queued.",
inputs=[
IO.Autogrow.Input(
"images",
template=IO.Autogrow.TemplatePrefix(
IO.Image.Input("image"),
prefix="image",
min=30,
max=50,
),
),
],
outputs=[
IO.Custom(PHOTA_LABS_PROFILE_ID).Output(display_name="profile_id"),
IO.String.Output(display_name="status"),
],
hidden=[
IO.Hidden.auth_token_comfy_org,
IO.Hidden.api_key_comfy_org,
IO.Hidden.unique_id,
],
is_api_node=True,
)
@classmethod
async def execute(
cls,
images: IO.Autogrow.Type,
) -> IO.NodeOutput:
image_urls = await upload_images_to_comfyapi(
cls,
list(images.values()),
max_images=50,
wait_label="Uploading training images",
)
response = await sync_op(
cls,
ApiEndpoint(path="/proxy/phota/v1/phota/profiles/add", method="POST"),
response_model=PhotaAddProfileResponse,
data=PhotaAddProfileRequest(image_urls=image_urls),
)
# Poll until validation passes and training is queued/in-progress/ready
status_response = await poll_op(
cls,
ApiEndpoint(
path=f"/proxy/phota/v1/phota/profiles/{response.profile_id}/status"
),
response_model=PhotaProfileStatusResponse,
status_extractor=lambda r: r.status,
completed_statuses=["QUEUING", "IN_PROGRESS", "READY"],
failed_statuses=["ERROR", "INACTIVE"],
)
return IO.NodeOutput(response.profile_id, status_response.status)
class PhotaLabsExtension(ComfyExtension):
@override
async def get_node_list(self) -> list[type[IO.ComfyNode]]:
return [
PhotaLabsGenerate,
PhotaLabsEdit,
PhotaLabsEnhance,
PhotaLabsSelectProfile,
PhotaLabsAddProfile,
]
async def comfy_entrypoint() -> PhotaLabsExtension:
return PhotaLabsExtension()

View File

@@ -9,9 +9,9 @@ class StringConcatenate(io.ComfyNode):
def define_schema(cls):
return io.Schema(
node_id="StringConcatenate",
display_name="Concatenate",
display_name="Text Concatenate",
category="utils/string",
search_aliases=["text concat", "join text", "merge text", "combine strings", "concat", "concatenate", "append text", "combine text", "string"],
search_aliases=["Concatenate", "text concat", "join text", "merge text", "combine strings", "concat", "concatenate", "append text", "combine text", "string"],
inputs=[
io.String.Input("string_a", multiline=True),
io.String.Input("string_b", multiline=True),
@@ -32,8 +32,8 @@ class StringSubstring(io.ComfyNode):
def define_schema(cls):
return io.Schema(
node_id="StringSubstring",
search_aliases=["extract text", "text portion"],
display_name="Substring",
search_aliases=["Substring", "extract text", "text portion"],
display_name="Text Substring",
category="utils/string",
inputs=[
io.String.Input("string", multiline=True),
@@ -55,8 +55,8 @@ class StringLength(io.ComfyNode):
def define_schema(cls):
return io.Schema(
node_id="StringLength",
search_aliases=["character count", "text size"],
display_name="Length",
search_aliases=["character count", "text size", "string length"],
display_name="Text Length",
category="utils/string",
inputs=[
io.String.Input("string", multiline=True),
@@ -76,8 +76,8 @@ class CaseConverter(io.ComfyNode):
def define_schema(cls):
return io.Schema(
node_id="CaseConverter",
search_aliases=["text case", "uppercase", "lowercase", "capitalize"],
display_name="Case Converter",
search_aliases=["Case Converter", "text case", "uppercase", "lowercase", "capitalize"],
display_name="Text Case Converter",
category="utils/string",
inputs=[
io.String.Input("string", multiline=True),
@@ -109,8 +109,8 @@ class StringTrim(io.ComfyNode):
def define_schema(cls):
return io.Schema(
node_id="StringTrim",
search_aliases=["clean whitespace", "remove whitespace"],
display_name="Trim",
search_aliases=["Trim", "clean whitespace", "remove whitespace", "strip"],
display_name="Text Trim",
category="utils/string",
inputs=[
io.String.Input("string", multiline=True),
@@ -140,8 +140,8 @@ class StringReplace(io.ComfyNode):
def define_schema(cls):
return io.Schema(
node_id="StringReplace",
search_aliases=["find and replace", "substitute", "swap text"],
display_name="Replace",
search_aliases=["Replace", "find and replace", "substitute", "swap text"],
display_name="Text Replace",
category="utils/string",
inputs=[
io.String.Input("string", multiline=True),
@@ -163,8 +163,8 @@ class StringContains(io.ComfyNode):
def define_schema(cls):
return io.Schema(
node_id="StringContains",
search_aliases=["text includes", "string includes"],
display_name="Contains",
search_aliases=["Contains", "text includes", "string includes"],
display_name="Text Contains",
category="utils/string",
inputs=[
io.String.Input("string", multiline=True),
@@ -191,8 +191,8 @@ class StringCompare(io.ComfyNode):
def define_schema(cls):
return io.Schema(
node_id="StringCompare",
search_aliases=["text match", "string equals", "starts with", "ends with"],
display_name="Compare",
search_aliases=["Compare", "text match", "string equals", "starts with", "ends with"],
display_name="Text Compare",
category="utils/string",
inputs=[
io.String.Input("string_a", multiline=True),
@@ -227,8 +227,8 @@ class RegexMatch(io.ComfyNode):
def define_schema(cls):
return io.Schema(
node_id="RegexMatch",
search_aliases=["pattern match", "text contains", "string match"],
display_name="Regex Match",
search_aliases=["Regex Match", "regex", "pattern match", "text contains", "string match"],
display_name="Text Match",
category="utils/string",
inputs=[
io.String.Input("string", multiline=True),
@@ -268,8 +268,8 @@ class RegexExtract(io.ComfyNode):
def define_schema(cls):
return io.Schema(
node_id="RegexExtract",
search_aliases=["pattern extract", "text parser", "parse text"],
display_name="Regex Extract",
search_aliases=["Regex Extract", "regex", "pattern extract", "text parser", "parse text"],
display_name="Text Extract Substring",
category="utils/string",
inputs=[
io.String.Input("string", multiline=True),
@@ -343,8 +343,8 @@ class RegexReplace(io.ComfyNode):
def define_schema(cls):
return io.Schema(
node_id="RegexReplace",
search_aliases=["pattern replace", "find and replace", "substitution"],
display_name="Regex Replace",
search_aliases=["Regex Replace", "regex", "pattern replace", "regex replace", "substitution"],
display_name="Text Replace (Regex)",
category="utils/string",
description="Find and replace text using regex patterns.",
inputs=[

View File

@@ -991,6 +991,10 @@ async def validate_inputs(prompt_id, prompt, item, validated):
if isinstance(input_type, list) or input_type == io.Combo.io_type:
if input_type == io.Combo.io_type:
# Skip validation for combos with remote options — options
# are fetched client-side and not available on the server.
if extra_info.get("remote"):
continue
combo_options = extra_info.get("options", [])
else:
combo_options = input_type