dalle2-in-python icon indicating copy to clipboard operation
dalle2-in-python copied to clipboard

Add support for creating variations

Open charlesjlee opened this issue 3 years ago • 4 comments

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.

charlesjlee avatar Jul 22 '22 01:07 charlesjlee

Thanks you for your first issue in dalle2-in-python

github-actions[bot] avatar Jul 22 '22 01:07 github-actions[bot]

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

kv-crosstech avatar Aug 11 '22 13:08 kv-crosstech

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

kv-crosstech avatar Aug 11 '22 13:08 kv-crosstech

d

Would be great if you could create this feature as well !

zhoujs93 avatar Sep 07 '22 22:09 zhoujs93