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

Get Output Images (without s3) #5

Closed
Dekita opened this issue Oct 13, 2023 · 8 comments
Closed

Get Output Images (without s3) #5

Dekita opened this issue Oct 13, 2023 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@Dekita
Copy link
Contributor

Dekita commented Oct 13, 2023

is it possible to obtain the output images without using an s3 bucket? if so, how? :)

I see they are being stored at '"simulated_uploaded/xyz.png", but thats relative to the serverless container right? so how can this be accessed when the job completes?

@TimPietrusky TimPietrusky self-assigned this Oct 13, 2023
@Satttoshi
Copy link

Yeah s3 bucket setup is insane, I think a plain b64 image would be alot more "comf"-ortable

@TimPietrusky
Copy link
Member

@Dekita yeah, I also think that a base64-encoded image (as suggested by @Satttoshi) would be the way to go to not force someone to setup an S3 bucket. Would that work for you?

@Dekita
Copy link
Contributor Author

Dekita commented Oct 13, 2023

b64 would be perfect. I had tried to implement that change myself last night, but for some reason when i pull the image from my private repo on runpod, i just get bash error when its trying to boot lol.

b64 should be super easy to get with something like this anyway:

import base64

def base64_encode(img_path):
    """
    Returns base64 encoded image.
    """
    with open(img_path, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read())
        return encoded_string.decode("utf-8")

@TimPietrusky TimPietrusky added the enhancement New feature or request label Oct 13, 2023
@Dekita
Copy link
Contributor Author

Dekita commented Oct 14, 2023

confirmed adding the following code into rp_handler.py works:

# at top of file:
import base64

def base64_encode(img_path):
    """
    Returns base64 encoded image.
    """
    with open(img_path, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read())
        return encoded_string.decode("utf-8")
    

# in handler(job) function: (in place of return value if os.path.exists()
print("runpod-worker-comfy - the image exists in the output folder")
print("runpod-worker-comfy - preparing base64 encoded output")
image_url = rp_upload.upload_image(
    job["id"], f"{COMFY_OUTPUT_PATH}/{output_images}"
)
return_base64 = "simulated_uploaded/" in image_url
return_output = f"{image_url}" if not return_base64 else base64_encode(f"{COMFY_OUTPUT_PATH}/{output_images}")
return {
    "status": "success", 
    "message": return_output, 
}

if you want i can make a pr with the changes :)

@TimPietrusky
Copy link
Member

@Dekita this looks really clean, please provide the PR! Thank you very much <3

@TimPietrusky
Copy link
Member

Thanks to @Dekita we have base64 output now. The changes are in dev timpietruskyblibla/runpod-worker-comfy:dev. Please try them (ping @Satttoshi) and let me know if everything is fine!

We should mention, that if you don't configure the S3 env variables, then the output will be base64. I will update the docs once the dev-image is actually fine and create a new release.

@TimPietrusky
Copy link
Member

@Dekita when testing this locally, I was not able to actually get a proper result. I need to test this again and actually start to write some tests, like #4 demands it ;)

@TimPietrusky
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants