Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

How to save DALL-e generated images to memory #2110

Unanswered
Mark531 asked this question in Q&A
Discussion options

I want to generate an image with DALL-e and then use this image as a starting point to generate other images and I'm running into 2 issues:

  1. I can't manage to save the image into a PIL.Image class to work in memory
  2. If I save the image to the disk and load it into a PIL.image, it won't be accepted by the edit() API

Creation of the image:

client = OpenAI(api_key=api_key)
response = client.images.generate(model="dall-e-3", prompt="A puppy wearing a cosmonaut helmet")

1) First issue

image_data = requests.get(response.data[0].url).content
image = Image.frombytes("RGBA", (1024, 1024), image_data, "raw")

This triggers the following error:

ValueError: not enough image data

2) Second issue

http_response = requests.get(response.data[0].url)

with open("/my_image.png", "wb") as fp:
    fp.write(http_response.content)

image = Image.open("/my_image.png")

# Without this conversion, I get an "Invalid input image" error
image = image.convert("RGBA")

response = client.images.edit(image=image.tobytes(), model="dall-e-2", prompt="This character is reading a book")

This triggers the following error:

Uploaded image must be a PNG and less than 4 MB.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.