Skip to content

Commit 36747f2

Browse files
committed
chore(api-nodes): add upload_image_to_comfyapi to make code look better
1 parent 8ccc0c9 commit 36747f2

File tree

13 files changed

+75
-61
lines changed

13 files changed

+75
-61
lines changed

comfy_api_nodes/nodes_bytedance.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
image_tensor_pair_to_batch,
3131
poll_op,
3232
sync_op,
33+
upload_image_to_comfyapi,
3334
upload_images_to_comfyapi,
3435
validate_image_aspect_ratio,
3536
validate_image_dimensions,
@@ -249,7 +250,7 @@ async def execute(
249250
if get_number_of_images(image) != 1:
250251
raise ValueError("Exactly one input image is required.")
251252
validate_image_aspect_ratio(image, (1, 3), (3, 1))
252-
source_url = (await upload_images_to_comfyapi(cls, image, max_images=1, mime_type="image/png"))[0]
253+
source_url = await upload_image_to_comfyapi(cls, image, mime_type="image/png")
253254
payload = Image2ImageTaskCreationRequest(
254255
model=model,
255256
prompt=prompt,
@@ -702,7 +703,7 @@ async def execute(
702703
validate_image_dimensions(image, min_width=300, min_height=300, max_width=6000, max_height=6000)
703704
validate_image_aspect_ratio(image, (2, 5), (5, 2), strict=False) # 0.4 to 2.5
704705

705-
image_url = (await upload_images_to_comfyapi(cls, image, max_images=1))[0]
706+
image_url = await upload_image_to_comfyapi(cls, image)
706707
prompt = (
707708
f"{prompt} "
708709
f"--resolution {resolution} "

comfy_api_nodes/nodes_kling.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
sync_op,
7272
tensor_to_base64_string,
7373
upload_audio_to_comfyapi,
74+
upload_image_to_comfyapi,
7475
upload_images_to_comfyapi,
7576
upload_video_to_comfyapi,
7677
validate_image_aspect_ratio,
@@ -958,7 +959,7 @@ async def execute(
958959
validate_image_aspect_ratio(first_frame, (1, 2.5), (2.5, 1))
959960
image_list: list[OmniParamImage] = [
960961
OmniParamImage(
961-
image_url=(await upload_images_to_comfyapi(cls, first_frame, wait_label="Uploading first frame"))[0],
962+
image_url=await upload_image_to_comfyapi(cls, first_frame, wait_label="Uploading first frame"),
962963
type="first_frame",
963964
)
964965
]
@@ -967,7 +968,7 @@ async def execute(
967968
validate_image_aspect_ratio(end_frame, (1, 2.5), (2.5, 1))
968969
image_list.append(
969970
OmniParamImage(
970-
image_url=(await upload_images_to_comfyapi(cls, end_frame, wait_label="Uploading end frame"))[0],
971+
image_url=await upload_image_to_comfyapi(cls, end_frame, wait_label="Uploading end frame"),
971972
type="end_frame",
972973
)
973974
)
@@ -2365,7 +2366,7 @@ async def execute(
23652366
response_model=TaskStatusResponse,
23662367
data=ImageToVideoWithAudioRequest(
23672368
model_name=model_name,
2368-
image=(await upload_images_to_comfyapi(cls, start_frame))[0],
2369+
image=await upload_image_to_comfyapi(cls, start_frame),
23692370
prompt=prompt,
23702371
mode=mode,
23712372
duration=str(duration),
@@ -2459,7 +2460,7 @@ async def execute(
24592460
response_model=TaskStatusResponse,
24602461
data=MotionControlRequest(
24612462
prompt=prompt,
2462-
image_url=(await upload_images_to_comfyapi(cls, reference_image))[0],
2463+
image_url=await upload_image_to_comfyapi(cls, reference_image),
24632464
video_url=await upload_video_to_comfyapi(cls, reference_video),
24642465
keep_original_sound="yes" if keep_original_sound else "no",
24652466
character_orientation=character_orientation,

comfy_api_nodes/nodes_ltxv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
ApiEndpoint,
99
get_number_of_images,
1010
sync_op_raw,
11-
upload_images_to_comfyapi,
11+
upload_image_to_comfyapi,
1212
validate_string,
1313
)
1414

@@ -187,7 +187,7 @@ async def execute(
187187
cls,
188188
ApiEndpoint("/proxy/ltx/v1/image-to-video", "POST"),
189189
data=ExecuteTaskRequest(
190-
image_uri=(await upload_images_to_comfyapi(cls, image, max_images=1, mime_type="image/png"))[0],
190+
image_uri=await upload_image_to_comfyapi(cls, image, mime_type="image/png"),
191191
prompt=prompt,
192192
model=MODELS_MAP[model],
193193
duration=duration,

comfy_api_nodes/nodes_luma.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
download_url_to_video_output,
3131
poll_op,
3232
sync_op,
33+
upload_image_to_comfyapi,
3334
upload_images_to_comfyapi,
3435
validate_string,
3536
)
@@ -257,8 +258,8 @@ async def _convert_luma_refs(cls, luma_ref: LumaReferenceChain, max_refs: int):
257258
luma_urls = []
258259
ref_count = 0
259260
for ref in luma_ref.refs:
260-
download_urls = await upload_images_to_comfyapi(cls, ref.image, max_images=1)
261-
luma_urls.append(download_urls[0])
261+
download_url = await upload_image_to_comfyapi(cls, ref.image)
262+
luma_urls.append(download_url)
262263
ref_count += 1
263264
if ref_count >= max_refs:
264265
break
@@ -340,8 +341,7 @@ async def execute(
340341
image_weight: float,
341342
seed,
342343
) -> IO.NodeOutput:
343-
download_urls = await upload_images_to_comfyapi(cls, image, max_images=1)
344-
image_url = download_urls[0]
344+
image_url = await upload_image_to_comfyapi(cls, image)
345345
response_api = await sync_op(
346346
cls,
347347
ApiEndpoint(path="/proxy/luma/generations/image", method="POST"),
@@ -589,11 +589,9 @@ async def _convert_to_keyframes(
589589
frame0 = None
590590
frame1 = None
591591
if first_image is not None:
592-
download_urls = await upload_images_to_comfyapi(cls, first_image, max_images=1)
593-
frame0 = LumaImageReference(type="image", url=download_urls[0])
592+
frame0 = LumaImageReference(type="image", url=await upload_image_to_comfyapi(cls, first_image))
594593
if last_image is not None:
595-
download_urls = await upload_images_to_comfyapi(cls, last_image, max_images=1)
596-
frame1 = LumaImageReference(type="image", url=download_urls[0])
594+
frame1 = LumaImageReference(type="image", url=await upload_image_to_comfyapi(cls, last_image))
597595
return LumaKeyframes(frame0=frame0, frame1=frame1)
598596

599597

comfy_api_nodes/nodes_meshy.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
download_url_to_bytesio,
2424
poll_op,
2525
sync_op,
26+
upload_image_to_comfyapi,
2627
upload_images_to_comfyapi,
2728
validate_string,
2829
)
@@ -197,7 +198,7 @@ async def execute(
197198
if texture_prompt:
198199
validate_string(texture_prompt, field_name="texture_prompt", max_length=600)
199200
if texture_image is not None:
200-
texture_image_url = (await upload_images_to_comfyapi(cls, texture_image, wait_label="Uploading texture"))[0]
201+
texture_image_url = await upload_image_to_comfyapi(cls, texture_image, wait_label="Uploading texture")
201202
response = await sync_op(
202203
cls,
203204
endpoint=ApiEndpoint(path="/proxy/meshy/openapi/v2/text-to-3d", method="POST"),
@@ -344,17 +345,15 @@ async def execute(
344345
validate_string(should_texture["texture_prompt"], field_name="texture_prompt", max_length=600)
345346
texture_prompt = should_texture["texture_prompt"]
346347
if should_texture["texture_image"] is not None:
347-
texture_image_url = (
348-
await upload_images_to_comfyapi(
349-
cls, should_texture["texture_image"], wait_label="Uploading texture"
350-
)
351-
)[0]
348+
texture_image_url = await upload_image_to_comfyapi(
349+
cls, should_texture["texture_image"], wait_label="Uploading texture"
350+
)
352351
response = await sync_op(
353352
cls,
354353
ApiEndpoint(path="/proxy/meshy/openapi/v1/image-to-3d", method="POST"),
355354
response_model=MeshyTaskResponse,
356355
data=MeshyImageToModelRequest(
357-
image_url=(await upload_images_to_comfyapi(cls, image, wait_label="Uploading base image"))[0],
356+
image_url=await upload_image_to_comfyapi(cls, image, wait_label="Uploading base image"),
358357
ai_model=model,
359358
topology=should_remesh.get("topology", None),
360359
target_polycount=should_remesh.get("target_polycount", None),
@@ -505,11 +504,9 @@ async def execute(
505504
validate_string(should_texture["texture_prompt"], field_name="texture_prompt", max_length=600)
506505
texture_prompt = should_texture["texture_prompt"]
507506
if should_texture["texture_image"] is not None:
508-
texture_image_url = (
509-
await upload_images_to_comfyapi(
510-
cls, should_texture["texture_image"], wait_label="Uploading texture"
511-
)
512-
)[0]
507+
texture_image_url = await upload_image_to_comfyapi(
508+
cls, should_texture["texture_image"], wait_label="Uploading texture"
509+
)
513510
response = await sync_op(
514511
cls,
515512
ApiEndpoint(path="/proxy/meshy/openapi/v1/multi-image-to-3d", method="POST"),
@@ -595,7 +592,7 @@ async def execute(
595592
) -> IO.NodeOutput:
596593
texture_image_url = None
597594
if texture_image is not None:
598-
texture_image_url = (await upload_images_to_comfyapi(cls, texture_image, wait_label="Uploading texture"))[0]
595+
texture_image_url = await upload_image_to_comfyapi(cls, texture_image, wait_label="Uploading texture")
599596
response = await sync_op(
600597
cls,
601598
endpoint=ApiEndpoint(path="/proxy/meshy/openapi/v1/rigging", method="POST"),
@@ -746,7 +743,7 @@ async def execute(
746743
raise ValueError("Either text_style_prompt or image_style is required")
747744
image_style_url = None
748745
if image_style is not None:
749-
image_style_url = (await upload_images_to_comfyapi(cls, image_style, wait_label="Uploading style"))[0]
746+
image_style_url = await upload_image_to_comfyapi(cls, image_style, wait_label="Uploading style")
750747
response = await sync_op(
751748
cls,
752749
endpoint=ApiEndpoint(path="/proxy/meshy/openapi/v1/retexture", method="POST"),

comfy_api_nodes/nodes_minimax.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
download_url_to_video_output,
1818
poll_op,
1919
sync_op,
20-
upload_images_to_comfyapi,
20+
upload_image_to_comfyapi,
2121
validate_string,
2222
)
2323

@@ -39,12 +39,12 @@ async def _generate_mm_video(
3939
validate_string(prompt_text, field_name="prompt_text")
4040
image_url = None
4141
if image is not None:
42-
image_url = (await upload_images_to_comfyapi(cls, image, max_images=1))[0]
42+
image_url = await upload_image_to_comfyapi(cls, image)
4343

4444
# TODO: figure out how to deal with subject properly, API returns invalid params when using S2V-01 model
4545
subject_reference = None
4646
if subject is not None:
47-
subject_url = (await upload_images_to_comfyapi(cls, subject, max_images=1))[0]
47+
subject_url = await upload_image_to_comfyapi(cls, subject)
4848
subject_reference = [SubjectReferenceItem(image=subject_url)]
4949

5050
response = await sync_op(
@@ -384,7 +384,7 @@ async def execute(
384384
# upload image, if passed in
385385
image_url = None
386386
if first_frame_image is not None:
387-
image_url = (await upload_images_to_comfyapi(cls, first_frame_image, max_images=1))[0]
387+
image_url = await upload_image_to_comfyapi(cls, first_frame_image)
388388

389389
response = await sync_op(
390390
cls,

comfy_api_nodes/nodes_moonvalley.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
poll_op,
1717
sync_op,
1818
trim_video,
19-
upload_images_to_comfyapi,
19+
upload_image_to_comfyapi,
2020
upload_video_to_comfyapi,
2121
validate_container_format_is_mp4,
2222
validate_image_dimensions,
@@ -267,7 +267,7 @@ async def execute(
267267

268268
# Get MIME type from tensor - assuming PNG format for image tensors
269269
mime_type = "image/png"
270-
image_url = (await upload_images_to_comfyapi(cls, image, max_images=1, mime_type=mime_type))[0]
270+
image_url = await upload_image_to_comfyapi(cls, image, mime_type=mime_type)
271271
task_creation_response = await sync_op(
272272
cls,
273273
endpoint=ApiEndpoint(path=API_IMG2VIDEO_ENDPOINT, method="POST"),

comfy_api_nodes/nodes_runway.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
validate_string,
3737
validate_image_dimensions,
3838
validate_image_aspect_ratio,
39+
upload_image_to_comfyapi,
3940
upload_images_to_comfyapi,
4041
download_url_to_video_output,
4142
download_url_to_image_tensor,
@@ -203,10 +204,9 @@ async def execute(
203204
validate_image_dimensions(start_frame, max_width=7999, max_height=7999)
204205
validate_image_aspect_ratio(start_frame, (1, 2), (2, 1))
205206

206-
download_urls = await upload_images_to_comfyapi(
207+
download_url = await upload_image_to_comfyapi(
207208
cls,
208209
start_frame,
209-
max_images=1,
210210
mime_type="image/png",
211211
)
212212

@@ -220,7 +220,7 @@ async def execute(
220220
duration=Duration(duration),
221221
ratio=AspectRatio(ratio),
222222
promptImage=RunwayPromptImageObject(
223-
root=[RunwayPromptImageDetailedObject(uri=str(download_urls[0]), position="first")]
223+
root=[RunwayPromptImageDetailedObject(uri=str(download_url), position="first")]
224224
),
225225
),
226226
)
@@ -297,10 +297,9 @@ async def execute(
297297
validate_image_dimensions(start_frame, max_width=7999, max_height=7999)
298298
validate_image_aspect_ratio(start_frame, (1, 2), (2, 1))
299299

300-
download_urls = await upload_images_to_comfyapi(
300+
download_url = await upload_image_to_comfyapi(
301301
cls,
302302
start_frame,
303-
max_images=1,
304303
mime_type="image/png",
305304
)
306305

@@ -314,7 +313,7 @@ async def execute(
314313
duration=Duration(duration),
315314
ratio=AspectRatio(ratio),
316315
promptImage=RunwayPromptImageObject(
317-
root=[RunwayPromptImageDetailedObject(uri=str(download_urls[0]), position="first")]
316+
root=[RunwayPromptImageDetailedObject(uri=str(download_url), position="first")]
318317
),
319318
),
320319
estimated_duration=AVERAGE_DURATION_FLF_SECONDS,
@@ -488,13 +487,12 @@ async def execute(
488487
if reference_image is not None:
489488
validate_image_dimensions(reference_image, max_width=7999, max_height=7999)
490489
validate_image_aspect_ratio(reference_image, (1, 2), (2, 1))
491-
download_urls = await upload_images_to_comfyapi(
490+
download_url = await upload_image_to_comfyapi(
492491
cls,
493492
reference_image,
494-
max_images=1,
495493
mime_type="image/png",
496494
)
497-
reference_images = [ReferenceImage(uri=str(download_urls[0]))]
495+
reference_images = [ReferenceImage(uri=str(download_url))]
498496

499497
initial_response = await sync_op(
500498
cls,

comfy_api_nodes/nodes_topaz.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
get_number_of_images,
3232
poll_op,
3333
sync_op,
34-
upload_images_to_comfyapi,
34+
upload_image_to_comfyapi,
3535
validate_container_format_is_mp4,
3636
)
3737

@@ -169,9 +169,7 @@ async def execute(
169169
) -> IO.NodeOutput:
170170
if get_number_of_images(image) != 1:
171171
raise ValueError("Only one input image is supported.")
172-
download_url = await upload_images_to_comfyapi(
173-
cls, image, max_images=1, mime_type="image/png", total_pixels=4096 * 4096
174-
)
172+
download_url = await upload_image_to_comfyapi(cls, image, mime_type="image/png", total_pixels=4096 * 4096)
175173
initial_response = await sync_op(
176174
cls,
177175
ApiEndpoint(path="/proxy/topaz/image/v1/enhance-gen/async", method="POST"),
@@ -189,7 +187,7 @@ async def execute(
189187
creativity=creativity,
190188
face_preservation=str(face_preservation).lower(),
191189
color_preservation=str(color_preservation).lower(),
192-
source_url=download_url[0],
190+
source_url=download_url,
193191
output_format="png",
194192
),
195193
content_type="multipart/form-data",

comfy_api_nodes/nodes_tripo.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
download_url_as_bytesio,
3030
poll_op,
3131
sync_op,
32-
upload_images_to_comfyapi,
32+
upload_image_to_comfyapi,
3333
)
3434
from folder_paths import get_output_directory
3535

@@ -298,7 +298,7 @@ async def execute(
298298
raise RuntimeError("Image is required")
299299
tripo_file = TripoFileReference(
300300
root=TripoUrlReference(
301-
url=(await upload_images_to_comfyapi(cls, image, max_images=1))[0],
301+
url=await upload_image_to_comfyapi(cls, image),
302302
type="jpeg",
303303
)
304304
)
@@ -438,9 +438,7 @@ async def execute(
438438
if image_ is not None:
439439
images.append(
440440
TripoFileReference(
441-
root=TripoUrlReference(
442-
url=(await upload_images_to_comfyapi(cls, image_, max_images=1))[0], type="jpeg"
443-
)
441+
root=TripoUrlReference(url=await upload_image_to_comfyapi(cls, image_), type="jpeg")
444442
)
445443
)
446444
else:
@@ -637,7 +635,7 @@ def define_schema(cls):
637635
"preset:hexapod:walk",
638636
"preset:octopod:walk",
639637
"preset:serpentine:march",
640-
"preset:aquatic:march"
638+
"preset:aquatic:march",
641639
],
642640
),
643641
],
@@ -841,7 +839,7 @@ async def execute(
841839
# Parse part_names from comma-separated string to list
842840
part_names_list = None
843841
if part_names and part_names.strip():
844-
part_names_list = [name.strip() for name in part_names.split(',') if name.strip()]
842+
part_names_list = [name.strip() for name in part_names.split(",") if name.strip()]
845843

846844
response = await sync_op(
847845
cls,

0 commit comments

Comments
 (0)