-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
41 lines (30 loc) · 796 Bytes
/
script.py
File metadata and controls
41 lines (30 loc) · 796 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
37
38
39
40
41
import os
import openai
from PIL import Image
import requests
from io import BytesIO
import sys
input_string = sys.argv[1]
#print(f"Received string from JavaScript: {input_string}")
def save_file(data, prefix, extension):
counter = 1
while True:
file_name = f"{prefix}_{counter:03d}.{extension}"
if not os.path.exists(file_name):
img.save(file_name)
break
counter += 1
PROMPT = input_string
#add your API key below
openai.api_key = " API key goes here... "
response = openai.Image.create(
prompt=PROMPT,
n=1,
size="256x256",
)
imshow = (response["data"][0]["url"])
response = requests.get(imshow)
img = Image.open(BytesIO(response.content))
#img.show()
img.save("output.jpg")
save_file(img, "Outputs/D_im", "jpg")