implement word list and image gen

This commit is contained in:
2024-12-13 13:11:48 -06:00
commit 2f8f3415fc
11 changed files with 13012 additions and 0 deletions

47
src/image_gen.py Normal file
View File

@@ -0,0 +1,47 @@
from openai import OpenAI
from pathlib import Path
import uuid
import requests
from enum import Enum
from typing import Literal
class Styles(Enum):
emoji = "emoji"
pixel_art = "pixel art"
svg = "svg"
cartoon = "cartoon"
client = OpenAI()
def image_style(base_prompt: str, style: Styles) -> str:
return f"create {style.name} style of {base_prompt}"
def icon_gen(prompt: str, quality: Literal["hd", "standard"], output: Path = "./output/"):
# Make sure output directory exists
output_path = Path(output) / quality
output_path.mkdir(parents=True, exist_ok=True)
# Generate the image using the OpenAI client
response = client.images.generate(
model="dall-e-3",
prompt=prompt,
size="1024x1024",
quality=quality,
n=1,
)
# Extract the image URL
image_url = response.data[0].url
# Generate a UUID for the filename
image_id = str(uuid.uuid4())
image_filename = f"{image_id}.png"
image_filepath = output_path / image_filename
# Download the image
image_response = requests.get(image_url)
image_response.raise_for_status()
with open(image_filepath, "wb") as f:
f.write(image_response.content)
print(image_id)