Virtual Try-On lets you generate images of people to virtually try-on clothing products. You provide an image of a person and an image of a clothing product, and then Virtual Try-On generates an image of the person wearing that product.
The following models support generating virtual try-on images:
Click to expand supported models
Before you begin
-
In the Cloud de Confiance console, on the project selector page, select or create a Cloud de Confiance project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Cloud de Confiance project.
Enable the Agent Platform API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Set up authentication for your environment.
Select the tab for how you plan to use the samples on this page:
Python
To use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
-
Install the Google Cloud CLI.
-
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
-
Create local authentication credentials for your user account:
gcloud auth application-default login
If an authentication error is returned, confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up ADC for a local development environment in the Cloud de Confiance authentication documentation.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI, and then sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Cloud de Confiance authentication documentation.
-
Generate images
Python
Install
pip install --upgrade google-genai
To learn more, see the SDK reference documentation.
Set environment variables to use the Google Gen AI SDK with Vertex AI:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_ENTERPRISE=True
REST
For more information about the Virtual Try-On API, see the following:
Before using any of the request data, make the following replacements:
- REGION: The region that your project is located in. For more information about supported regions, see Deployments and endpoints.
- PROJECT_ID: Your Cloud de Confiance by S3NS project ID.
- BASE64_PERSON_IMAGE: The Base64-encoded image of the person image.
- BASE64_PRODUCT_IMAGE: The Base64-encoded image of the product image.
-
IMAGE_COUNT: The number of images to generate. The accepted range
of values is
1to4. - GCS_OUTPUT_PATH: The Cloud Storage path to store the virtual try-on output to.
HTTP method and URL:
POST https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/virtual-try-on-001:predict
Request JSON body:
{
"instances": [
{
"personImage": {
"image": {
"bytesBase64Encoded": "BASE64_PERSON_IMAGE"
}
},
"productImages": [
{
"image": {
"bytesBase64Encoded": "BASE64_PRODUCT_IMAGE"
}
}
]
}
],
"parameters": {
"sampleCount": IMAGE_COUNT,
"storageUri": "GCS_OUTPUT_PATH"
}
}
To send your request, choose one of these options:
curl
Save the request body in a file named request.json,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/virtual-try-on-001:predict"
PowerShell
Save the request body in a file named request.json,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/virtual-try-on-001:predict" | Select-Object -Expand Content
{
"predictions": [
{
"mimeType": "image/png",
"bytesBase64Encoded": "BASE64_IMG_BYTES"
},
{
"bytesBase64Encoded": "BASE64_IMG_BYTES",
"mimeType": "image/png"
}
]
}