Skip to content

Commit ae60b15

Browse files
update node tooltips and validation (Comfy-Org#8036)
1 parent 42da274 commit ae60b15

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

comfy_api_nodes/nodes_ideogram.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ def download_and_process_images(image_urls):
234234

235235
class IdeogramV1(ComfyNodeABC):
236236
"""
237-
Generates images synchronously using the Ideogram V1 model.
238-
239-
Images links are available for a limited period of time; if you would like to keep the image, you must download it.
237+
Generates images using the Ideogram V1 model.
240238
"""
241239

242240
def __init__(self):
@@ -365,9 +363,7 @@ def api_call(
365363

366364
class IdeogramV2(ComfyNodeABC):
367365
"""
368-
Generates images synchronously using the Ideogram V2 model.
369-
370-
Images links are available for a limited period of time; if you would like to keep the image, you must download it.
366+
Generates images using the Ideogram V2 model.
371367
"""
372368

373369
def __init__(self):
@@ -536,10 +532,7 @@ def api_call(
536532

537533
class IdeogramV3(ComfyNodeABC):
538534
"""
539-
Generates images synchronously using the Ideogram V3 model.
540-
541-
Supports both regular image generation from text prompts and image editing with mask.
542-
Images links are available for a limited period of time; if you would like to keep the image, you must download it.
535+
Generates images using the Ideogram V3 model. Supports both regular image generation from text prompts and image editing with mask.
543536
"""
544537

545538
def __init__(self):

comfy_api_nodes/nodes_kling.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,33 @@ def validate_image_result_response(response) -> None:
184184
raise KlingApiError(error_msg)
185185

186186

187+
def validate_input_image(image: torch.Tensor) -> None:
188+
"""
189+
Validates the input image adheres to the expectations of the Kling API:
190+
- The image resolution should not be less than 300*300px
191+
- The aspect ratio of the image should be between 1:2.5 ~ 2.5:1
192+
193+
See: https://app.klingai.com/global/dev/document-api/apiReference/model/imageToVideo
194+
"""
195+
if len(image.shape) == 4:
196+
height, width = image.shape[1], image.shape[2]
197+
elif len(image.shape) == 3:
198+
height, width = image.shape[0], image.shape[1]
199+
else:
200+
raise ValueError("Invalid image tensor shape.")
201+
202+
# Ensure minimum resolution is met
203+
if height < 300:
204+
raise ValueError("Image height must be at least 300px")
205+
if width < 300:
206+
raise ValueError("Image width must be at least 300px")
207+
208+
# Ensure aspect ratio is within acceptable range
209+
aspect_ratio = width / height
210+
if aspect_ratio < 1 / 2.5 or aspect_ratio > 2.5:
211+
raise ValueError("Image aspect ratio must be between 1:2.5 and 2.5:1")
212+
213+
187214
def get_camera_control_input_config(
188215
tooltip: str, default: float = 0.0
189216
) -> tuple[IO, InputTypeOptions]:
@@ -530,7 +557,10 @@ def INPUT_TYPES(s):
530557
return {
531558
"required": {
532559
"start_frame": model_field_to_node_input(
533-
IO.IMAGE, KlingImage2VideoRequest, "image"
560+
IO.IMAGE,
561+
KlingImage2VideoRequest,
562+
"image",
563+
tooltip="The reference image used to generate the video.",
534564
),
535565
"prompt": model_field_to_node_input(
536566
IO.STRING, KlingImage2VideoRequest, "prompt", multiline=True
@@ -607,9 +637,10 @@ def api_call(
607637
auth_token: Optional[str] = None,
608638
) -> tuple[VideoFromFile]:
609639
validate_prompts(prompt, negative_prompt, MAX_PROMPT_LENGTH_I2V)
640+
validate_input_image(start_frame)
610641

611642
if camera_control is not None:
612-
# Camera control type for image 2 video is always simple
643+
# Camera control type for image 2 video is always `simple`
613644
camera_control.type = KlingCameraControlType.simple
614645

615646
initial_operation = SynchronousOperation(

0 commit comments

Comments
 (0)