#!/usr/bin/env python3
"""Hero piloto 04 v2 — CURIOSIDADE — refação após reprovação da v1.

v1 saiu abstrata (parecia teclado gamer / painel de código).
v2 precisa ser INEQUIVOCAMENTE: notebook aberto mostrando GRID de FOTOS REAIS
de pessoas (formatura, evento) na tela + mão humana apoiada ao lado.

Qualquer pessoa que olhar precisa pensar "ah, são fotos de pessoas num computador".
"""
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")

prompt = (
    "Photorealistic cinematic close-up of an open modern MacBook laptop at a slight three-quarter angle, "
    "the laptop screen prominently displays a clear visible grid of 16 real portrait photos arranged in a 4x4 gallery layout, "
    "the photos show young people wearing graduation gowns and formal attire smiling at a graduation ceremony, "
    "each thumbnail is clearly a recognizable human face photograph with natural warm skin tones, colored clothing, and real event backgrounds, "
    "the photos look like typical professional event photography thumbnails in a photo management app, "
    "the keyboard of the laptop is partially visible in the lower frame with soft key reflections, "
    "the laptop sits on a dark wooden desk, "
    "cinematic soft dramatic side lighting from the upper left, "
    "very subtle lime-green glow (hex #87C925) coming only from a thin accent line on the screen edge, discreet, not dominating, "
    "the overall color palette is natural warm tones of the photos themselves, "
    "a relaxed adult human hand rests completely still on the wooden desk to the right of the laptop, palm down, fingers relaxed, NOT touching the keyboard, NOT clicking, just observing, "
    "the hand has natural skin tone, lit by soft ambient light, visible and clearly identifiable as a human hand, "
    "deep dark background with soft bokeh and subtle texture, not pure black, "
    "atmosphere: calm productive tech, mysterious but inviting, as if the computer is organizing the photos by itself while the person just watches, "
    "shot on 50mm lens, shallow depth of field with sharp focus on the laptop screen showing the photos clearly, "
    "editorial technology photography, hyper detailed, 8k, photorealistic, "
    "no text, no readable logos on the screen, no watermarks, no visible laptop brand, "
    "square 1:1 composition"
)

print("Gerando hero curiosidade v2 via gpt-image-1 (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_curiosidade_v2.png"
dest.write_bytes(base64.b64decode(b64))
print(f"OK -> {dest}")
