Creative production is the bottleneck in Meta ads performance. Testing requires multiple variations, but traditional production means photographers, models, and weeks of turnaround.

This playbook extends the Meta Ads automation system with AI image composition, transforming basic product photos into complete campaign creatives in minutes.

Meta Ads AI Flow With Human-in-the-Loop
This playbook shows how to use LangGraph workflows to generate campaign configs from simple inputs. We’ll build a system that transforms product descriptions into complete campaign strategies with audience segments and ad variations, while preserving human approval before execution.

The pipeline generates creative variations and deploys targeted campaigns:

Product Selection → AI Composition → Campaign Generation → Human Review → Meta Deployment

The system takes product indices from a fashion dataset (or your own images), generates professional marketing creatives using Gemini's image generation, creates targeted campaign structures, and deploys to Meta after human approval.

This extends the original LangGraph workflow with minimal modifications:

# Original workflow
workflow.set_entry_point("generate")
workflow.add_edge("generate", "review")

# Enhanced workflow - adds one node
workflow.add_node("compose", compose_images)
workflow.set_entry_point("compose")
workflow.add_edge("compose", "generate")

When use_composition: false, the compose node passes through immediately, preserving original behavior.

API Credentials

GOOGLE_AI_API_KEY      # Powers image and campaign generation
META_ADS_TOKEN         # Your Meta access token
META_ADS_ACCOUNT_ID    # Format: act_123456789
META_PAGE_ID           # Your Facebook page ID

Configuration File

Upload the following campaign_input.yaml file

product_description: "Summer fashion collection"
budget: 50
target_countries: ["US"]
landing_url: "https://yourstore.com"
use_composition: true           # Enable AI generation
product_indices: [0, 5, 10]     # Select from dataset

Image Composition with Fashion Dataset

The system uses Hugging Face's fashion dataset with 44,000+ products

ashraq/fashion-product-images-small · Datasets at Hugging Face
We’re on a journey to advance and democratize artificial intelligence through open source and open science.

Here's how the composition works:

# Load fashion dataset
data = load_dataset("ashraq/fashion-product-images-small", split="train")
images = data["image"]
df = data.to_pandas()

# Create composition function
def create_composition(client, images_list, indices, prompt, output_name):
    selected_images = [images_list[i] for i in indices]
    
    response = client.models.generate_content(
        model="gemini-2.5-flash-image-preview",
        contents=selected_images + [prompt],
    )
    
    # Extract and save generated image
    image_parts = [
        part.inline_data.data
        for part in response.candidates[0].content.parts
        if part.inline_data
    ]
    
    if image_parts:
        image = Image.open(BytesIO(image_parts[0]))
        image.save(output_name)
        return output_name

Example Compositions

Starting with four basic product images from the dataset:

  • Index 0: Navy Blue Shirt
  • Index 5: Grey T-shirt
  • Index 10: Casual Shoes
  • Index 12: Sandals

The system generates multiple creative styles:

Hero Shot: "Professional e-commerce product shot on white background"

  • Clean, minimalist product presentation
  • Ideal for primary campaign visuals

Lifestyle: "Model wearing these items in casual urban setting"

  • Contextual product usage
  • Higher engagement for social placements

Flat Lay: "Aesthetic arrangement for Instagram"

  • Styled product composition
  • Optimized for Instagram feed/stories

Each composition takes ~5 seconds and costs ~$0.01 in API usage.

Complete Pipeline Integration

This post is for paying subscribers only

Sign up now and upgrade your account to read the post and get access to the full library of posts for paying subscribers only.

Sign up now Already have an account? Sign in