-
Notifications
You must be signed in to change notification settings - Fork 4.3k
-
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:
- I can't manage to save the image into a PIL.Image class to work in memory
- 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.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment