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
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:
:stop_button: do not use ImageFromPrompt.__generate_image_to_disk if you don't know what you're doing
:warning: :warning: You need to provide a path otherwise the images will be saved to a temporary folder and you may simply not be able to recover them if you don't know what you're doing.
It's not a big deal but since you're only paying 2cents everytime you call the API, you better be careful.
So ... just use public methods :+1: !
you're safe... You can't provide ImageFromPrompt.generate_image with an empty path! :heart: :heart: When a path has been provided & the image already exists (meaning that the image has been generated from the prompt), then the image will be automatically reloaded... meaning you can directly use the object as is for next time.
Disclaimer
Use openAI's image API https://platform.openai.com/docs/api-reference/images/object
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.
Generate and download to disk
Side note:
ImageFromPrompt.__generate_image_to_disk
if you don't know what you're doingImageFromPrompt.generate_image
with an empty path! :heart: :heart: When a path has been provided & the image already exists (meaning that the image has been generated from the prompt), then the image will be automatically reloaded... meaning you can directly use the object as is for next time.