File tree Expand file tree Collapse file tree 3 files changed +10
-9
lines changed
Expand file tree Collapse file tree 3 files changed +10
-9
lines changed Original file line number Diff line number Diff line change 22from base64 import b64decode
33from pathlib import Path
44
5- JSON_FILE = Path ("An ec-1668602437.json" )
6- IMAGE_DIR = Path .cwd () / "images" / JSON_FILE .stem
75DATA_DIR = Path .cwd () / "responses"
6+ JSON_FILE = DATA_DIR / "An ec-1667994848.json"
7+ IMAGE_DIR = Path .cwd () / "images" / JSON_FILE .stem
88
99IMAGE_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
1414for 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 )
Original file line number Diff line number Diff line change 1414openai .api_key = os .getenv ("OPENAI_API_KEY" )
1515
1616response = 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" ,
Original file line number Diff line number Diff line change 55
66import openai
77
8- SOURCE_FILE = "A com-1667994848.json"
98DATA_DIR = Path .cwd () / "responses"
9+ SOURCE_FILE = DATA_DIR / "An ec-1667994848.json"
1010
1111openai .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
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
2626with open (DATA_DIR / new_file_name , mode = "w" , encoding = "utf-8" ) as file :
2727 json .dump (response , file )
You can’t perform that action at this time.
0 commit comments