-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04-image-generation.py
More file actions
32 lines (27 loc) · 917 Bytes
/
Copy path04-image-generation.py
File metadata and controls
32 lines (27 loc) · 917 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
import os
from PIL import Image
from openai import AzureOpenAI
from dotenv import load_dotenv
import requests
load_dotenv()
dalle3client = AzureOpenAI(
api_version=os.environ["AZURE_IMAGE_GEN_API_VERSION"],
azure_endpoint=os.environ["AZURE_IMAGE_GENERATION_ENDPOINT"],
api_key= os.environ["AZURE_IMAGE_GEN_API_KEY"]
)
response = dalle3client.images.generate(
model=os.environ["AZURE_IMAGE_GEN_MODEL"],
prompt="A simple nail polish bottle on a white background",
n=1,
style="vivid",
quality="standard",
)
img_dir = os.path.join(os.curdir, "generated_images")
if not os.path.exists(img_dir):
os.makedirs(img_dir)
generated_img_url = response.data[0].url
generated_image = requests.get(generated_img_url).content
image_path = os.path.join(img_dir, "generated_image.png")
with open(image_path, "wb") as img_file:
img_file.write(generated_image)
Image.open(image_path).show()