-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenAIImage.py
More file actions
33 lines (21 loc) · 775 Bytes
/
Copy pathOpenAIImage.py
File metadata and controls
33 lines (21 loc) · 775 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
# API call to Open AI
# OPENAI_API_KEY is obtained from https://platform.openai.com/playground, click on account and select "View API Keys"
# Set as an environment variable under Windows Control Panel
import os
import openai # install via python -m pip install openai
import webbrowser
openai.api_key = os.getenv("OPENAI_API_KEY")
image_request = input("What image do you want to request: ")
response = openai.Image.create(
prompt= image_request, #"A cute baby sea otter",
n=2,
size="1024x1024"
)
print("OpenAI Response Data Type:")
print(type(response))
print("\nOpenAI Response:")
print(response)
print("\nOpenAI Image URL:")
print(response["data"][0]["url"])
print("\nLaunching browser to display image...\n")
webbrowser.open(response["data"][0]["url"])