balthazarneveu / interactive_pipe

create interactive image processing pipeline with friendly sliders
The Unlicense
5 stars 1 forks source link

image from prompts using openai Dall-e API #27

Closed balthazarneveu closed 1 year ago

balthazarneveu commented 1 year ago

Disclaimer

image

  • Using the openAI service costs a few cents per request.
  • You need to know what you're doing here, refer to https://platform.openai.com/ to get an account and check billing options.
  • For obvious reasons: Internet access is mandatory for obvious reasons An API token is required or to be provided directly when calling the class. To be more convenient, user can set OPENAI_API_KEY in their os environment variables
  • such as ~/zsh.rc under linux
  • in the global environment variables under windows

Use openAI's image API https://platform.openai.com/docs/api-reference/images/object

image

How to use the ImageFromPrompt class?

Load into RAM as an image object

Image is loaded in memory. img.data is a numpy array . It can be used conveniently afterwards inside the interactive pipe.

from interactive_pipe.thirdparty.images_openai_api import ImageFromPrompt
img = ImageFromPrompt(
    "a smiling elephant walking in the sunny yellow savana in a modern kid book drawing style on a white background",
    "images/elephant_openai.png"
)
img.show()

Generate and download to disk

out = ImageFromPrompt.generate_image_to_disk(
    "a smiling elephant walking in the sunny yellow savana in a modern kid book drawing style on a white background",
    "images/elephant_openai.png"
)
assert out.exists()
print(out)

Side note: