Skip to content

Instantly share code, notes, and snippets.

@under0tech
Created February 1, 2023 18:49
Show Gist options
  • Save under0tech/866582b6d134b960c8678b004a4bf981 to your computer and use it in GitHub Desktop.
Save under0tech/866582b6d134b960c8678b004a4bf981 to your computer and use it in GitHub Desktop.
# Don't forget to install the library from OpenAI
# !pip install openai
import os
import openai
import requests
import shutil
# SETTINGS
DALLE_API_KEY = '[DALL-E 2 API_KEY]'
IMAGE_COUNT = 1 # Generate just one image per request
IMAGE_SIZE = '256x256' # Size for the image 256x256 px
openai.api_key = DALLE_API_KEY
# GENERATE IMAGE
def generate_image(prompt):
response = openai.Image.create(prompt=prompt, n=1, size=IMAGE_SIZE)
return response['data'][0]['url']
# DOWNLOAD IMAGE
def download_png(url, file_name):
res = requests.get(url, stream = True)
with open(file_name,'wb') as f:
shutil.copyfileobj(res.raw, f)
# ARRAY OF IMAGES FOR GENERATION
images = [
['nft anime girl in headphones and field', '1.png'],
['nft anime girl in headphones and blue sunny sky', '2.png'],
['nft anime girl in headphones and flowers with blue eyes', '3.png']
]
for img in images:
download_png(generate_image(img[0]), img[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment