diff --git a/generative_ai/embeddings/multimodal_image_example.py b/generative_ai/embeddings/multimodal_image_example.py deleted file mode 100644 index 84549f16ba..0000000000 --- a/generative_ai/embeddings/multimodal_image_example.py +++ /dev/null @@ -1,57 +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 - -from vertexai.vision_models import MultiModalEmbeddingResponse - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def get_image_text_embeddings() -> MultiModalEmbeddingResponse: - """Example of how to generate multimodal embeddings from image and text. - - Read more @ https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-multimodal-embeddings#text-image-embedding - """ - # [START generativeaionvertexai_multimodal_embedding_image] - import vertexai - from vertexai.vision_models import Image, MultiModalEmbeddingModel - - # TODO(developer): Update & uncomment line below - # PROJECT_ID = "your-project-id" - vertexai.init(project=PROJECT_ID, location="us-central1") - - model = MultiModalEmbeddingModel.from_pretrained("multimodalembedding@001") - image = Image.load_from_file( - "gs://cloud-samples-data/vertex-ai/llm/prompts/landmark1.png" - ) - - embeddings = model.get_embeddings( - image=image, - contextual_text="Colosseum", - dimension=1408, - ) - print(f"Image Embedding: {embeddings.image_embedding}") - print(f"Text Embedding: {embeddings.text_embedding}") - # Example response: - # Image Embedding: [-0.0123147098, 0.0727171078, ...] - # Text Embedding: [0.00230263756, 0.0278981831, ...] - - # [END generativeaionvertexai_multimodal_embedding_image] - - return embeddings - - -if __name__ == "__main__": - get_image_text_embeddings() diff --git a/generative_ai/embeddings/multimodal_video_example.py b/generative_ai/embeddings/multimodal_video_example.py deleted file mode 100644 index df9dcd31c1..0000000000 --- a/generative_ai/embeddings/multimodal_video_example.py +++ /dev/null @@ -1,64 +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 - -from vertexai.vision_models import MultiModalEmbeddingResponse - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def get_video_embeddings() -> MultiModalEmbeddingResponse: - """Example of how to use the multimodal embedding model to get embeddings only for video content. - - Read more at https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-multimodal-embeddings#vid-embedding - """ - # [START generativeaionvertexai_multimodal_embedding_video] - import vertexai - - from vertexai.vision_models import MultiModalEmbeddingModel, Video - from vertexai.vision_models import VideoSegmentConfig - - # TODO(developer): Update & uncomment line below - # PROJECT_ID = "your-project-id" - vertexai.init(project=PROJECT_ID, location="us-central1") - - model = MultiModalEmbeddingModel.from_pretrained("multimodalembedding@001") - - embeddings = model.get_embeddings( - video=Video.load_from_file( - "gs://cloud-samples-data/vertex-ai-vision/highway_vehicles.mp4" - ), - video_segment_config=VideoSegmentConfig(end_offset_sec=1), - ) - - # Video Embeddings are segmented based on the video_segment_config. - print("Video Embeddings:") - for video_embedding in embeddings.video_embeddings: - print( - f"Video Segment: {video_embedding.start_offset_sec} - {video_embedding.end_offset_sec}" - ) - print(f"Embedding: {video_embedding.embedding}") - - # Example response: - # Video Embeddings: - # Video Segment: 0.0 - 1.0 - # Embedding: [-0.0206376351, 0.0123456789, ...] - - # [END generativeaionvertexai_multimodal_embedding_video] - - return embeddings - - -if __name__ == "__main__": - get_video_embeddings() diff --git a/generative_ai/embeddings/test_embeddings_examples.py b/generative_ai/embeddings/test_embeddings_examples.py index b430b978e2..46eeddec88 100644 --- a/generative_ai/embeddings/test_embeddings_examples.py +++ b/generative_ai/embeddings/test_embeddings_examples.py @@ -14,28 +14,23 @@ import os import backoff - -from google.api_core.exceptions import FailedPrecondition, ResourceExhausted - -import google.auth - -from google.cloud import aiplatform -from google.cloud.aiplatform import initializer as aiplatform_init - - import batch_example import code_retrieval_example import document_retrieval_example import generate_embeddings_with_lower_dimension +from google.api_core.exceptions import FailedPrecondition, ResourceExhausted +import google.auth +from google.cloud import aiplatform +from google.cloud.aiplatform import initializer as aiplatform_init import model_tuning_example import multimodal_example -import multimodal_image_example -import multimodal_video_example @backoff.on_exception(backoff.expo, ResourceExhausted, max_time=10) def test_embed_text_batch() -> None: - batch_prediction_job = batch_example.embed_text_batch("gs://python-docs-samples-tests/") + batch_prediction_job = batch_example.embed_text_batch( + "gs://python-docs-samples-tests/" + ) assert batch_prediction_job @@ -48,21 +43,6 @@ def test_multimodal_embedding_image_video_text() -> None: assert embeddings.text_embedding is not None -@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=10) -def test_multimodal_embedding_video() -> None: - embeddings = multimodal_video_example.get_video_embeddings() - assert embeddings is not None - assert embeddings.video_embeddings is not None - - -@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=10) -def test_multimodal_embedding_image() -> None: - embeddings = multimodal_image_example.get_image_text_embeddings() - assert embeddings is not None - assert embeddings.image_embedding is not None - assert embeddings.text_embedding is not None - - @backoff.on_exception(backoff.expo, ResourceExhausted, max_time=10) def test_generate_embeddings_with_lower_dimension() -> None: embeddings = ( diff --git a/generative_ai/image_generation/edit_image_inpainting_insert_mask.py b/generative_ai/image_generation/edit_image_inpainting_insert_mask.py deleted file mode 100644 index beb2bd6351..0000000000 --- a/generative_ai/image_generation/edit_image_inpainting_insert_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. - Inpainting can insert the object designated by the prompt into the masked - area. -""" -import os - -from vertexai.preview import vision_models - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def edit_image_inpainting_insert_mask( - input_file: str, - mask_file: str, - output_file: str, - prompt: str, -) -> vision_models.ImageGenerationResponse: - # [START generativeaionvertexai_imagen_edit_image_inpainting_insert_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 = "red hat" # The 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="inpainting-insert", - ) - - 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 1400814 bytes - - # [END generativeaionvertexai_imagen_edit_image_inpainting_insert_mask] - - return images - - -if __name__ == "__main__": - edit_image_inpainting_insert_mask( - input_file="test_resources/woman.png", - mask_file="test_resources/woman_inpainting_insert_mask.png", - output_file="test_resources/woman_with_hat.png", - prompt="red hat", - ) diff --git a/generative_ai/image_generation/edit_image_inpainting_insert_mask_mode.py b/generative_ai/image_generation/edit_image_inpainting_insert_mask_mode.py deleted file mode 100644 index e6f388dffe..0000000000 --- a/generative_ai/image_generation/edit_image_inpainting_insert_mask_mode.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 mode. The - mask mode is used to automatically select the background, foreground (i.e., - the primary subject of the image), or an object based on segmentation class. - Inpainting can insert the object or background designated by the prompt. -""" -import os - -from vertexai.preview import vision_models - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def edit_image_inpainting_insert_mask_mode( - input_file: str, - mask_mode: str, - output_file: str, - prompt: str, -) -> vision_models.ImageGenerationResponse: - # [START generativeaionvertexai_imagen_edit_image_inpainting_insert_mask_mode] - - 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_mode = "background" # 'background', 'foreground', or 'semantic' - # output_file = "output-image.png" - # prompt = "beach" # The 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) - - images = model.edit_image( - base_image=base_img, - mask_mode=mask_mode, - prompt=prompt, - edit_mode="inpainting-insert", - ) - - 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_inpainting_insert_mask_mode] - - return images - - -if __name__ == "__main__": - edit_image_inpainting_insert_mask_mode( - input_file="test_resources/woman.png", - mask_mode="background", - output_file="test_resources/woman_at_beach.png", - prompt="beach", - ) diff --git a/generative_ai/image_generation/edit_image_inpainting_insert_mask_mode_test.py b/generative_ai/image_generation/edit_image_inpainting_insert_mask_mode_test.py deleted file mode 100644 index bdae7e6041..0000000000 --- a/generative_ai/image_generation/edit_image_inpainting_insert_mask_mode_test.py +++ /dev/null @@ -1,44 +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_inpainting_insert_mask_mode - - -_RESOURCES = os.path.join(os.path.dirname(__file__), "test_resources") -_INPUT_FILE = os.path.join(_RESOURCES, "woman.png") -_MASK_MODE = "background" -_OUTPUT_FILE = os.path.join(_RESOURCES, "woman_at_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_inpainting_insert_mask_mode() -> None: - response = ( - edit_image_inpainting_insert_mask_mode.edit_image_inpainting_insert_mask_mode( - _INPUT_FILE, - _MASK_MODE, - _OUTPUT_FILE, - _PROMPT, - ) - ) - - assert len(response[0]._image_bytes) > 1000 diff --git a/generative_ai/image_generation/edit_image_inpainting_insert_mask_test.py b/generative_ai/image_generation/edit_image_inpainting_insert_mask_test.py deleted file mode 100644 index 5fadcfa78d..0000000000 --- a/generative_ai/image_generation/edit_image_inpainting_insert_mask_test.py +++ /dev/null @@ -1,41 +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_inpainting_insert_mask - - -_RESOURCES = os.path.join(os.path.dirname(__file__), "test_resources") -_INPUT_FILE = os.path.join(_RESOURCES, "woman.png") -_MASK_FILE = os.path.join(_RESOURCES, "woman_inpainting_insert_mask.png") -_OUTPUT_FILE = os.path.join(_RESOURCES, "woman_with_hat.png") -_PROMPT = "hat" - - -@pytest.mark.skip("imagegeneration@006 samples pending deprecation") -@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=60) -def test_edit_image_inpainting_insert_mask() -> None: - response = edit_image_inpainting_insert_mask.edit_image_inpainting_insert_mask( - _INPUT_FILE, - _MASK_FILE, - _OUTPUT_FILE, - _PROMPT, - ) - - assert len(response[0]._image_bytes) > 1000 diff --git a/generative_ai/image_generation/edit_image_inpainting_remove_mask.py b/generative_ai/image_generation/edit_image_inpainting_remove_mask.py deleted file mode 100644 index 6990e24e77..0000000000 --- a/generative_ai/image_generation/edit_image_inpainting_remove_mask.py +++ /dev/null @@ -1,78 +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. - Inpainting can remove an object from the masked area. -""" -import os - -from vertexai.preview import vision_models - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def edit_image_inpainting_remove_mask( - input_file: str, - mask_file: str, - output_file: str, - prompt: str, -) -> vision_models.ImageGenerationResponse: - # [START generativeaionvertexai_imagen_edit_image_inpainting_remove_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 = "outpur-image.png" - # prompt = "" # The text prompt describing the entire image. - - 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="inpainting-remove", - # Optional parameters - # negative_prompt="", # Describes the object being removed (i.e., "person") - ) - - 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 12345678 bytes - - # [END generativeaionvertexai_imagen_edit_image_inpainting_remove_mask] - - return images - - -if __name__ == "__main__": - edit_image_inpainting_remove_mask( - input_file="test_resources/volleyball_game.png", - mask_file="test_resources/volleyball_game_inpainting_remove_mask.png", - output_file="test_resources/volleyball_game_single_blue_player.png", - prompt="volleyball game", - ) diff --git a/generative_ai/image_generation/edit_image_inpainting_remove_mask_mode.py b/generative_ai/image_generation/edit_image_inpainting_remove_mask_mode.py deleted file mode 100644 index 2130fdc6da..0000000000 --- a/generative_ai/image_generation/edit_image_inpainting_remove_mask_mode.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 mode. The - mask mode is used to automatically select the background, foreground (i.e., - the primary subject of the image), or an object based on segmentation class. - Inpainting can remove the object or background designated by the prompt. -""" -import os - -from vertexai.preview import vision_models - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def edit_image_inpainting_remove_mask_mode( - input_file: str, - mask_mode: str, - output_file: str, - prompt: str, -) -> vision_models.ImageGenerationResponse: - # [START generativeaionvertexai_imagen_edit_image_inpainting_remove_mask_mode] - - 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_mode = "foreground" # 'background', 'foreground', or 'semantic' - # output_file = "output-image.png" - # prompt = "sports car" # The text prompt describing what you want to see in the edited image. - - 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, - mask_mode=mask_mode, - prompt=prompt, - edit_mode="inpainting-remove", - ) - - 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 1279948 bytes - - # [END generativeaionvertexai_imagen_edit_image_inpainting_remove_mask_mode] - - return images - - -if __name__ == "__main__": - edit_image_inpainting_remove_mask_mode( - input_file="test_resources/woman.png", - mask_mode="foreground", - output_file="test_resources/sports_car.png", - prompt="sports car", - ) diff --git a/generative_ai/image_generation/edit_image_inpainting_remove_mask_mode_test.py b/generative_ai/image_generation/edit_image_inpainting_remove_mask_mode_test.py deleted file mode 100644 index 68dea24551..0000000000 --- a/generative_ai/image_generation/edit_image_inpainting_remove_mask_mode_test.py +++ /dev/null @@ -1,44 +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_inpainting_remove_mask_mode - - -_RESOURCES = os.path.join(os.path.dirname(__file__), "test_resources") -_INPUT_FILE = os.path.join(_RESOURCES, "woman.png") -_MASK_MODE = "foreground" -_OUTPUT_FILE = os.path.join(_RESOURCES, "sports_car.png") -_PROMPT = "sports car" - - -@pytest.mark.skip("imagegeneration@006 samples pending deprecation") -@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=60) -def test_edit_image_inpainting_remove_mask_mode() -> None: - response = ( - edit_image_inpainting_remove_mask_mode.edit_image_inpainting_remove_mask_mode( - _INPUT_FILE, - _MASK_MODE, - _OUTPUT_FILE, - _PROMPT, - ) - ) - - assert len(response[0]._image_bytes) > 1000 diff --git a/generative_ai/image_generation/edit_image_inpainting_remove_mask_test.py b/generative_ai/image_generation/edit_image_inpainting_remove_mask_test.py deleted file mode 100644 index b11b1b1605..0000000000 --- a/generative_ai/image_generation/edit_image_inpainting_remove_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_inpainting_remove_mask - - -_RESOURCES = os.path.join(os.path.dirname(__file__), "test_resources") -_INPUT_FILE = os.path.join(_RESOURCES, "volleyball_game.png") -_MASK_FILE = os.path.join(_RESOURCES, "volleyball_game_inpainting_remove_mask.png") -_OUTPUT_FILE = os.path.join(_RESOURCES, "volleyball_game_single_blue_player.png") -_PROMPT = "volleyball game" - - -@pytest.mark.skip("imagegeneration@006 samples pending deprecation") -@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=60) -def test_edit_image_inpainting_remove_mask() -> None: - response = edit_image_inpainting_remove_mask.edit_image_inpainting_remove_mask( - _INPUT_FILE, - _MASK_FILE, - _OUTPUT_FILE, - _PROMPT, - ) - - assert len(response[0]._image_bytes) > 1000 diff --git a/generative_ai/prompts/prompt_template.py b/generative_ai/prompts/prompt_template.py deleted file mode 100644 index 7517c7bb66..0000000000 --- a/generative_ai/prompts/prompt_template.py +++ /dev/null @@ -1,67 +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 - -from vertexai.generative_models import GenerationResponse - - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def prompt_template_example() -> list[GenerationResponse]: - """Build a parameterized prompt template to generate content with multiple variable sets""" - - # [START generativeaionvertexai_prompt_template] - import vertexai - from vertexai.preview.prompts import Prompt - - # Initialize vertexai - vertexai.init(project=PROJECT_ID, location="us-central1") - - variables = [ - {"animal": "Eagles", "activity": "eat berries"}, - {"animal": "Coyotes", "activity": "jump"}, - {"animal": "Squirrels", "activity": "fly"} - ] - - # define prompt template - prompt = Prompt( - prompt_data="Do {animal} {activity}?", - model_name="gemini-2.0-flash-001", - variables=variables, - system_instruction="You are a helpful zoologist" - # generation_config=generation_config, # Optional - # safety_settings=safety_settings, # Optional - ) - - # Generates content using the assembled prompt. - responses = [] - for variable_set in prompt.variables: - response = prompt.generate_content( - contents=prompt.assemble_contents(**variable_set) - ) - responses.append(response) - - for response in responses: - print(response.text, end="") - - # Example response - # Assembled prompt replacing: 1 instances of variable animal, 1 instances of variable activity - # Eagles are primarily carnivorous. While they might *accidentally* ingest a berry...... - # [END generativeaionvertexai_prompt_template] - return responses - - -if __name__ == "__main__": - prompt_template_example() diff --git a/generative_ai/prompts/test_prompt_template.py b/generative_ai/prompts/test_prompt_template.py index 92c358e5d1..218df2e596 100644 --- a/generative_ai/prompts/test_prompt_template.py +++ b/generative_ai/prompts/test_prompt_template.py @@ -20,12 +20,6 @@ import prompt_list_prompts import prompt_list_version # import prompt_restore_version -import prompt_template - - -def test_prompt_template() -> None: - text = prompt_template.prompt_template_example() - assert len(text) > 2 def test_prompt_create() -> None: