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

[BUG]: Unable to get more than 1 output image from a workflow #95

Open
julien-moment opened this issue Jan 29, 2025 · 2 comments
Open
Labels
bug Something isn't working

Comments

@julien-moment
Copy link

Describe the bug

I have a workflow with one single Save image node (core) at the end.
This workflow is supposed to generate 4 images using Batch-condition Batch-String custom node to send 4 different prompts.
It works properly in the Web UI generating all 4 images but when used with the runpod-worker-comfy it only sends 1 image in the result message (Base64 encoded) instead of 4, but I can see that the 4 imgs have been generated in the output folder.
So it seems that the worker API isn't able to get the 3 other images... ?

I have the same issue running everything on runpod and on my local server.

Repro MVP (Minimal Viable Procedure)

Here is a simple workflow example, generating 4 images using Batch Condition node :
Batch Image Generation.json

Image

Expected behavior

I expect the result message having all 4 images base64 encoded.

Screenshots

Versions (please complete the following information):

  • ComfyUI version: 0.3.12
  • Host OS: Ubuntu 22.04
  • Docker version: ??

Additional context

@julien-moment julien-moment added the bug Something isn't working label Jan 29, 2025
@bluematter
Copy link

Same issue, the problem is here

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"])

Every time the loop iterates over an image, it assigns a new value to output_images instead of adding to a list. Thus, if you have multiple images, only the final image’s path will remain in output_images.

The proposed solution from chatGPT is

def process_output_images(outputs, job_id):
    COMFY_OUTPUT_PATH = os.environ.get("COMFY_OUTPUT_PATH", "/comfyui/output")
    
    # Use a list to accumulate image paths
    output_images = []

    for node_id, node_output in outputs.items():
        if "images" in node_output:
            for image in node_output["images"]:
                image_path = os.path.join(image["subfolder"], image["filename"])
                output_images.append(image_path)

    print("runpod-worker-comfy - image generation is done")
    
    # Check if any images were found
    if not output_images:
        print("runpod-worker-comfy - no images found in the outputs")
        return {
            "status": "error",
            "message": "No images were generated in the output.",
        }

    # Process each image: upload or encode
    processed_images = []
    for rel_path in output_images:
        local_image_path = os.path.join(COMFY_OUTPUT_PATH, rel_path)
        print(f"runpod-worker-comfy - Processing image at {local_image_path}")
    
        if os.path.exists(local_image_path):
            if os.environ.get("BUCKET_ENDPOINT_URL", False):
                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:
                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:
            print(f"runpod-worker-comfy - the image does not exist: {local_image_path}")
            processed_images.append(f"Error: Image does not exist at {local_image_path}")

    return {
        "status": "success",
        "message": processed_images,
    }

Im forking and will submit a PR if it fixes it

@bluematter
Copy link

Submitted a PR works for me #96 enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants