- Load and preview a source image
- Call the DALL·E variations endpoint
- Render the generated images
Prerequisites
- Python 3.6+
- Install the OpenAI Python library:
- Set your API key as an environment variable:
1. Import Modules and Configure the API Key
Begin by importing the necessary modules and loading your API key:2. Load and Display the Source Image
Use IPython’s display utilities to preview the original asset:3. Generate Three Variations
Call the DALL·E variation endpoint, specifying the image file, output size, and number of results:You can modify the
size or the n parameter to control the resolution and the number of variations returned.4. Render the Generated Variations
Display each variation using the URLs returned in the response:Summary of Steps
| Step | Description | Example Code |
|---|---|---|
| Import & Authenticate | Load libraries and set API key | openai.api_key = os.getenv("OPENAI_API_KEY") |
| Preview Source Image | Display the original image | display(Image(...)) |
| Request Variations | Generate n new images with specified size | openai.Image.create_variation(...) |
| Render Outputs | Show each variation using returned URLs | display(Image(url=...)) |