#!/usr/bin/env python3
"""Gera imagem hero para o piloto 02: formatura com família + overlay face-detection (gpt-image-2 via gpt-image-1).

OBS: no SDK atual o modelo é 'gpt-image-1' (gpt-image-2 é alias comum interno PX3).
"""
import os
import base64
from pathlib import Path
from openai import OpenAI

# carrega env
env_path = Path("/opt/mia/.env")
if env_path.exists():
    for line in env_path.read_text().splitlines():
        if line.strip() and not line.startswith("#") and "=" in line:
            k, v = line.split("=", 1)
            os.environ.setdefault(k.strip(), v.strip())

OUT = Path("/opt/mia/workspace/clientes/px3lab/lancamento_photorf2/criativos_oferta/hero_familia_formatura.png")

client = OpenAI()

PROMPT = """Cinematic photo of a Brazilian graduation ceremony (formatura) celebration moment.
Center: a young graduate wearing graduation cap and gown, smiling with pure joy.
Around the graduate: their family — proud parents (40s-50s, warm expressions),
grandparents (70s, emotional), and a younger sibling. All embracing in a group hug.
Setting: elegant ballroom/salon with warm bokeh lights in the background (amber and gold),
soft tungsten lighting hitting the faces. Shallow depth of field.
Mood: emotional, celebratory, tears of joy, authentic Brazilian family at a graduation party.
Style: shot on 35mm, cinematic color grading, slight film grain, high dynamic range.
No text, no overlays, no graphics — pure photographic image.
Photorealistic, documentary wedding/event photography style.
Composition: medium shot, family fills most of the frame, graduate slightly off-center.
Diverse Brazilian ethnicities. Natural, candid expressions — not posed.
Lighting: warm key light from the right (party lights), subtle fill from the left.
"""

print("Gerando hero via gpt-image-1 (1024x1024)...")
resp = client.images.generate(
    model="gpt-image-1",
    prompt=PROMPT,
    size="1024x1024",
    quality="high",
    n=1,
)

img_b64 = resp.data[0].b64_json
OUT.write_bytes(base64.b64decode(img_b64))
print(f"OK -> {OUT} ({OUT.stat().st_size//1024}KB)")
