Created
April 10, 2025 06:14
-
-
Save karmicdice/806991d86f72203367c47c9f8042cf71 to your computer and use it in GitHub Desktop.
DALL-E Create logo based on domain name
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
import os | |
import openai | |
import requests | |
from dotenv import load_dotenv | |
def generate_logo(domain, name, description): | |
load_dotenv() | |
openai.api_key = os.getenv("OPENAI_API_KEY") | |
if not openai.api_key: | |
raise ValueError("Environment is not suitable") | |
prompt = f"Generate a logo for {domain} - {name} is {description} - horizontal with symbol on the left and wording on the right, minimalistic - rich pastels." | |
try: | |
# Generate the image using DALL-E | |
response = openai.Image.create( | |
prompt=prompt, | |
n=1, | |
size="180x80", | |
response_format="url" | |
) | |
# Get the image URL | |
image_url = response["data"][0]["url"] | |
# Download the image | |
image_response = requests.get(image_url) | |
# Ensure file name is valid | |
filename = f"{domain}.png" | |
# Save the image | |
with open(filename, "wb") as file: | |
file.write(image_response.content) | |
print(f"Logo successfully generated and saved as {filename}") | |
return filename | |
except Exception as e: | |
print(f"Error generating logo: {e}") | |
return None | |
if __name__ == "__main__": | |
import argparse | |
parser = argparse.ArgumentParser(description="Generate a logo using OpenAI DALL-E") | |
parser.add_argument("--domain", required=True, help="Domain name") | |
parser.add_argument("--name", required=True, help="Enter Company/brand name") | |
parser.add_argument("--description", required=True, help="Enter Company/brand description") | |
args = parser.parse_args() | |
generate_logo(args.domain, args.name, args.description) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment