Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow to process multiple images #96

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions src/rp_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,45 +232,45 @@ def process_output_images(outputs, job_id):
# The path where ComfyUI stores the generated images
COMFY_OUTPUT_PATH = os.environ.get("COMFY_OUTPUT_PATH", "/comfyui/output")

output_images = {}
# Changed from a dictionary to a list to collect multiple image paths
output_images = []

for node_id, node_output in outputs.items():
if "images" in node_output:
for image in node_output["images"]:
output_images = os.path.join(image["subfolder"], image["filename"])
# Append each image's path (combining subfolder and filename) instead of overwriting
output_images.append(os.path.join(image["subfolder"], image["filename"]))

print(f"runpod-worker-comfy - image generation is done")

# expected image output folder
local_image_path = f"{COMFY_OUTPUT_PATH}/{output_images}"
processed_images = [] # List to store the processed images (either URL or base64)

print(f"runpod-worker-comfy - {local_image_path}")
# Process each image found in the outputs
for rel_path in output_images:
# expected image output folder
local_image_path = f"{COMFY_OUTPUT_PATH}/{rel_path}"

# The image is in the output folder
if os.path.exists(local_image_path):
if os.environ.get("BUCKET_ENDPOINT_URL", False):
# URL to image in AWS S3
image = rp_upload.upload_image(job_id, local_image_path)
print(
"runpod-worker-comfy - the image was generated and uploaded to AWS S3"
)
print(f"runpod-worker-comfy - {local_image_path}")

# The image is in the output folder
if os.path.exists(local_image_path):
if os.environ.get("BUCKET_ENDPOINT_URL", False):
# URL to image in AWS S3
image_result = rp_upload.upload_image(job_id, local_image_path)
print("runpod-worker-comfy - the image was generated and uploaded to AWS S3")
else:
# base64 image
image_result = base64_encode(local_image_path)
print("runpod-worker-comfy - the image was generated and converted to base64")
processed_images.append(image_result)
else:
# base64 image
image = base64_encode(local_image_path)
print(
"runpod-worker-comfy - the image was generated and converted to base64"
)
print("runpod-worker-comfy - the image does not exist in the output folder")
processed_images.append(f"the image does not exist in the specified output folder: {local_image_path}")

return {
"status": "success",
"message": image,
}
else:
print("runpod-worker-comfy - the image does not exist in the output folder")
return {
"status": "error",
"message": f"the image does not exist in the specified output folder: {local_image_path}",
}
return {
"status": "success",
"message": processed_images,
}


def handler(job):
Expand Down