Skip to content

Commit 143b339

Browse files
authored
Final QA edits of OpenAI DALL-E materials (#336)
* Final QA edits of OpenAI DALL-E materials * Split long statement
1 parent 89d3e93 commit 143b339

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

openai-dalle/convert.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
from base64 import b64decode
33
from pathlib import Path
44

5-
JSON_FILE = Path("An ec-1668602437.json")
6-
IMAGE_DIR = Path.cwd() / "images" / JSON_FILE.stem
75
DATA_DIR = Path.cwd() / "responses"
6+
JSON_FILE = DATA_DIR / "An ec-1667994848.json"
7+
IMAGE_DIR = Path.cwd() / "images" / JSON_FILE.stem
88

99
IMAGE_DIR.mkdir(parents=True, exist_ok=True)
1010

11-
with open(DATA_DIR / JSON_FILE, "r") as file:
11+
with open(JSON_FILE, mode="r", encoding="utf-8") as file:
1212
response = json.load(file)
1313

1414
for index, image_dict in enumerate(response["data"]):
1515
image_data = b64decode(image_dict["b64_json"])
16-
with open(IMAGE_DIR / f"{JSON_FILE.stem}-{index}.png", "wb") as png:
16+
image_file = IMAGE_DIR / f"{JSON_FILE.stem}-{index}.png"
17+
with open(image_file, mode="wb") as png:
1718
png.write(image_data)

openai-dalle/edit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
openai.api_key = os.getenv("OPENAI_API_KEY")
1515

1616
response = openai.Image.create_edit(
17-
image=open(SOURCE_PATH / "computer.png", "rb"),
18-
mask=open(SOURCE_PATH / "mask.png", "rb"),
17+
image=open(SOURCE_PATH / "computer.png", mode="rb"),
18+
mask=open(SOURCE_PATH / "mask.png", mode="rb"),
1919
prompt=PROMPT,
2020
n=1,
2121
size="256x256",

openai-dalle/vary.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
import openai
77

8-
SOURCE_FILE = "A com-1667994848.json"
98
DATA_DIR = Path.cwd() / "responses"
9+
SOURCE_FILE = DATA_DIR / "An ec-1667994848.json"
1010

1111
openai.api_key = os.getenv("OPENAI_API_KEY")
1212

13-
with open(DATA_DIR / SOURCE_FILE, "r") as json_file:
13+
with open(SOURCE_FILE, mode="r", encoding="utf-8") as json_file:
1414
saved_response = json.load(json_file)
1515
image_data = b64decode(saved_response["data"][0]["b64_json"])
1616

@@ -21,7 +21,7 @@
2121
response_format="b64_json",
2222
)
2323

24-
new_file_name = f"vary-{SOURCE_FILE[:4]}-{response['created']}.json"
24+
new_file_name = f"vary-{SOURCE_FILE.stem[:5]}-{response['created']}.json"
2525

2626
with open(DATA_DIR / new_file_name, mode="w", encoding="utf-8") as file:
2727
json.dump(response, file)

0 commit comments

Comments
 (0)