🎨 Data Designer Tutorial: Image-to-Image Editing¶
📚 What you'll learn¶
This notebook shows how to chain image generation columns: first generate animal portraits from text, then edit those generated images by adding accessories and changing styles—all without loading external datasets.
- 🖼️ Text-to-image generation: Generate images from text prompts
- 🔗 Chaining image columns: Use
ImageContextto pass generated images to a follow-up editing column - 🎲 Sampler-driven diversity: Combine sampled accessories and settings for varied edits
This tutorial uses an autoregressive model (one that supports both text-to-image and image-to-image generation via the chat completions API). Diffusion models (DALL·E, Stable Diffusion, etc.) do not support image context—see Tutorial 5 for text-to-image generation with diffusion models.
Prerequisites: This tutorial uses OpenRouter with the Flux 2 Pro model. Set
OPENROUTER_API_KEYin your environment before running.
If this is your first time using Data Designer, we recommend starting with the first notebook in this tutorial series.
📦 Import Data Designer¶
data_designer.configprovides the configuration API.DataDesigneris the main interface for generation.
import base64
from pathlib import Path
from IPython.display import Image as IPImage
from IPython.display import display
import data_designer.config as dd
from data_designer.interface import DataDesigner
⚙️ Initialize the Data Designer interface¶
We initialize Data Designer without arguments here—the image model is configured explicitly in the next cell.
data_designer = DataDesigner()
🎛️ Define an image model¶
We need an autoregressive model that supports both text-to-image and image-to-image generation via the chat completions API. This lets us generate images from text and then pass those images as context for editing.
- Use
ImageInferenceParamsso Data Designer treats this model as an image generator. - Image-specific options are model-dependent; pass them via
extra_body.
Note: This tutorial uses the Flux 2 Pro model via OpenRouter. Set
OPENROUTER_API_KEYin your environment.
MODEL_PROVIDER = "openrouter"
MODEL_ID = "black-forest-labs/flux.2-pro"
MODEL_ALIAS = "image-model"
model_configs = [
dd.ModelConfig(
alias=MODEL_ALIAS,
model=MODEL_ID,
provider=MODEL_PROVIDER,
inference_parameters=dd.ImageInferenceParams(
extra_body={"height": 512, "width": 512},
),
)
]
🏗️ Build the configuration¶
We chain two image generation columns:
- Sampler columns — randomly sample animal types, accessories, settings, and art styles
- First image column — generate an animal portrait from a text prompt
- Second image column with context — edit the generated portrait using
ImageContext
config_builder = dd.DataDesignerConfigBuilder(model_configs=model_configs)
# 1. Sampler columns for diversity
config_builder.add_column(
dd.SamplerColumnConfig(
name="animal",
sampler_type=dd.SamplerType.CATEGORY,
params=dd.CategorySamplerParams(
values=["cat", "dog", "fox", "owl", "rabbit", "panda"],
),
)
)
config_builder.add_column(
dd.SamplerColumnConfig(
name="accessory",
sampler_type=dd.SamplerType.CATEGORY,
params=dd.CategorySamplerParams(
values=[
"a tiny top hat",
"oversized sunglasses",
"a red bow tie",
"a knitted beanie",
"a flower crown",
"a monocle and mustache",
"a pirate hat and eye patch",
"a chef hat",
],
),
)
)
config_builder.add_column(
dd.SamplerColumnConfig(
name="setting",
sampler_type=dd.SamplerType.CATEGORY,
params=dd.CategorySamplerParams(
values=[
"a cozy living room",
"a sunny park",
"a photo studio with soft lighting",
"a red carpet event",
"a holiday card backdrop with snowflakes",
"a tropical beach at sunset",
],
),
)
)
config_builder.add_column(
dd.SamplerColumnConfig(
name="art_style",
sampler_type=dd.SamplerType.CATEGORY,
params=dd.CategorySamplerParams(
values=[
"a photorealistic style",
"a Disney Pixar 3D render",
"a watercolor painting",
"a pop art poster",
],
),
)
)
# 2. Generate animal portrait from text
config_builder.add_column(
dd.ImageColumnConfig(
name="animal_portrait",
prompt="A close-up portrait photograph of a {{ animal }} looking at the camera, studio lighting, high quality.",
model_alias=MODEL_ALIAS,
)
)
# 3. Edit the generated portrait
config_builder.add_column(
dd.ImageColumnConfig(
name="edited_portrait",
prompt=(
"Edit this {{ animal }} portrait photo. "
"Add {{ accessory }} on the animal. "
"Place the {{ animal }} in {{ setting }}. "
"Render the result in {{ art_style }}. "
"Keep the animal's face, expression, and features faithful to the original photo."
),
model_alias=MODEL_ALIAS,
multi_modal_context=[dd.ImageContext(column_name="animal_portrait")],
)
)
data_designer.validate(config_builder)
[21:21:26] [INFO] ✅ Validation passed
🔁 Preview: quick iteration¶
In preview mode, generated images are stored as base64 strings in the dataframe. Use this to iterate on your prompts, accessories, and sampler values before scaling up.
preview = data_designer.preview(config_builder, num_records=2)
[21:21:26] [INFO] 🧐 Preview generation in progress
[21:21:26] [INFO] |-- 🔒 Jinja rendering engine: secure
[21:21:26] [INFO] ✅ Validation passed
[21:21:26] [INFO] ⛓️ Sorting column configs into a Directed Acyclic Graph
[21:21:26] [INFO] 🩺 Running health checks for models...
[21:21:26] [INFO] |-- 👀 Checking 'black-forest-labs/flux.2-pro' in provider named 'openrouter' for model alias 'image-model'...
[21:21:35] [INFO] |-- ✅ Passed!
[21:21:35] [INFO] ⚡ DATA_DESIGNER_ASYNC_ENGINE is enabled - using async task-queue preview
[21:21:35] [INFO] 🖼️ image model config for column 'animal_portrait'
[21:21:35] [INFO] |-- model: 'black-forest-labs/flux.2-pro'
[21:21:35] [INFO] |-- model alias: 'image-model'
[21:21:35] [INFO] |-- model provider: 'openrouter'
[21:21:35] [INFO] |-- inference parameters:
[21:21:35] [INFO] | |-- generation_type=image
[21:21:35] [INFO] | |-- max_parallel_requests=4
[21:21:35] [INFO] | |-- extra_body={'height': 512, 'width': 512}
[21:21:35] [INFO] 🖼️ image model config for column 'edited_portrait'
[21:21:35] [INFO] |-- model: 'black-forest-labs/flux.2-pro'
[21:21:35] [INFO] |-- model alias: 'image-model'
[21:21:35] [INFO] |-- model provider: 'openrouter'
[21:21:35] [INFO] |-- inference parameters:
[21:21:35] [INFO] | |-- generation_type=image
[21:21:35] [INFO] | |-- max_parallel_requests=4
[21:21:35] [INFO] | |-- extra_body={'height': 512, 'width': 512}
[21:21:35] [INFO] ⚡️ Async generation: 2 column(s) (animal_portrait, edited_portrait), 4 tasks across 1 row group(s)
[21:21:35] [INFO] 🚀 (1/1) Dispatching with 2 records
[21:21:35] [INFO] 🎲 (1/1) Preparing samplers to generate 2 records across 4 columns
[21:21:55] [INFO] 📊 Progress [19.4s]:
[21:21:55] [INFO] |-- 🌗 animal_portrait: 1/2 (50%) 0.1 rec/s
[21:21:55] [INFO] |-- 🥚 edited_portrait: 0/2 (0%) 0.0 rec/s
[21:22:22] [INFO] 📊 Progress [46.5s]:
[21:22:22] [INFO] |-- 🌗 animal_portrait: 1/2 (50%) 0.0 rec/s
[21:22:22] [INFO] |-- 🐥 edited_portrait: 1/2 (50%) 0.0 rec/s
[21:24:44] [INFO] 📊 Progress [188.1s]:
[21:24:44] [INFO] |-- 🌕 animal_portrait: 2/2 (100%) 0.0 rec/s
[21:24:44] [INFO] |-- 🐥 edited_portrait: 1/2 (50%) 0.0 rec/s
[21:24:57] [INFO] 📊 Progress [201.9s]:
[21:24:57] [INFO] |-- 🌕 animal_portrait: 2/2 (100%) 0.0 rec/s
[21:24:57] [INFO] |-- 🐔 edited_portrait: 2/2 (100%) 0.0 rec/s
[21:24:57] [INFO] ✅ Async generation complete [201.9s]: 4 ok, 0 failed across 2 column(s)
[21:24:57] [INFO] 📊 Model usage summary:
[21:24:57] [INFO] |-- model: black-forest-labs/flux.2-pro
[21:24:57] [INFO] |-- tokens: input=9198, output=12288, total=21486, tps=106
[21:24:57] [INFO] |-- requests: success=4, failed=0, total=4, rpm=1
[21:24:57] [INFO] |-- images: total=4
[21:24:57] [INFO] 📐 Measuring dataset column statistics:
[21:24:57] [INFO] |-- 🎲 column: 'animal'
[21:24:57] [INFO] |-- 🎲 column: 'accessory'
[21:24:57] [INFO] |-- 🎲 column: 'setting'
[21:24:57] [INFO] |-- 🎲 column: 'art_style'
[21:24:57] [INFO] |-- 🖼️ column: 'animal_portrait'
[21:24:57] [INFO] |-- 🖼️ column: 'edited_portrait'
[21:24:57] [INFO] 🏆 Preview complete!
for i in range(len(preview.dataset)):
preview.display_sample_record()
Generated Columns ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Name ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ animal │ fox │ ├──────────────────────────────────┼─────────────────────────────────────────────────────────────────────────┤ │ accessory │ a chef hat │ ├──────────────────────────────────┼─────────────────────────────────────────────────────────────────────────┤ │ setting │ a sunny park │ ├──────────────────────────────────┼─────────────────────────────────────────────────────────────────────────┤ │ art_style │ a photorealistic style │ └──────────────────────────────────┴─────────────────────────────────────────────────────────────────────────┘ Images ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Name ┃ Preview ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ animal_portrait │ [0] <base64, 1907000 chars> │ ├────────────────────────────────────────┼───────────────────────────────────────────────────────────────────┤ │ edited_portrait │ [0] <base64, 1757024 chars> │ └────────────────────────────────────────┴───────────────────────────────────────────────────────────────────┘
Generated Columns ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Name ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ animal │ owl │ ├──────────────────────────────────┼─────────────────────────────────────────────────────────────────────────┤ │ accessory │ a knitted beanie │ ├──────────────────────────────────┼─────────────────────────────────────────────────────────────────────────┤ │ setting │ a sunny park │ ├──────────────────────────────────┼─────────────────────────────────────────────────────────────────────────┤ │ art_style │ a photorealistic style │ └──────────────────────────────────┴─────────────────────────────────────────────────────────────────────────┘ Images ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Name ┃ Preview ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ animal_portrait │ [0] <base64, 1880376 chars> │ ├────────────────────────────────────────┼───────────────────────────────────────────────────────────────────┤ │ edited_portrait │ [0] <base64, 2095592 chars> │ └────────────────────────────────────────┴───────────────────────────────────────────────────────────────────┘