Skip to content

Instantly share code, notes, and snippets.

@alexandreaquiles
Created May 7, 2025 00:28
Show Gist options
  • Save alexandreaquiles/119b54eb57505e7aa41d8df564703986 to your computer and use it in GitHub Desktop.
Save alexandreaquiles/119b54eb57505e7aa41d8df564703986 to your computer and use it in GitHub Desktop.

Revisions

  1. alexandreaquiles created this gist May 7, 2025.
    27 changes: 27 additions & 0 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    import base64
    import time
    import os

    from dotenv import load_dotenv
    from openai import OpenAI

    load_dotenv()

    client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

    prompt = """
    Generate a Dragon Ball Z style version of the photo attached.
    """

    result = client.images.edit(
    model="gpt-image-1",
    image=open("eu-gleice-cachoeira.jpg", "rb"),
    prompt=prompt
    )

    image_base64 = result.data[0].b64_json
    image_bytes = base64.b64decode(image_base64)

    # Save the image to a file
    with open(f"dragonball-{time.time_ns()}.png", "wb") as f:
    f.write(image_bytes)