Created
November 6, 2023 22:57
-
-
Save fofr/284ff45dc849615bff21d8a75ac59ac5 to your computer and use it in GitHub Desktop.
dalle3 style and quality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from openai import OpenAI | |
import os | |
from datetime import datetime | |
import requests | |
client = OpenAI() | |
prompt = "a portrait photo of a woman" | |
qualities = ["standard", "hd"] | |
styles = ["natural", "vivid"] | |
for quality in qualities: | |
for style in styles: | |
response = client.images.generate( | |
model="dall-e-3", | |
prompt=prompt, | |
size="1024x1024", | |
quality=quality, | |
style=style, | |
n=1, | |
) | |
image_url = response.data[0].url | |
# Create outputs directory if it doesn't exist | |
if not os.path.exists('outputs'): | |
os.makedirs('outputs') | |
# Create a timestamp for the filename | |
timestamp = datetime.now().strftime('%Y%m%d%H%M%S') | |
# Create the filename using the timestamp, prompt, quality, and style | |
filename = f"outputs/{timestamp}_{prompt.replace(' ', '_')}_{quality}_{style}.png" | |
# Download the image and save it to the file | |
response = requests.get(image_url) | |
with open(filename, 'wb') as f: | |
f.write(response.content) | |
# Print the path of the saved file | |
print(f"Image saved to {filename}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment