├── main.py └── requirements.txt /main.py: -------------------------------------------------------------------------------- 1 | # pip isntall openai 2 | import openai 3 | import os 4 | import json 5 | from base64 import b64decode 6 | 7 | prompt = input('The prompt: ') 8 | openai.api_key = os.getenv('API_KEY') 9 | 10 | response = openai.Image.create( 11 | prompt=prompt, 12 | n=1, 13 | size='256x256', 14 | response_format='b64_json' 15 | ) 16 | 17 | with open('data.json', 'w') as file: 18 | json.dump(response, file, indent=4, ensure_ascii=False) 19 | 20 | image_data = b64decode(response['data'][0]['b64_json']) 21 | file_name = '_'.join(prompt.split(' ')) 22 | 23 | with open(f'{file_name}.png', 'wb') as file: 24 | file.write(image_data) 25 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | openai==0.27.7 2 | --------------------------------------------------------------------------------