🎨 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)
[16:36:50] [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)
[16:36:50] [INFO] 🔭 Preview generation in progress
[16:36:50] [INFO] ✅ Validation passed
[16:36:51] [INFO] ⛓️ Sorting column configs into a Directed Acyclic Graph
[16:36:51] [INFO] 🩺 Running health checks for models...
[16:36:51] [INFO] |-- 👀 Checking 'black-forest-labs/flux.2-pro' in provider named 'openrouter' for model alias 'image-model'...
[16:36:59] [INFO] |-- ✅ Passed!
[16:36:59] [INFO] 🎲 Preparing samplers to generate 2 records across 4 columns
[16:36:59] [INFO] 🖼️ image model config for column 'animal_portrait'
[16:36:59] [INFO] |-- model: 'black-forest-labs/flux.2-pro'
[16:36:59] [INFO] |-- model alias: 'image-model'
[16:36:59] [INFO] |-- model provider: 'openrouter'
[16:36:59] [INFO] |-- inference parameters:
[16:36:59] [INFO] | |-- generation_type=image
[16:36:59] [INFO] | |-- max_parallel_requests=4
[16:36:59] [INFO] | |-- extra_body={'height': 512, 'width': 512}
[16:36:59] [INFO] ⚡️ Processing image column 'animal_portrait' with 4 concurrent workers
[16:36:59] [INFO] ⏱️ image column 'animal_portrait' will report progress after each record
[16:37:09] [INFO] |-- 😸 image column 'animal_portrait' progress: 1/2 (50%) complete, 1 ok, 0 failed, 0.10 rec/s, eta 9.6s
[16:37:09] [INFO] |-- 🦁 image column 'animal_portrait' progress: 2/2 (100%) complete, 2 ok, 0 failed, 0.20 rec/s, eta 0.0s
[16:37:09] [INFO] 🖼️ image model config for column 'edited_portrait'
[16:37:09] [INFO] |-- model: 'black-forest-labs/flux.2-pro'
[16:37:09] [INFO] |-- model alias: 'image-model'
[16:37:09] [INFO] |-- model provider: 'openrouter'
[16:37:09] [INFO] |-- inference parameters:
[16:37:09] [INFO] | |-- generation_type=image
[16:37:09] [INFO] | |-- max_parallel_requests=4
[16:37:09] [INFO] | |-- extra_body={'height': 512, 'width': 512}
[16:37:09] [INFO] ⚡️ Processing image column 'edited_portrait' with 4 concurrent workers
[16:37:09] [INFO] ⏱️ image column 'edited_portrait' will report progress after each record
[16:37:22] [INFO] |-- 🌗 image column 'edited_portrait' progress: 1/2 (50%) complete, 1 ok, 0 failed, 0.08 rec/s, eta 12.7s
[16:37:25] [INFO] |-- 🌕 image column 'edited_portrait' progress: 2/2 (100%) complete, 2 ok, 0 failed, 0.13 rec/s, eta 0.0s
[16:37:25] [INFO] 📊 Model usage summary:
[16:37:25] [INFO] |-- model: black-forest-labs/flux.2-pro
[16:37:25] [INFO] |-- tokens: input=0, output=0, total=0, tps=0
[16:37:25] [INFO] |-- requests: success=4, failed=0, total=4, rpm=9
[16:37:25] [INFO] |-- images: total=4
[16:37:25] [INFO] 📐 Measuring dataset column statistics:
[16:37:25] [INFO] |-- 🎲 column: 'animal'
[16:37:25] [INFO] |-- 🎲 column: 'accessory'
[16:37:25] [INFO] |-- 🎲 column: 'setting'
[16:37:25] [INFO] |-- 🎲 column: 'art_style'
[16:37:25] [INFO] |-- 🖼️ column: 'animal_portrait'
[16:37:25] [INFO] |-- 🖼️ column: 'edited_portrait'
[16:37:25] [INFO] 🎊 Preview complete!
for i in range(len(preview.dataset)):
preview.display_sample_record()
Generated Columns ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Name ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ animal │ cat │ ├───────────────────────────────┼────────────────────────────────────────────────────────────────────────────┤ │ accessory │ a pirate hat and eye patch │ ├───────────────────────────────┼────────────────────────────────────────────────────────────────────────────┤ │ setting │ a red carpet event │ ├───────────────────────────────┼────────────────────────────────────────────────────────────────────────────┤ │ art_style │ a pop art poster │ └───────────────────────────────┴────────────────────────────────────────────────────────────────────────────┘ Images ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Name ┃ Preview ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ animal_portrait │ [0] <base64, 1616164 chars> │ ├────────────────────────────────────────┼───────────────────────────────────────────────────────────────────┤ │ edited_portrait │ [0] <base64, 1940540 chars> │ └────────────────────────────────────────┴───────────────────────────────────────────────────────────────────┘
Generated Columns ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Name ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ animal │ owl │ ├───────────────────────────────┼────────────────────────────────────────────────────────────────────────────┤ │ accessory │ a red bow tie │ ├───────────────────────────────┼────────────────────────────────────────────────────────────────────────────┤ │ setting │ a tropical beach at sunset │ ├───────────────────────────────┼────────────────────────────────────────────────────────────────────────────┤ │ art_style │ a photorealistic style │ └───────────────────────────────┴────────────────────────────────────────────────────────────────────────────┘ Images ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Name ┃ Preview ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ animal_portrait │ [0] <base64, 1978724 chars> │ ├────────────────────────────────────────┼───────────────────────────────────────────────────────────────────┤ │ edited_portrait │ [0] <base64, 2187172 chars> │ └────────────────────────────────────────┴───────────────────────────────────────────────────────────────────┘
preview.dataset
| animal | accessory | setting | art_style | animal_portrait | edited_portrait | |
|---|---|---|---|---|---|---|
| 0 | cat | a pirate hat and eye patch | a red carpet event | a pop art poster | [iVBORw0KGgoAAAANSUhEUgAABAAAAAMACAIAAAA12IJaA... | [iVBORw0KGgoAAAANSUhEUgAABAAAAAMACAIAAAA12IJaA... |
| 1 | owl | a red bow tie | a tropical beach at sunset | a photorealistic style | [iVBORw0KGgoAAAANSUhEUgAABAAAAAMACAIAAAA12IJaA... | [iVBORw0KGgoAAAANSUhEUgAABAAAAAMACAIAAAA12IJaA... |
🔎 Compare original vs edited¶
Let's display the generated animal portraits next to their edited versions.
def display_image(image_value, base_path: Path | None = None) -> None:
"""Display an image from base64 (preview mode) or file path (create mode)."""
values = [image_value] if isinstance(image_value, str) else list(image_value)
for value in values:
if base_path is not None:
display(IPImage(filename=str(base_path / value)))
else:
display(IPImage(data=base64.b64decode(value)))
def display_before_after(row, index: int, base_path: Path | None = None) -> None:
"""Display original portrait vs edited version for a single record."""
print(f"\n{'=' * 60}")
print(f"Record {index}: {row['animal']} wearing {row['accessory']}")
print(f"Setting: {row['setting']}, Style: {row['art_style']}")
print(f"{'=' * 60}")
print("\n📷 Generated portrait:")
display_image(row["animal_portrait"], base_path)
print("\n🎨 Edited version:")
display_image(row["edited_portrait"], base_path)
for index, row in preview.dataset.iterrows():
display_before_after(row, index)
============================================================ Record 0: cat wearing a pirate hat and eye patch Setting: a red carpet event, Style: a pop art poster ============================================================ 📷 Generated portrait:
🎨 Edited version:
============================================================ Record 1: owl wearing a red bow tie Setting: a tropical beach at sunset, Style: a photorealistic style ============================================================ 📷 Generated portrait:
🎨 Edited version:
🆙 Create at scale¶
In create mode, images are saved to disk in images/<column_name>/ folders with UUID filenames. The dataframe stores relative paths. ImageContext auto-detection handles this transparently—generated file paths are resolved to base64 before being sent to the model for editing.
results = data_designer.create(config_builder, num_records=5, dataset_name="tutorial-6-edited-images")
[16:37:25] [INFO] 🎨 Creating Data Designer dataset
[16:37:25] [INFO] ✅ Validation passed
[16:37:25] [INFO] ⛓️ Sorting column configs into a Directed Acyclic Graph
[16:37:25] [INFO] 🩺 Running health checks for models...
[16:37:25] [INFO] |-- 👀 Checking 'black-forest-labs/flux.2-pro' in provider named 'openrouter' for model alias 'image-model'...
[16:37:38] [INFO] |-- ✅ Passed!
[16:37:38] [INFO] ⏳ Processing batch 1 of 1
[16:37:38] [INFO] 🎲 Preparing samplers to generate 5 records across 4 columns
[16:37:38] [INFO] 🖼️ image model config for column 'animal_portrait'
[16:37:38] [INFO] |-- model: 'black-forest-labs/flux.2-pro'
[16:37:38] [INFO] |-- model alias: 'image-model'
[16:37:38] [INFO] |-- model provider: 'openrouter'
[16:37:38] [INFO] |-- inference parameters:
[16:37:38] [INFO] | |-- generation_type=image
[16:37:38] [INFO] | |-- max_parallel_requests=4
[16:37:38] [INFO] | |-- extra_body={'height': 512, 'width': 512}
[16:37:38] [INFO] ⚡️ Processing image column 'animal_portrait' with 4 concurrent workers
[16:37:38] [INFO] ⏱️ image column 'animal_portrait' will report progress after each record
[16:37:47] [INFO] |-- 😴 image column 'animal_portrait' progress: 1/5 (20%) complete, 1 ok, 0 failed, 0.11 rec/s, eta 36.8s
[16:37:48] [INFO] |-- 🥱 image column 'animal_portrait' progress: 2/5 (40%) complete, 2 ok, 0 failed, 0.21 rec/s, eta 14.5s
[16:37:49] [INFO] |-- 😐 image column 'animal_portrait' progress: 3/5 (60%) complete, 3 ok, 0 failed, 0.27 rec/s, eta 7.5s
[16:37:50] [INFO] |-- 😊 image column 'animal_portrait' progress: 4/5 (80%) complete, 4 ok, 0 failed, 0.33 rec/s, eta 3.1s
[16:37:58] [INFO] |-- 🤩 image column 'animal_portrait' progress: 5/5 (100%) complete, 5 ok, 0 failed, 0.25 rec/s, eta 0.0s
[16:37:58] [INFO] 🖼️ image model config for column 'edited_portrait'
[16:37:58] [INFO] |-- model: 'black-forest-labs/flux.2-pro'
[16:37:58] [INFO] |-- model alias: 'image-model'
[16:37:58] [INFO] |-- model provider: 'openrouter'
[16:37:58] [INFO] |-- inference parameters:
[16:37:58] [INFO] | |-- generation_type=image
[16:37:58] [INFO] | |-- max_parallel_requests=4
[16:37:58] [INFO] | |-- extra_body={'height': 512, 'width': 512}
[16:37:58] [INFO] ⚡️ Processing image column 'edited_portrait' with 4 concurrent workers
[16:37:58] [INFO] ⏱️ image column 'edited_portrait' will report progress after each record
[16:38:11] [INFO] |-- 🥚 image column 'edited_portrait' progress: 1/5 (20%) complete, 1 ok, 0 failed, 0.08 rec/s, eta 52.0s
[16:38:11] [INFO] |-- 🐣 image column 'edited_portrait' progress: 2/5 (40%) complete, 2 ok, 0 failed, 0.15 rec/s, eta 19.8s
[16:38:13] [INFO] |-- 🐥 image column 'edited_portrait' progress: 3/5 (60%) complete, 3 ok, 0 failed, 0.20 rec/s, eta 10.1s
[16:38:15] [INFO] |-- 🐤 image column 'edited_portrait' progress: 4/5 (80%) complete, 4 ok, 0 failed, 0.24 rec/s, eta 4.1s
[16:38:35] [INFO] |-- 🐔 image column 'edited_portrait' progress: 5/5 (100%) complete, 5 ok, 0 failed, 0.14 rec/s, eta 0.0s
[16:38:35] [INFO] 📊 Model usage summary:
[16:38:35] [INFO] |-- model: black-forest-labs/flux.2-pro
[16:38:35] [INFO] |-- tokens: input=0, output=0, total=0, tps=0
[16:38:35] [INFO] |-- requests: success=10, failed=0, total=10, rpm=10
[16:38:35] [INFO] |-- images: total=10
[16:38:35] [INFO] 📐 Measuring dataset column statistics:
[16:38:35] [INFO] |-- 🎲 column: 'animal'
[16:38:35] [INFO] |-- 🎲 column: 'accessory'
[16:38:35] [INFO] |-- 🎲 column: 'setting'
[16:38:35] [INFO] |-- 🎲 column: 'art_style'
[16:38:35] [INFO] |-- 🖼️ column: 'animal_portrait'
[16:38:35] [INFO] |-- 🖼️ column: 'edited_portrait'
dataset = results.load_dataset()
dataset.head()
| animal | accessory | setting | art_style | animal_portrait | edited_portrait | |
|---|---|---|---|---|---|---|
| 0 | cat | a red bow tie | a tropical beach at sunset | a pop art poster | ['images/animal_portrait/e6c16d7b-04b7-4c08-a5... | ['images/edited_portrait/29a4cf03-66ed-460f-b2... |
| 1 | owl | a tiny top hat | a tropical beach at sunset | a Disney Pixar 3D render | ['images/animal_portrait/7ba15ddc-3c11-42d1-92... | ['images/edited_portrait/d89c3cd7-178a-4ccb-a4... |
| 2 | panda | a pirate hat and eye patch | a cozy living room | a pop art poster | ['images/animal_portrait/bc7d44f3-c179-4a3c-8f... | ['images/edited_portrait/c8583aeb-d70c-4f33-94... |
| 3 | dog | a flower crown | a sunny park | a pop art poster | ['images/animal_portrait/405b3959-d762-4a2c-97... | ['images/edited_portrait/c665280a-4e2e-4bce-a5... |
| 4 | owl | a tiny top hat | a sunny park | a pop art poster | ['images/animal_portrait/7928b518-d47a-49b1-8b... | ['images/edited_portrait/60fe111c-3c92-46ef-99... |
for index, row in dataset.head(10).iterrows():
display_before_after(row, index, base_path=results.artifact_storage.base_dataset_path)
============================================================ Record 0: cat wearing a red bow tie Setting: a tropical beach at sunset, Style: a pop art poster ============================================================ 📷 Generated portrait:
🎨 Edited version:
============================================================ Record 1: owl wearing a tiny top hat Setting: a tropical beach at sunset, Style: a Disney Pixar 3D render ============================================================ 📷 Generated portrait:
🎨 Edited version:
============================================================ Record 2: panda wearing a pirate hat and eye patch Setting: a cozy living room, Style: a pop art poster ============================================================ 📷 Generated portrait:
🎨 Edited version:
============================================================ Record 3: dog wearing a flower crown Setting: a sunny park, Style: a pop art poster ============================================================ 📷 Generated portrait:
🎨 Edited version:
============================================================ Record 4: owl wearing a tiny top hat Setting: a sunny park, Style: a pop art poster ============================================================ 📷 Generated portrait:
🎨 Edited version:
⏭️ Next steps¶
- Experiment with different autoregressive models for image generation and editing
- Try more creative editing prompts (style transfer, background replacement, artistic filters)
- Combine image generation with text generation (e.g., generate captions using an LLM-Text column with
ImageContext) - Chain more than two image columns for multi-step editing pipelines
Related tutorials:
- The basics: samplers and LLM text columns
- Providing images as context: image-to-text with VLMs
- Generating images: text-to-image generation with diffusion models