ezzcodeezzlife / dalle2-in-python

Use DALL·E 2 in Python
https://pypi.org/project/dalle2/
MIT License
178 stars 34 forks source link

Invalid request error when running inpainting example code #26

Closed benjiebob closed 1 year ago

benjiebob commented 1 year ago

Describe the bug Running example inpainting code results in the following error:

{
  "error": {
    "message": "Your image was invalid.",
    "type": "invalid_request_error",
    "param": "masked_image",
    "code": "invalid_image"
  }
}

To Reproduce Steps to reproduce the behavior:

  1. Obtain the token per instructions and set dalle = Dalle2(token)
  2. Wget an example image, e.g. wget https://thumbs.dreamstime.com/b/golden-retriever-dog-21668976.jpg
  3. Replace image = Image.open('my_image.png') with the path to the image file
  4. Replace .png with .webp extension in generate_from_masked_image call. This seems a bug.
  5. Run the example code
  6. See error as above

Expected behavior DALLE-2 should accept the uploaded image and inpaint according to the text description.

Other notes

github-actions[bot] commented 1 year ago

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

nitish116 commented 1 year ago

Yes. Still facing the same issue. Request to take a look at the inpainting / masked images demo. Thanks!

Wheest commented 1 year ago

I am also experiencing this issue. I get the same error above when I upload a webp (with quite a long wait time).

If I upload the file as a PNG, I get the following error (with a normal/shorter wait time).

 {'type': 'error', 'message': 'Your task failed. Sorry about that! Please try again.', 'code': 'task_failed'}

Looking at the actual API requests on the web UI, I believe that the uploaded image should be a PNG. The header in the image and masked_image fields look like a PNG to me, i.e. iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAYAAAB/....

However, even as a PNG I still get the error. Also, I note that now the default value of inpainting_batch_size is 4 on the web UI, however changing this on the Python side still doesn't fix the error.

Printing out the response, I can see that my images are successfully uploaded to the https://openailabsprodscus.blob.core.windows.net server (and are stored as webp). My conclusion is that PNG is the right format to use here, but there's something else going on.

Wheest commented 1 year ago

Okay, I think I've figured out the issue. The API expects square 1024x1024 images in the PNG format. I have put in a PR that clarifies this in the README

ezzcodeezzlife commented 1 year ago

solved in #27 thanks everyone for the inputs