open ai: https://openai.com/blog/openai-api
""" 생성 """
import openai
import webbrowser
import os
# Replace YOUR_API_KEY with your OpenAI API key
client = openai.OpenAI(api_key = "API KEY")
# Call the API
# 1장 생성 시 0.03$
response = client.images.generate(
model="dall-e-3",
prompt="a cute cat with a hat on",
size="1024x1024",
quality="standard",
n=1,
)
# Show the result that has been pushed to an url
webbrowser.open(response.data[0].url)
+) url을 통해 이미지 저장
""" 이미지 저장"""
# curl 요청
url = response.data[0].url
import urllib.request
import time
img_dest = "./"
start = time.time()
urllib.request.urlretrieve(url, img_dest+"result.jpg")
end = time.time()
print(f"총 소요시간 {end-start}초")