From fe676a94be2fc242cc3c48fc47f16e3afd16fdb9 Mon Sep 17 00:00:00 2001 From: David del Real Sifuentes Date: Mon, 24 Aug 2026 17:23:09 +0000 Subject: [PATCH] chore(generative_ai): remove migrated and unused samples part 2 Deletes legacy image generation and prompt template examples that have been migrated to the `google-genai` SDK or have fallen into disuse. --- .../image_generation/edit_image_mask.py | 81 ------------------- .../image_generation/edit_image_mask_free.py | 75 ----------------- .../edit_image_mask_free_test.py | 40 --------- .../image_generation/edit_image_mask_test.py | 42 ---------- .../edit_image_outpainting_mask.py | 77 ------------------ .../edit_image_outpainting_mask_test.py | 42 ---------- .../edit_image_product_image.py | 71 ---------------- .../edit_image_product_image_test.py | 40 --------- 8 files changed, 468 deletions(-) delete mode 100644 generative_ai/image_generation/edit_image_mask.py delete mode 100644 generative_ai/image_generation/edit_image_mask_free.py delete mode 100644 generative_ai/image_generation/edit_image_mask_free_test.py delete mode 100644 generative_ai/image_generation/edit_image_mask_test.py delete mode 100644 generative_ai/image_generation/edit_image_outpainting_mask.py delete mode 100644 generative_ai/image_generation/edit_image_outpainting_mask_test.py delete mode 100644 generative_ai/image_generation/edit_image_product_image.py delete mode 100644 generative_ai/image_generation/edit_image_product_image_test.py diff --git a/generative_ai/image_generation/edit_image_mask.py b/generative_ai/image_generation/edit_image_mask.py deleted file mode 100644 index 6f5f550e527..00000000000 --- a/generative_ai/image_generation/edit_image_mask.py +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright 2024 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 -# -# https://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. - -"""Google Cloud Vertex AI sample for editing an image using a mask. The - edit is applied to the masked area of the image and is saved to a new file. -""" -import os - -from vertexai.preview import vision_models - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def edit_image_mask( - input_file: str, - mask_file: str, - output_file: str, - prompt: str, -) -> vision_models.ImageGenerationResponse: - # [START generativeaionvertexai_imagen_edit_image_mask] - - import vertexai - from vertexai.preview.vision_models import Image, ImageGenerationModel - - # TODO(developer): Update and un-comment below lines - # PROJECT_ID = "your-project-id" - # input_file = "input-image.png" - # mask_file = "mask-image.png" - # output_file = "output-image.png" - # prompt = "" # The text prompt describing what you want to see. - - vertexai.init(project=PROJECT_ID, location="us-central1") - - model = ImageGenerationModel.from_pretrained("imagegeneration@002") - base_img = Image.load_from_file(location=input_file) - mask_img = Image.load_from_file(location=mask_file) - - images = model.edit_image( - base_image=base_img, - mask=mask_img, - prompt=prompt, - # Optional parameters - seed=1, - # Controls the strength of the prompt. - # -- 0-9 (low strength), 10-20 (medium strength), 21+ (high strength) - guidance_scale=21, - number_of_images=1, - ) - - images[0].save(location=output_file, include_generation_parameters=False) - - # Optional. View the edited image in a notebook. - # images[0].show() - - print(f"Created output image using {len(images[0]._image_bytes)} bytes") - # Example response: - # Created output image using 971614 bytes - - # [END generativeaionvertexai_imagen_edit_image_mask] - - return images - - -if __name__ == "__main__": - edit_image_mask( - input_file="test_resources/dog_newspaper.png", - mask_file="test_resources/dog_newspaper_mask.png", - output_file="test_resources/dog_book.png", - prompt="a big book", - ) diff --git a/generative_ai/image_generation/edit_image_mask_free.py b/generative_ai/image_generation/edit_image_mask_free.py deleted file mode 100644 index 0e4bfc1c658..00000000000 --- a/generative_ai/image_generation/edit_image_mask_free.py +++ /dev/null @@ -1,75 +0,0 @@ -# Copyright 2024 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 -# -# https://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. - -"""Google Cloud Vertex AI sample for editing an image without using a mask. The - edit is applied to the entire image and is saved to a new file. -""" - -import os - -from vertexai.preview import vision_models - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def edit_image_mask_free( - input_file: str, output_file: str, prompt: str -) -> vision_models.ImageGenerationResponse: - # [START generativeaionvertexai_imagen_edit_image_mask_free] - - import vertexai - from vertexai.preview.vision_models import Image, ImageGenerationModel - - # TODO(developer): Update and un-comment below lines - # PROJECT_ID = "your-project-id" - # input_file = "input-image.png" - # output_file = "output-image.png" - # prompt = "" # The text prompt describing what you want to see. - - vertexai.init(project=PROJECT_ID, location="us-central1") - - model = ImageGenerationModel.from_pretrained("imagegeneration@002") - base_img = Image.load_from_file(location=input_file) - - images = model.edit_image( - base_image=base_img, - prompt=prompt, - # Optional parameters - seed=1, - # Controls the strength of the prompt. - # -- 0-9 (low strength), 10-20 (medium strength), 21+ (high strength) - guidance_scale=21, - number_of_images=1, - ) - - images[0].save(location=output_file, include_generation_parameters=False) - - # Optional. View the edited image in a notebook. - # images[0].show() - - print(f"Created output image using {len(images[0]._image_bytes)} bytes") - # Example response: - # Created output image using 1234567 bytes - - # [END generativeaionvertexai_imagen_edit_image_mask_free] - - return images - - -if __name__ == "__main__": - edit_image_mask_free( - input_file="test_resources/cat.png", - output_file="test_resources/dog.png", - prompt="a dog", - ) diff --git a/generative_ai/image_generation/edit_image_mask_free_test.py b/generative_ai/image_generation/edit_image_mask_free_test.py deleted file mode 100644 index 078578f8bd9..00000000000 --- a/generative_ai/image_generation/edit_image_mask_free_test.py +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright 2024 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 -# -# https://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. - -import os - -import backoff - -from google.api_core.exceptions import ResourceExhausted -import pytest - -import edit_image_mask_free - - -_RESOURCES = os.path.join(os.path.dirname(__file__), "test_resources") -_INPUT_FILE = os.path.join(_RESOURCES, "cat.png") -_OUTPUT_FILE = os.path.join(_RESOURCES, "dog.png") -_PROMPT = "a dog" - - -@pytest.mark.skip("imagegeneration@002 samples pending deprecation") -@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=60) -def test_edit_image_mask_free() -> None: - response = edit_image_mask_free.edit_image_mask_free( - _INPUT_FILE, - _OUTPUT_FILE, - _PROMPT, - ) - - assert len(response[0]._image_bytes) > 1000 diff --git a/generative_ai/image_generation/edit_image_mask_test.py b/generative_ai/image_generation/edit_image_mask_test.py deleted file mode 100644 index fa244f6ef73..00000000000 --- a/generative_ai/image_generation/edit_image_mask_test.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2024 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 -# -# https://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. - -import os - -import backoff - -from google.api_core.exceptions import ResourceExhausted -import pytest - -import edit_image_mask - - -_RESOURCES = os.path.join(os.path.dirname(__file__), "test_resources") -_INPUT_FILE = os.path.join(_RESOURCES, "dog_newspaper.png") -_MASK_FILE = os.path.join(_RESOURCES, "dog_newspaper_mask.png") -_OUTPUT_FILE = os.path.join(_RESOURCES, "dog_book.png") -_PROMPT = "a big book" - - -@pytest.mark.skip("imagegeneration@002 samples pending deprecation") -@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=60) -def test_edit_image_mask() -> None: - response = edit_image_mask.edit_image_mask( - _INPUT_FILE, - _MASK_FILE, - _OUTPUT_FILE, - _PROMPT, - ) - - assert len(response[0]._image_bytes) > 1000 diff --git a/generative_ai/image_generation/edit_image_outpainting_mask.py b/generative_ai/image_generation/edit_image_outpainting_mask.py deleted file mode 100644 index c0a35e475b2..00000000000 --- a/generative_ai/image_generation/edit_image_outpainting_mask.py +++ /dev/null @@ -1,77 +0,0 @@ -# Copyright 2024 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 -# -# https://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. - -"""Google Cloud Vertex AI sample for editing an image using a mask file. - Outpainting lets you expand the content of a base image to fit a larger or - differently sized mask canvas. -""" -import os - -from vertexai.preview import vision_models - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def edit_image_outpainting_mask( - input_file: str, - mask_file: str, - output_file: str, - prompt: str, -) -> vision_models.ImageGenerationResponse: - # [START generativeaionvertexai_imagen_edit_image_outpainting_mask] - - import vertexai - from vertexai.preview.vision_models import Image, ImageGenerationModel - - # TODO(developer): Update and un-comment below lines - # PROJECT_ID = "your-project-id" - # input_file = "input-image.png" - # mask_file = "mask-image.png" - # output_file = "output-image.png" - # prompt = "" # The optional text prompt describing what you want to see inserted. - - vertexai.init(project=PROJECT_ID, location="us-central1") - - model = ImageGenerationModel.from_pretrained("imagegeneration@006") - base_img = Image.load_from_file(location=input_file) - mask_img = Image.load_from_file(location=mask_file) - - images = model.edit_image( - base_image=base_img, - mask=mask_img, - prompt=prompt, - edit_mode="outpainting", - ) - - images[0].save(location=output_file, include_generation_parameters=False) - - # Optional. View the edited image in a notebook. - # images[0].show() - - print(f"Created output image using {len(images[0]._image_bytes)} bytes") - # Example response: - # Created output image using 1234567 bytes - - # [END generativeaionvertexai_imagen_edit_image_outpainting_mask] - - return images - - -if __name__ == "__main__": - edit_image_outpainting_mask( - input_file="test_resources/roller_skaters.png", - mask_file="test_resources/roller_skaters_mask.png", - output_file="test_resources/roller_skaters_downtown.png", - prompt="city with skyscrapers", - ) diff --git a/generative_ai/image_generation/edit_image_outpainting_mask_test.py b/generative_ai/image_generation/edit_image_outpainting_mask_test.py deleted file mode 100644 index 1827d871694..00000000000 --- a/generative_ai/image_generation/edit_image_outpainting_mask_test.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2024 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 -# -# https://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. - -import os - -import backoff - -from google.api_core.exceptions import ResourceExhausted -import pytest - -import edit_image_outpainting_mask - - -_RESOURCES = os.path.join(os.path.dirname(__file__), "test_resources") -_INPUT_FILE = os.path.join(_RESOURCES, "roller_skaters.png") -_MASK_FILE = os.path.join(_RESOURCES, "roller_skaters_mask.png") -_OUTPUT_FILE = os.path.join(_RESOURCES, "roller_skaters_downtown.png") -_PROMPT = "city with skyscrapers" - - -@pytest.mark.skip("imagegeneration@006 samples pending deprecation") -@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=60) -def test_edit_image_outpainting_mask() -> None: - response = edit_image_outpainting_mask.edit_image_outpainting_mask( - _INPUT_FILE, - _MASK_FILE, - _OUTPUT_FILE, - _PROMPT, - ) - - assert len(response[0]._image_bytes) > 1000 diff --git a/generative_ai/image_generation/edit_image_product_image.py b/generative_ai/image_generation/edit_image_product_image.py deleted file mode 100644 index 0162f17c4e3..00000000000 --- a/generative_ai/image_generation/edit_image_product_image.py +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright 2024 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 -# -# https://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. - -"""Google Cloud Vertex AI sample for editing a product image. You can - modify the background content but preserve the product's appearance. -""" -import os - -from vertexai.preview import vision_models - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def edit_image_product_image( - input_file: str, - output_file: str, - prompt: str, -) -> vision_models.ImageGenerationResponse: - # [START generativeaionvertexai_imagen_edit_image_product_image] - - import vertexai - from vertexai.preview.vision_models import Image, ImageGenerationModel - - # TODO(developer): Update and un-comment below lines - # PROJECT_ID = "your-project-id" - # input_file = "input-image.png" - # output_file = "output-image.png" - # prompt = "" # The text prompt describing what you want to see in the background. - - vertexai.init(project=PROJECT_ID, location="us-central1") - - model = ImageGenerationModel.from_pretrained("imagegeneration@006") - base_img = Image.load_from_file(location=input_file) - - images = model.edit_image( - base_image=base_img, - prompt=prompt, - edit_mode="product-image", - ) - - images[0].save(location=output_file, include_generation_parameters=False) - - # Optional. View the edited image in a notebook. - # images[0].show() - - print(f"Created output image using {len(images[0]._image_bytes)} bytes") - # Example response: - # Created output image using 1234567 bytes - - # [END generativeaionvertexai_imagen_edit_image_product_image] - - return images - - -if __name__ == "__main__": - edit_image_product_image( - input_file="test_resources/pillow.png", - output_file="test_resources/pillow_on_beach.png", - prompt="beach", - ) diff --git a/generative_ai/image_generation/edit_image_product_image_test.py b/generative_ai/image_generation/edit_image_product_image_test.py deleted file mode 100644 index d0256eafc93..00000000000 --- a/generative_ai/image_generation/edit_image_product_image_test.py +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright 2024 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 -# -# https://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. - -import os - -import backoff - -from google.api_core.exceptions import ResourceExhausted -import pytest - -import edit_image_product_image - - -_RESOURCES = os.path.join(os.path.dirname(__file__), "test_resources") -_INPUT_FILE = os.path.join(_RESOURCES, "pillow.png") -_OUTPUT_FILE = os.path.join(_RESOURCES, "pillow_on_beach.png") -_PROMPT = "beach" - - -@pytest.mark.skip("imagegeneration@006 samples pending deprecation") -@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=60) -def test_edit_image_product_image() -> None: - response = edit_image_product_image.edit_image_product_image( - _INPUT_FILE, - _OUTPUT_FILE, - _PROMPT, - ) - - assert len(response[0]._image_bytes) > 1000