-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdall-e.py
48 lines (33 loc) · 1.46 KB
/
dall-e.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# /!\ use openai==0.28.1, pip install openai==0.28.1, openai.image.create is deprecated with version of openai > 1.0.0
import os
import openai
import base64
from datetime import datetime
from IPython.display import Image
from IPython import display
openai.api_key = ""
##############################################################################
prompt = "Draw a logo for a house named Chatka. The logo should represent the roof of the house with smoke coming out of the chimney, at the bottom a central wooden window should be visible, and on the first floor a cooking pot should be the base of the house."
##############################################################################
os.makedirs('outputs', exist_ok=True)
# Number of images to generate
num_images = 3
for i in range(num_images):
now = datetime.now()
timestamp = now.strftime("%Y%m%d%H%M%S")
# Call the OpenAI API to generate an image
response = openai.Image.create(
prompt=prompt,
model="dall-e-3", # Update to the latest model if necessary
size="1024x1024",
response_format="b64_json"
)
# Decode the base64 image
image_b64 = response['data'][0]['b64_json']
imgdata = base64.b64decode(image_b64)
# Save the image to a file
filename = f'outputs/{timestamp}_image.jpg'
with open(filename, 'wb') as f:
f.write(imgdata)
# Optionally display the image in a Jupyter notebook
display.display(Image(filename=filename))