#!/usr/bin/env python3
"""Hero piloto 05 D VERTICAL v2 (1024x1536) — rosto COMPLETO visivel.

Correcao: o v1 cortou a cabeca do fotografo. Prompt reforcado explicitando
camera distance e headroom pra garantir top of head visivel.
"""
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 VERTICAL editorial photograph (9:16 portrait) of a relaxed professional photographer in his 30s or 40s, "
    "wearing a casual dark t-shirt, standing calmly behind a wooden desk inside his home photography studio, "
    "FULL HEAD AND TORSO VISIBLE IN FRAME — the camera is positioned FAR ENOUGH BACK to show the ENTIRE FACE from the TOP OF THE HEAD (with generous headroom above the hair) down to the mid-chest and the laptop on the desk below, "
    "subject centered in the frame with the TOP OF THE HEAD clearly inside the frame, NOT cropped, NOT touching the top edge, "
    "classic medium shot composition with HEADROOM above the subject, "
    "holding a warm ceramic coffee mug in his left hand near chest level, warm genuine subtle smile on his face, "
    "his face is clearly visible including forehead, eyes, nose, mouth and chin — all facial features in frame, "
    "his body posture is clearly RELAXED and SATISFIED, NOT tired, NOT stressed, "
    "below him on the wooden desk sits an open modern laptop prominently displaying a clear visible grid of real portrait photos arranged in a gallery layout, "
    "the photos on screen show different 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 and real event backgrounds, "
    "the photos look like typical professional event photography thumbnails being auto-organized in a photo management app, "
    "GOLDEN HOUR WARM SUNLIGHT streams in from a large window behind the photographer on the left side, casting warm orange and amber tones across the scene, soft rim light on the photographer's hair and shoulders, late afternoon golden light flooding the room, "
    "the atmosphere strongly suggests end-of-afternoon calm, warm productive quietness, as if the day is ending early and the work is already done, "
    "visible background: tasteful home photography studio with wooden shelves, a camera on a tripod blurred in the far background, framed photo prints softly out of focus on the wall, warm wood tones everywhere, "
    "the mood is RELIEF and CALM MASTERY — a man enjoying his evening coffee while his software does the heavy work for him, "
    "very subtle lime-green glow (hex #87C925) coming only from a thin accent line on the laptop screen edge, extremely discreet, barely noticeable, "
    "the dominant palette is warm golden amber from the sunset light and natural human skin tones, "
    "shot on 50mm lens at f/2.8, shallow depth of field with sharp focus on the photographer's face and the laptop screen, "
    "VERTICAL MEDIUM SHOT framing: approximately 15% headroom above the top of the head, then full face visible, then torso down to the chest, then laptop and desk visible in the lower third of the frame, "
    "editorial lifestyle technology photography, hyper detailed, 8k, photorealistic, "
    "NO clocks, NO digital numbers, NO watches, NO timestamps, NO text overlays, no readable logos on the screen, no watermarks, no visible laptop brand, "
    "vertical 9:16 composition, cinematic depth, full scene fills the frame edge-to-edge, "
    "IMPORTANT: do NOT crop the top of the head, the top of the hair must be clearly inside the frame with empty space above it"
)

print("Gerando hero D VERTICAL v2 (rosto completo) via gpt-image-1 (30-60s)...")
r = client.images.generate(
    model="gpt-image-1",
    prompt=prompt,
    size="1024x1536",
    quality="high",
    n=1,
)
b64 = r.data[0].b64_json
dest = OUT / "hero_tempo_D_vertical_v2.png"
dest.write_bytes(base64.b64decode(b64))
print(f"OK -> {dest}")
