dalle2-in-python
dalle2-in-python copied to clipboard
Add support for creating variations
DALL·E supports an edit API that lets you generate variations on a given image. The image can either be one that was generated by DALL·E and lives on the server, or one that you upload.
Thanks you for your first issue in dalle2-in-python
So, endpoint is https://labs.openai.com/api/labs/tasks, but payload is different. Pay attention to batch_size - it's limited to 3. I'm not sure what is the reasoning behind that (aside their current UI limitations), but I hope that we will have ability to change that number after full release.
like in #10 and #11 we need to have generation ID and put it to [prompt][parent_generation_id]
from time import sleep
import requests
def save_response_images_to_file_api(response: dict):
# save images to disk
pass
auth_header = "Bearer sess-..."
payload = {
"task_type": "variations",
"prompt": {
"batch_size": 3,
"parent_generation_id": "generation-LVAn5NE3twBGOFh6SJOwFxC8",
},
}
content_type = "application/json"
create_task_link = "https://labs.openai.com/api/labs/tasks"
headers = {
"Content-type": content_type,
"Authorization": auth_header,
}
if __name__ == "__main__":
ret = requests.post(create_task_link, json=payload, headers=headers)
ret = ret.json()
sleep(3)
while ret["status"] == "pending":
ret = requests.get(create_task_link + "/" + ret["id"], headers=headers)
ret = ret.json()
sleep(3)
if ret["status"] == "succeeded":
save_response_images_to_file_api(ret)
print("DONE")
That's for the already generated image.
About uploads I will have to look later, they do base64 encoding, but i'm not sure they do it the way I do it. Further testing is required 😄 Probably current functionality for inpainting can do such upload correctly
d
Would be great if you could create this feature as well !