junit
junit
diff --git a/genai/snippets/src/main/java/genai/imagegeneration/ImageGenCannyCtrlTypeWithTextAndImage.java b/genai/snippets/src/main/java/genai/imagegeneration/ImageGenCannyCtrlTypeWithTextAndImage.java
new file mode 100644
index 00000000000..a47128809f5
--- /dev/null
+++ b/genai/snippets/src/main/java/genai/imagegeneration/ImageGenCannyCtrlTypeWithTextAndImage.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2025 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package genai.imagegeneration;
+
+// [START googlegenaisdk_imggen_canny_ctrl_type_with_txt_img]
+
+import com.google.genai.Client;
+import com.google.genai.types.ControlReferenceConfig;
+import com.google.genai.types.ControlReferenceImage;
+import com.google.genai.types.EditImageConfig;
+import com.google.genai.types.EditImageResponse;
+import com.google.genai.types.GeneratedImage;
+import com.google.genai.types.Image;
+import java.util.List;
+import java.util.Optional;
+
+public class ImageGenCannyCtrlTypeWithTextAndImage {
+
+ public static void main(String[] args) {
+ // TODO(developer): Replace these variables before running the sample.
+ String modelId = "imagen-3.0-capability-001";
+ String outputGcsUri = "gs://your-bucket/your-prefix";
+ cannyEdgeCustomization(modelId, outputGcsUri);
+ }
+
+ /**
+ * Generates an image with a Canny edge image and text prompt.
+ *
+ * This function demonstrates controlled customization. It uses a "Canny edge" image, which is
+ * a black-and-white line drawing that outlines the shapes of objects. The model is instructed to
+ * follow this structural outline to generate an image based the text prompt.
+ *
+ * @param modelId The GenAI model to use for generating the image.
+ * @param outputGcsUri A GCS URI where the generated image will be saved. Example:
+ * "gs://your-bucket/your-prefix"
+ * @return An Optional containing the GCS URI of the generated image if successful.
+ */
+ public static Optional cannyEdgeCustomization(String modelId, String outputGcsUri) {
+ // Client Initialization. Once created, it can be reused for multiple requests.
+ try (Client client = Client.builder().location("global").vertexAI(true).build()) {
+ // Create a reference image out of an existing canny edge image signal
+ // using https://storage.googleapis.com/cloud-samples-data/generative-ai/image/car_canny.png
+ ControlReferenceImage controlReferenceImage =
+ ControlReferenceImage.builder()
+ .referenceId(1)
+ .referenceImage(
+ Image.builder()
+ .gcsUri("gs://cloud-samples-data/generative-ai/image/car_canny.png")
+ .build())
+ .config(ControlReferenceConfig.builder().controlType("CONTROL_TYPE_CANNY").build())
+ .build();
+
+ // The `[1]` in the prompt refers to the `referenceId` assigned to
+ // the control reference image.
+ EditImageResponse imageResponse =
+ client.models.editImage(
+ modelId,
+ "a watercolor painting of a red car[1] driving on a road",
+ List.of(controlReferenceImage),
+ EditImageConfig.builder()
+ .editMode("EDIT_MODE_CONTROLLED_EDITING")
+ .numberOfImages(1)
+ .safetyFilterLevel("BLOCK_MEDIUM_AND_ABOVE")
+ .personGeneration("ALLOW_ADULT")
+ .outputGcsUri(outputGcsUri)
+ .build());
+
+ Image generatedImage =
+ imageResponse
+ .generatedImages()
+ .flatMap(generatedImages -> generatedImages.stream().findFirst())
+ .flatMap(GeneratedImage::image)
+ .orElseThrow(() -> new IllegalStateException("No image was generated by the model."));
+
+ generatedImage.gcsUri().ifPresent(System.out::println);
+ // Example response:
+ // gs://your-bucket/your-prefix
+ return generatedImage.gcsUri();
+ }
+ }
+}
+// [END googlegenaisdk_imggen_canny_ctrl_type_with_txt_img]
diff --git a/genai/snippets/src/main/java/genai/imagegeneration/ImageGenRawReferenceWithTextAndImage.java b/genai/snippets/src/main/java/genai/imagegeneration/ImageGenRawReferenceWithTextAndImage.java
new file mode 100644
index 00000000000..18b5c648f1d
--- /dev/null
+++ b/genai/snippets/src/main/java/genai/imagegeneration/ImageGenRawReferenceWithTextAndImage.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2025 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package genai.imagegeneration;
+
+// [START googlegenaisdk_imggen_raw_reference_with_txt_img]
+
+import com.google.genai.Client;
+import com.google.genai.types.EditImageConfig;
+import com.google.genai.types.EditImageResponse;
+import com.google.genai.types.GeneratedImage;
+import com.google.genai.types.Image;
+import com.google.genai.types.RawReferenceImage;
+import java.util.List;
+import java.util.Optional;
+
+public class ImageGenRawReferenceWithTextAndImage {
+
+ public static void main(String[] args) {
+ // TODO(developer): Replace these variables before running the sample.
+ String modelId = "imagen-3.0-capability-001";
+ String outputGcsUri = "gs://your-bucket/your-prefix";
+ styleTransferCustomization(modelId, outputGcsUri);
+ }
+
+ /**
+ * Generates an image in a new style based on a raw reference image and text prompt.
+ *
+ * This function demonstrates style transfer customization. It uses a raw reference image of a
+ * "teacup". The model is instructed to recreate the reference image in a new style based on the
+ * text prompt.
+ *
+ * @param modelId The GenAI model to use for generating the image.
+ * @param outputGcsUri A GCS URI where the generated image will be saved. Example:
+ * "gs://your-bucket/your-prefix"
+ * @return An Optional containing the GCS URI of the generated image if successful.
+ */
+ public static Optional styleTransferCustomization(String modelId, String outputGcsUri) {
+ // Client Initialization. Once created, it can be reused for multiple requests.
+ try (Client client = Client.builder().location("global").vertexAI(true).build()) {
+ // Create a raw reference image of teacup stored in Google Cloud Storage
+ // using https://storage.googleapis.com/cloud-samples-data/generative-ai/image/teacup-1.png
+ RawReferenceImage rawReferenceImage =
+ RawReferenceImage.builder()
+ .referenceId(1)
+ .referenceImage(
+ Image.builder()
+ .gcsUri("gs://cloud-samples-data/generative-ai/image/teacup-1.png")
+ .build())
+ .build();
+
+ // The `[1]` in the prompt refers to the `referenceId` assigned to the raw reference image.
+ EditImageResponse imageResponse =
+ client.models.editImage(
+ modelId,
+ "transform the subject in the image so that "
+ + "the teacup[1] is made entirely out of chocolate",
+ List.of(rawReferenceImage),
+ EditImageConfig.builder()
+ .editMode("EDIT_MODE_DEFAULT")
+ .numberOfImages(1)
+ .safetyFilterLevel("BLOCK_MEDIUM_AND_ABOVE")
+ .personGeneration("ALLOW_ADULT")
+ .outputGcsUri(outputGcsUri)
+ .build());
+
+ Image generatedImage =
+ imageResponse
+ .generatedImages()
+ .flatMap(generatedImages -> generatedImages.stream().findFirst())
+ .flatMap(GeneratedImage::image)
+ .orElseThrow(() -> new IllegalStateException("No image was generated by the model."));
+
+ generatedImage.gcsUri().ifPresent(System.out::println);
+ // Example response:
+ // gs://your-bucket/your-prefix
+ return generatedImage.gcsUri();
+ }
+ }
+}
+// [END googlegenaisdk_imggen_raw_reference_with_txt_img]
diff --git a/genai/snippets/src/main/java/genai/imagegeneration/ImageGenScribbleCtrlTypeWithTextAndImage.java b/genai/snippets/src/main/java/genai/imagegeneration/ImageGenScribbleCtrlTypeWithTextAndImage.java
new file mode 100644
index 00000000000..09dc64259e2
--- /dev/null
+++ b/genai/snippets/src/main/java/genai/imagegeneration/ImageGenScribbleCtrlTypeWithTextAndImage.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2025 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package genai.imagegeneration;
+
+// [START googlegenaisdk_imggen_scribble_ctrl_type_with_txt_img]
+
+import com.google.genai.Client;
+import com.google.genai.types.ControlReferenceConfig;
+import com.google.genai.types.ControlReferenceImage;
+import com.google.genai.types.EditImageConfig;
+import com.google.genai.types.EditImageResponse;
+import com.google.genai.types.GeneratedImage;
+import com.google.genai.types.Image;
+import java.util.List;
+import java.util.Optional;
+
+public class ImageGenScribbleCtrlTypeWithTextAndImage {
+
+ public static void main(String[] args) {
+ // TODO(developer): Replace these variables before running the sample.
+ String modelId = "imagen-3.0-capability-001";
+ String outputGcsUri = "gs://your-bucket/your-prefix";
+ scribbleCustomization(modelId, outputGcsUri);
+ }
+
+ /**
+ * Generates an image with a Scribble image and text prompt.
+ *
+ * This function demonstrates controlled customization. It uses a "Scribble" image, which is a
+ * rough drawing with a black background and white lines. The model is instructed to follow this
+ * structural outline to generate an image based the text prompt.
+ *
+ * @param modelId The GenAI model to use for generating the image.
+ * @param outputGcsUri A GCS URI where the generated image will be saved. Example:
+ * "gs://your-bucket/your-prefix"
+ * @return An Optional containing the GCS URI of the generated image if successful.
+ */
+ public static Optional scribbleCustomization(String modelId, String outputGcsUri) {
+ // Client Initialization. Once created, it can be reused for multiple requests.
+ try (Client client = Client.builder().location("global").vertexAI(true).build()) {
+ // Create a reference image out of an existing scribble image signal
+ // using
+ // https://storage.googleapis.com/cloud-samples-data/generative-ai/image/car_scribble.png
+ ControlReferenceImage controlReferenceImage =
+ ControlReferenceImage.builder()
+ .referenceId(1)
+ .referenceImage(
+ Image.builder()
+ .gcsUri("gs://cloud-samples-data/generative-ai/image/car_scribble.png")
+ .build())
+ .config(ControlReferenceConfig.builder().controlType("CONTROL_TYPE_SCRIBBLE").build())
+ .build();
+
+ // The `[1]` in the prompt refers to the `referenceId` assigned to the
+ // control reference image.
+ EditImageResponse imageResponse =
+ client.models.editImage(
+ modelId,
+ "an oil painting showing the side of a red car[1]",
+ List.of(controlReferenceImage),
+ EditImageConfig.builder()
+ .editMode("EDIT_MODE_CONTROLLED_EDITING")
+ .numberOfImages(1)
+ .safetyFilterLevel("BLOCK_MEDIUM_AND_ABOVE")
+ .personGeneration("ALLOW_ADULT")
+ .outputGcsUri(outputGcsUri)
+ .build());
+
+ Image generatedImage =
+ imageResponse
+ .generatedImages()
+ .flatMap(generatedImages -> generatedImages.stream().findFirst())
+ .flatMap(GeneratedImage::image)
+ .orElseThrow(() -> new IllegalStateException("No image was generated by the model."));
+
+ generatedImage.gcsUri().ifPresent(System.out::println);
+ // Example response:
+ // gs://your-bucket/your-prefix
+
+ return generatedImage.gcsUri();
+ }
+ }
+}
+// [END googlegenaisdk_imggen_scribble_ctrl_type_with_txt_img]
diff --git a/genai/snippets/src/main/java/genai/imagegeneration/ImageGenStyleReferenceWithTextAndImage.java b/genai/snippets/src/main/java/genai/imagegeneration/ImageGenStyleReferenceWithTextAndImage.java
new file mode 100644
index 00000000000..887b76b99a3
--- /dev/null
+++ b/genai/snippets/src/main/java/genai/imagegeneration/ImageGenStyleReferenceWithTextAndImage.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2025 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package genai.imagegeneration;
+
+// [START googlegenaisdk_imggen_style_reference_with_txt_img]
+
+import com.google.genai.Client;
+import com.google.genai.types.EditImageConfig;
+import com.google.genai.types.EditImageResponse;
+import com.google.genai.types.GeneratedImage;
+import com.google.genai.types.Image;
+import com.google.genai.types.StyleReferenceConfig;
+import com.google.genai.types.StyleReferenceImage;
+import java.util.List;
+import java.util.Optional;
+
+public class ImageGenStyleReferenceWithTextAndImage {
+
+ public static void main(String[] args) {
+ // TODO(developer): Replace these variables before running the sample.
+ String modelId = "imagen-3.0-capability-001";
+ String outputGcsUri = "gs://your-bucket/your-prefix";
+ styleCustomization(modelId, outputGcsUri);
+ }
+
+ /**
+ * Generates an image with a style reference image and text prompt
+ *
+ * This function demonstrates style customization. It uses a style reference image of a "neon
+ * sign". The model is instructed to transfer the style of the reference image to a new image
+ * based on the text prompt.
+ *
+ * @param modelId The GenAI model to use for generating the image.
+ * @param outputGcsUri A GCS URI where the generated image will be saved. Example:
+ * "gs://your-bucket/your-prefix"
+ * @return An Optional containing the GCS URI of the generated image if successful.
+ */
+ public static Optional styleCustomization(String modelId, String outputGcsUri) {
+ // Client Initialization. Once created, it can be reused for multiple requests.
+ try (Client client = Client.builder().location("global").vertexAI(true).build()) {
+ // Create a style reference image of a neon sign stored in Google Cloud Storage
+ // using https://storage.googleapis.com/cloud-samples-data/generative-ai/image/neon.png
+ StyleReferenceImage styleReferenceImage =
+ StyleReferenceImage.builder()
+ .referenceId(1)
+ .referenceImage(
+ Image.builder()
+ .gcsUri("gs://cloud-samples-data/generative-ai/image/neon.png")
+ .build())
+ .config(StyleReferenceConfig.builder().styleDescription("neon sign").build())
+ .build();
+
+ // The `[1]` in the prompt refers to the `referenceId` assigned to the style reference image.
+ EditImageResponse imageResponse =
+ client.models.editImage(
+ modelId,
+ "generate an image of a neon sign [1] with the words: have a great day",
+ List.of(styleReferenceImage),
+ EditImageConfig.builder()
+ .editMode("EDIT_MODE_DEFAULT")
+ .numberOfImages(1)
+ .safetyFilterLevel("BLOCK_MEDIUM_AND_ABOVE")
+ .personGeneration("ALLOW_ADULT")
+ .outputGcsUri(outputGcsUri)
+ .build());
+
+ Image generatedImage =
+ imageResponse
+ .generatedImages()
+ .flatMap(generatedImages -> generatedImages.stream().findFirst())
+ .flatMap(GeneratedImage::image)
+ .orElseThrow(() -> new IllegalStateException("No image was generated by the model."));
+
+ generatedImage.gcsUri().ifPresent(System.out::println);
+ // Example response:
+ // gs://your-bucket/your-prefix
+
+ return generatedImage.gcsUri();
+ }
+ }
+}
+// [END googlegenaisdk_imggen_style_reference_with_txt_img]
diff --git a/genai/snippets/src/main/java/genai/imagegeneration/ImageGenSubjectReferenceWithTextAndImage.java b/genai/snippets/src/main/java/genai/imagegeneration/ImageGenSubjectReferenceWithTextAndImage.java
new file mode 100644
index 00000000000..511cd64fb2a
--- /dev/null
+++ b/genai/snippets/src/main/java/genai/imagegeneration/ImageGenSubjectReferenceWithTextAndImage.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2025 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package genai.imagegeneration;
+
+// [START googlegenaisdk_imggen_subj_refer_ctrl_refer_with_txt_imgs]
+
+import com.google.genai.Client;
+import com.google.genai.types.ControlReferenceConfig;
+import com.google.genai.types.ControlReferenceImage;
+import com.google.genai.types.EditImageConfig;
+import com.google.genai.types.EditImageResponse;
+import com.google.genai.types.GeneratedImage;
+import com.google.genai.types.Image;
+import com.google.genai.types.SubjectReferenceConfig;
+import com.google.genai.types.SubjectReferenceImage;
+import java.util.List;
+import java.util.Optional;
+
+public class ImageGenSubjectReferenceWithTextAndImage {
+
+ public static void main(String[] args) {
+ // TODO(developer): Replace these variables before running the sample.
+ String modelId = "imagen-3.0-capability-001";
+ String outputGcsUri = "gs://your-bucket/your-prefix";
+ subjectCustomization(modelId, outputGcsUri);
+ }
+
+ /**
+ * Demonstrates subject customization.
+ *
+ * This function customizes a subject image using a subject reference image of type person,
+ * control reference image of type face mesh and text prompt. The model generates a new image of a
+ * person by adapting the subject reference image based on the control reference image and the
+ * given prompt.
+ *
+ * @param modelId The GenAI model to use for generating the image.
+ * @param outputGcsUri A GCS URI where the generated image will be saved. Example:
+ * "gs://your-bucket/your-prefix"
+ * @return An Optional containing the GCS URI of the generated image if successful.
+ */
+ public static Optional subjectCustomization(String modelId, String outputGcsUri) {
+ // Client Initialization. Once created, it can be reused for multiple requests.
+ try (Client client = Client.builder().location("global").vertexAI(true).build()) {
+ // Create subject and control reference images of a photograph stored in Google Cloud Storage
+ // using https://storage.googleapis.com/cloud-samples-data/generative-ai/image/person.png
+ SubjectReferenceImage subjectReferenceImage =
+ SubjectReferenceImage.builder()
+ .referenceId(1)
+ .referenceImage(
+ Image.builder()
+ .gcsUri("gs://cloud-samples-data/generative-ai/image/person.png")
+ .build())
+ .config(
+ SubjectReferenceConfig.builder()
+ .subjectDescription("a headshot of a woman")
+ .subjectType("SUBJECT_TYPE_PERSON")
+ .build())
+ .build();
+
+ ControlReferenceImage controlReferenceImage =
+ ControlReferenceImage.builder()
+ .referenceId(2)
+ .referenceImage(
+ Image.builder()
+ .gcsUri("gs://cloud-samples-data/generative-ai/image/person.png")
+ .build())
+ .config(
+ ControlReferenceConfig.builder().controlType("CONTROL_TYPE_FACE_MESH").build())
+ .build();
+
+ // The `[1]` and `[2]` in the prompt refer to the `referenceId` assigned to
+ // the subject reference and control reference images.
+ EditImageResponse imageResponse =
+ client.models.editImage(
+ modelId,
+ "a portrait of a woman[1] in the pose of the control image[2]in a watercolor style by"
+ + " a professional artist, light and low-contrast stokes, bright pastel colors,"
+ + " a warm atmosphere, clean background, grainy paper, bold visible brushstrokes,"
+ + " patchy details",
+ List.of(subjectReferenceImage, controlReferenceImage),
+ EditImageConfig.builder()
+ .editMode("EDIT_MODE_DEFAULT")
+ .numberOfImages(1)
+ .safetyFilterLevel("BLOCK_MEDIUM_AND_ABOVE")
+ .personGeneration("ALLOW_ADULT")
+ .outputGcsUri(outputGcsUri)
+ .build());
+
+ Image generatedImage =
+ imageResponse
+ .generatedImages()
+ .flatMap(generatedImages -> generatedImages.stream().findFirst())
+ .flatMap(GeneratedImage::image)
+ .orElseThrow(() -> new IllegalStateException("No image was generated by the model."));
+
+ generatedImage.gcsUri().ifPresent(System.out::println);
+ // Example response:
+ // gs://your-bucket/your-prefix
+
+ return generatedImage.gcsUri();
+ }
+ }
+}
+// [END googlegenaisdk_imggen_subj_refer_ctrl_refer_with_txt_imgs]
diff --git a/genai/snippets/src/test/java/genai/imagegeneration/ImageGenerationIT.java b/genai/snippets/src/test/java/genai/imagegeneration/ImageGenerationIT.java
index 00ed82837b0..eb6aa392ee7 100644
--- a/genai/snippets/src/test/java/genai/imagegeneration/ImageGenerationIT.java
+++ b/genai/snippets/src/test/java/genai/imagegeneration/ImageGenerationIT.java
@@ -19,11 +19,16 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
+import com.google.api.gax.paging.Page;
+import com.google.cloud.storage.Blob;
+import com.google.cloud.storage.Storage;
+import com.google.cloud.storage.StorageOptions;
import com.google.genai.types.Image;
import java.io.ByteArrayOutputStream;
-import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
+import java.util.Optional;
+import java.util.UUID;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -35,7 +40,11 @@
@RunWith(JUnit4.class)
public class ImageGenerationIT {
- private static final String IMAGGEN_4_MODEL = "imagen-4.0-generate-001";
+ private static final String IMAGEN_3_MODEL = "imagen-3.0-capability-001";
+ private static final String BUCKET_NAME = "java-docs-samples-testing";
+ private static final String PREFIX = "genai-img-generation-" + UUID.randomUUID();
+ private static final String OUTPUT_GCS_URI = String.format("gs://%s/%s", BUCKET_NAME, PREFIX);
+ private static final String IMAGEN_4_MODEL = "imagen-4.0-generate-001";
private static final String VIRTUAL_TRY_ON_MODEL = "virtual-try-on-preview-08-04";
private ByteArrayOutputStream bout;
@@ -53,6 +62,16 @@ public static void checkRequirements() {
requireEnvVar("GOOGLE_CLOUD_PROJECT");
}
+ @AfterClass
+ public static void cleanup() {
+ Storage storage = StorageOptions.getDefaultInstance().getService();
+ Page blobs = storage.list(BUCKET_NAME, Storage.BlobListOption.prefix(PREFIX));
+
+ for (Blob blob : blobs.iterateAll()) {
+ storage.delete(blob.getBlobId());
+ }
+ }
+
@Before
public void setUp() {
bout = new ByteArrayOutputStream();
@@ -65,11 +84,56 @@ public void tearDown() {
System.setOut(null);
}
+ @Test
+ public void testImageGenCannyCtrlTypeWithTextAndImage() {
+ Optional response =
+ ImageGenCannyCtrlTypeWithTextAndImage.cannyEdgeCustomization(
+ IMAGEN_3_MODEL, OUTPUT_GCS_URI);
+ assertThat(response).isPresent();
+ assertThat(response.get()).isNotEmpty();
+ }
+
+ @Test
+ public void testImageGenRawReferenceWithTextAndImage() {
+ Optional response =
+ ImageGenRawReferenceWithTextAndImage.styleTransferCustomization(
+ IMAGEN_3_MODEL, OUTPUT_GCS_URI);
+ assertThat(response).isPresent();
+ assertThat(response.get()).isNotEmpty();
+ }
+
+ @Test
+ public void testImageGenScribbleCtrlTypeWithTextAndImage() {
+ Optional response =
+ ImageGenScribbleCtrlTypeWithTextAndImage.scribbleCustomization(
+ IMAGEN_3_MODEL, OUTPUT_GCS_URI);
+ assertThat(response).isPresent();
+ assertThat(response.get()).isNotEmpty();
+ }
+
+ @Test
+ public void testImageGenStyleReferenceWithTextAndImage() {
+ Optional response =
+ ImageGenStyleReferenceWithTextAndImage.styleCustomization(
+ IMAGEN_3_MODEL, OUTPUT_GCS_URI);
+ assertThat(response).isPresent();
+ assertThat(response.get()).isNotEmpty();
+ }
+
+ @Test
+ public void testImageGenSubjectReferenceWithTextAndImage() {
+ Optional response =
+ ImageGenSubjectReferenceWithTextAndImage.subjectCustomization(
+ IMAGEN_3_MODEL, OUTPUT_GCS_URI);
+ assertThat(response).isPresent();
+ assertThat(response.get()).isNotEmpty();
+ }
+
@Test
public void testImageGenVirtualTryOnWithTextAndImage() throws IOException {
Image image =
- ImageGenVirtualTryOnWithTextAndImage.generateContent(
- VIRTUAL_TRY_ON_MODEL, "resources/output/man_in_sweater.png");
+ ImageGenVirtualTryOnWithTextAndImage.generateContent(
+ VIRTUAL_TRY_ON_MODEL, "resources/output/man_in_sweater.png");
assertThat(image).isNotNull();
assertThat(image.imageBytes()).isPresent();
@@ -79,10 +143,11 @@ public void testImageGenVirtualTryOnWithTextAndImage() throws IOException {
@Test
public void testImageGenWithText() throws IOException {
Image image =
- ImageGenWithText.generateImage(IMAGGEN_4_MODEL, "resources/output/dog_newspaper.png");
+ ImageGenWithText.generateImage(IMAGEN_4_MODEL, "resources/output/dog_newspaper.png");
assertThat(image).isNotNull();
assertThat(image.imageBytes()).isPresent();
assertThat(image.imageBytes().get().length).isGreaterThan(0);
}
+
}
\ No newline at end of file