OpenAI
Generate images using OpenAI API in Python
Create and save images with OpenAIās DALLĀ·E 3. Set prompts, choose image size and quality, download the image, save it to a file, and handle errors if retrieval fails.
Required packages
You need below packages to use the code generated by recipe. All packages are automatically installed in MLJAR Studio.
openai>=1.35.14
pillow>=10.2.0
requests>=2.31.0
Interactive recipe
You can use below interactive recipe to generate code. This recipe is available in MLJAR Studio.
In the below recipe, we assume that you have following variables available in your notebook:
- client (type OpenAI)
Python code
# Python code will be hereCode explanation
- Create the image generation request.
- Save the response as a variable.
- Define the image path.
- Save and dispay the image.
Example Python notebooks
Please find inspiration in example notebooks
OpenAI cookbook
Code recipes from OpenAI cookbook.
- Ā« Previous
- Files embeddings
- Next Ā»
- Speech transcriptions