-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathedit.py
More file actions
30 lines (24 loc) · 770 Bytes
/
edit.py
File metadata and controls
30 lines (24 loc) · 770 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
import json
import os
from pathlib import Path
import openai
SOURCE_PATH = Path.cwd() / "images" / "An ec-1667994848"
DESTINATION_PATH = Path.cwd() / "responses"
PROMPT = "A 90s vaporwave computer showing Rick Astley on the screen"
SOURCE_PATH.mkdir(parents=True, exist_ok=True)
DESTINATION_PATH.mkdir(parents=True, exist_ok=True)
openai.api_key = os.getenv("OPENAI_API_KEY")
response = openai.Image.create_edit(
image=open(SOURCE_PATH / "computer.png", mode="rb"),
mask=open(SOURCE_PATH / "mask.png", mode="rb"),
prompt=PROMPT,
n=1,
size="256x256",
response_format="b64_json",
)
with open(
DESTINATION_PATH / f"edit-{PROMPT[:5]}-{response['created']}.json",
mode="w",
encoding="utf-8",
) as file:
json.dump(response, file)