Vertex AIでVirtual Try-Onを試してみる

公式から配布されているColabノートブックを和訳しながら進めてみる。
モデルは専用のものが用意されており「virtual-try-on-preview-08-04」をGoogle Gen AI SDK経由で使う。
Imagenで生成したこちらのモデルに

このドレスを着せる

from google import genai
from google.genai.types import (
GenerateImagesConfig,
Image,
ProductImage,
RecontextImageConfig,
RecontextImageSource,
)
client = genai.Client(vertexai=True, project=PROJECT_ID, location=LOCATION)
virtual_try_on = "virtual-try-on-preview-08-04"
response = client.models.recontext_image(
model=virtual_try_on,
source=RecontextImageSource(
person_image=image.generated_images[0].image,
product_images=[
ProductImage(
product_image=Image(
gcs_uri="gs://cloud-samples-data/generative-ai/image/dress.jpg"
)
)
],
),
config=RecontextImageConfig(
base_steps=32,
number_of_images=1,
safety_filter_level="BLOCK_LOW_AND_ABOVE",
person_generation="ALLOW_ADULT",
),
)
display_image(response.generated_images[0].image)

価格は画像一枚につき$0.12
https://cloud.google.com/vertex-ai/generative-ai/pricing?hl=en#imagen-models
和訳後のノートブックの全文はこちら。