import os
from google import genai

# Set up API key
os.environ['GEMINI_API_KEY'] = 'AIzaSyC2dTGU667C7l8mzaCjI5S18txWtf0aHPc'

def save_image_from_response(response, filename):
    """Extract and save image from Gemini response"""
    for part in response.candidates[0].content.parts:
        if hasattr(part, 'inline_data') and part.inline_data:
            # Save the image data
            image_data = part.inline_data.data
            with open(f"/root/.openclaw/workspace/phat-deck-images/{filename}", "wb") as f:
                f.write(image_data)
            print(f"✓ Saved {filename}")
            return True
    return False

def generate_images():
    client = genai.Client()
    
    # Image 1: Close-up of kid's face with disappointing cake blurred in foreground
    prompt1 = """Generate a high-quality editorial photograph in 16:9 landscape format. 
    Close-up portrait of a 5-year-old child's face showing subtle disappointment and confusion (NOT crying or dramatic). 
    In the blurred foreground, a birthday cake that's clearly "not quite right" - slightly deflated, waxy-looking frosting, off-color. 
    Editorial photography style like Oatly campaigns meets high-end food photography. 
    Warm natural lighting, shallow depth of field, professional commercial quality.
    The child's expression should be more puzzled/unimpressed than sad."""
    
    print("Generating Image 1: Close-up of kid's face...")
    response1 = client.models.generate_content(
        model="gemini-2.0-flash-exp",
        contents=prompt1,
        config=genai.types.GenerateContentConfig(response_modalities=["TEXT", "IMAGE"])
    )
    save_image_from_response(response1, "problem_slide_v1.png")
    
    # Image 2: Wide shot — kid at birthday table, cake focal point, kid looking sideways
    prompt2 = """Generate a high-quality editorial photograph in 16:9 landscape format.
    Wide shot of a 5-year-old child sitting at a birthday party table, looking sideways at a disappointing birthday cake with subtle confusion/disappointment (NOT dramatic or crying). 
    The cake is the focal point - clearly an attempt at a birthday cake but something is off: slightly deflated, wrong texture, waxy frosting, maybe off-color.
    Editorial photography style like Oatly campaigns meets high-end food photography.
    Warm natural lighting, shallow depth of field, professional commercial quality.
    Birthday party setting but the mood is "something's not quite right"."""
    
    print("Generating Image 2: Wide shot at birthday table...")
    response2 = client.models.generate_content(
        model="gemini-2.0-flash-exp",
        contents=prompt2,
        config=genai.types.GenerateContentConfig(response_modalities=["TEXT", "IMAGE"])
    )
    save_image_from_response(response2, "problem_slide_v2.png")
    
    # Image 3: Detail shot — kid's hand poking at cake, wrong texture/waxy
    prompt3 = """Generate a high-quality editorial photograph in 16:9 landscape format.
    Detail shot of a 5-year-old child's small hand poking/touching a birthday cake that has clearly wrong texture - waxy, artificial-looking frosting, maybe slightly deflated or off-color.
    Focus on the tactile wrongness of the cake texture under the child's finger.
    Editorial photography style like Oatly campaigns meets high-end food photography.
    Warm natural lighting, shallow depth of field, professional commercial quality.
    The cake should look like it tried to be a birthday cake but failed - capturing the "almost but not quite right" feeling."""
    
    print("Generating Image 3: Detail shot of hand poking cake...")
    response3 = client.models.generate_content(
        model="gemini-2.0-flash-exp",
        contents=prompt3,
        config=genai.types.GenerateContentConfig(response_modalities=["TEXT", "IMAGE"])
    )
    save_image_from_response(response3, "problem_slide_v3.png")
    
    print("All images generated successfully!")

if __name__ == "__main__":
    generate_images()