#!/usr/bin/env python3
"""Gera imagem hero para o piloto do Cloud PhotoRF 2.0 via gpt-image-1."""
import os
import base64
from pathlib import Path

env_path = Path("/opt/mia/.env")
for line in env_path.read_text().splitlines():
    if line.startswith("OPENAI_API_KEY="):
        os.environ["OPENAI_API_KEY"] = line.split("=", 1)[1].strip()
        break

try:
    from openai import OpenAI
except ImportError:
    os.system("pip install --break-system-packages openai -q")
    from openai import OpenAI

client = OpenAI()
OUT = Path("/opt/mia/workspace/clientes/px3lab/lancamento_photorf2/criativos_oferta")
OUT.mkdir(parents=True, exist_ok=True)

prompt = (
    "Photorealistic cinematic shot of a professional event photographer in black outfit "
    "holding a large DSLR camera, standing slightly off-center on the right side, "
    "shallow depth of field, background is a blurred bokeh wedding reception at night "
    "with warm golden fairy lights and purple stage spotlights, the photographer's face "
    "is lit by the vibrant lime-green glow (hex #87C925) emanating from the camera's back display, "
    "subtle floating holographic UI elements with lime-green rectangular face-detection boxes "
    "overlaying tiny guest faces in the bokeh background, as if the camera is scanning and "
    "recognizing people in real time, dark moody atmosphere, deep black shadows, "
    "editorial tech-forward photography, highly detailed, 4k, no text, no logos, no watermarks, "
    "square 1:1 composition"
)

print("Gerando hero via gpt-image-1 (pode levar 20-40s)...")
r = client.images.generate(
    model="gpt-image-1",
    prompt=prompt,
    size="1024x1024",
    quality="high",
    n=1,
)
b64 = r.data[0].b64_json
dest = OUT / "hero_fotografo_scan.png"
dest.write_bytes(base64.b64decode(b64))
print(f"OK -> {dest}")
