-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdall-e 2.py
More file actions
36 lines (29 loc) · 813 Bytes
/
Copy pathdall-e 2.py
File metadata and controls
36 lines (29 loc) · 813 Bytes
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
import openai
from PIL import Image
import requests
from io import BytesIO
import random
openai.api_key = "YOURapiKEY"
def resize(image, name):
# Open the image file
img = Image.open(image)
# Convert the image to RGBA format
img = img.convert('RGBA')
img = img.resize((1024, 1024))
img.save(name)
resize("sunflowers.png", "input.png")
resize("mask.png", "input-mask.png")
response = openai.Image.create_edit(
image=open("input.png", "rb"),
mask=open("input-mask.png", "rb"),
prompt="A cute tortoiseshell cat sniffing the sunflowers",
n=1,
size="1024x1024"
)
image_url = response['data'][0]['url']
print(image_url)
response = requests.get(image_url)
img = Image.open(BytesIO(response.content))
img.show()
count = random.randint(0, 1111)
img.save(f"cat-sniffing-sunflowers{count}.png")