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

Add support to make image public and generate shareable link

Open charlesjlee opened this issue 3 years ago • 1 comments

The DALL·E UI allows you to designate an image as public and then creates a shareable link. It would be nice to be able to do this programatically.

charlesjlee avatar Jul 22 '22 01:07 charlesjlee

So, there's additional steps required. After generation of images it returns generation with id

{
  "generations": {
    "data": [
      {
        "id": "generation-KdiiXg780fGKdfOEiMXI8Tnf",
        ...
      },
      ..,
    ]
  }
}

that KdiiXg780fGKdfOEiMXI8Tnf is what we will need later on

we launch empty POST request to https://labs.openai.com/api/labs/generations/generation-KdiiXg780fGKdfOEiMXI8Tnf/share and then after result is received we generate link like they do (it's not in the response) https://labs.openai.com/s/KdiiXg780fGKdfOEiMXI8Tnf

import requests

auth_header = "Bearer sess-......"

generation = "KdiiXg780fGKdfOEiMXI8Tnf"

ret = requests.post(
    f"https://labs.openai.com/api/labs/generations/generation-{generation}/share",
    headers={"Authorization": auth_header},
)
print(ret.json())
print(f"Your share link: https://labs.openai.com/s/{generation}")

And, yes, link returns 404 before it, so /share is required

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