diff --git a/generative_ai/image_generation/generate_image.py b/generative_ai/image_generation/generate_image.py deleted file mode 100644 index 397119a23f5..00000000000 --- a/generative_ai/image_generation/generate_image.py +++ /dev/null @@ -1,73 +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 generating an image using only - descriptive text as an input. -""" -import os - -from vertexai.preview import vision_models - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def generate_image( - output_file: str, prompt: str -) -> vision_models.ImageGenerationResponse: - # [START generativeaionvertexai_imagen_generate_image] - - import vertexai - from vertexai.preview.vision_models import ImageGenerationModel - - # TODO(developer): Update and un-comment below lines - # PROJECT_ID = "your-project-id" - # output_file = "input-image.png" - # prompt = "" # The text prompt describing what you want to see. - - vertexai.init(project=PROJECT_ID, location="us-central1") - - model = ImageGenerationModel.from_pretrained("imagen-3.0-generate-002") - - images = model.generate_images( - prompt=prompt, - # Optional parameters - number_of_images=1, - language="en", - # You can't use a seed value and watermark at the same time. - # add_watermark=False, - # seed=100, - aspect_ratio="1:1", - safety_filter_level="block_some", - person_generation="allow_adult", - ) - - images[0].save(location=output_file, include_generation_parameters=False) - - # Optional. View the generated 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_generate_image] - - return images - - -if __name__ == "__main__": - generate_image( - output_file="test_resources/dog_newspaper.png", - prompt="A dog reading a newspaper", - ) diff --git a/generative_ai/image_generation/generate_image_test.py b/generative_ai/image_generation/generate_image_test.py deleted file mode 100644 index ed8ab2b8bf5..00000000000 --- a/generative_ai/image_generation/generate_image_test.py +++ /dev/null @@ -1,36 +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 generate_image - - -_RESOURCES = os.path.join(os.path.dirname(__file__), "test_resources") -_OUTPUT_FILE = os.path.join(_RESOURCES, "dog_newspaper.png") -_PROMPT = "a dog reading a newspaper" - - -@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=60) -def test_generate_image() -> None: - response = generate_image.generate_image( - _OUTPUT_FILE, - _PROMPT, - ) - - assert len(response[0]._image_bytes) > 1000 diff --git a/generative_ai/image_generation/get_short_form_image_captions.py b/generative_ai/image_generation/get_short_form_image_captions.py deleted file mode 100644 index b2ed8d3d335..00000000000 --- a/generative_ai/image_generation/get_short_form_image_captions.py +++ /dev/null @@ -1,54 +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 getting short-form image captions. -""" -import os - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def get_short_form_image_captions(input_file: str) -> list: - # [START generativeaionvertexai_imagen_get_short_form_image_captions] - - import vertexai - from vertexai.preview.vision_models import Image, ImageTextModel - - # TODO(developer): Update and un-comment below lines - # PROJECT_ID = "your-project-id" - # input_file = "input-image.png" - - vertexai.init(project=PROJECT_ID, location="us-central1") - - model = ImageTextModel.from_pretrained("imagetext@001") - source_img = Image.load_from_file(location=input_file) - - captions = model.get_captions( - image=source_img, - # Optional parameters - language="en", - number_of_results=2, - ) - - print(captions) - # Example response: - # ['a cat with green eyes looks up at the sky'] - - # [END generativeaionvertexai_imagen_get_short_form_image_captions] - - return captions - - -if __name__ == "__main__": - get_short_form_image_captions("test_resources/cat.png") diff --git a/generative_ai/image_generation/get_short_form_image_captions_test.py b/generative_ai/image_generation/get_short_form_image_captions_test.py deleted file mode 100644 index 2364d45d306..00000000000 --- a/generative_ai/image_generation/get_short_form_image_captions_test.py +++ /dev/null @@ -1,36 +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 get_short_form_image_captions - - -_RESOURCES = os.path.join(os.path.dirname(__file__), "test_resources") -_INPUT_FILE = os.path.join(_RESOURCES, "cat.png") - - -@pytest.mark.skip("Sample pending deprecation b/452720552") -@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=60) -def test_get_short_form_image_captions() -> None: - response = get_short_form_image_captions.get_short_form_image_captions( - _INPUT_FILE, - ) - - assert len(response) > 0 and "cat" in response[0] diff --git a/generative_ai/image_generation/get_short_form_image_responses.py b/generative_ai/image_generation/get_short_form_image_responses.py deleted file mode 100644 index 79b81c1c0cc..00000000000 --- a/generative_ai/image_generation/get_short_form_image_responses.py +++ /dev/null @@ -1,59 +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 getting short-form responses to a - question about an image. -""" -import os - -PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") - - -def get_short_form_image_responses(input_file: str, question: str) -> list: - # [START generativeaionvertexai_imagen_get_short_form_image_responses] - - import vertexai - from vertexai.preview.vision_models import Image, ImageTextModel - - # TODO(developer): Update and un-comment below lines - # PROJECT_ID = "your-project-id" - # input_file = "input-image.png" - # question = "" # The question about the contents of the image. - - vertexai.init(project=PROJECT_ID, location="us-central1") - - model = ImageTextModel.from_pretrained("imagetext@001") - source_img = Image.load_from_file(location=input_file) - - answers = model.ask_question( - image=source_img, - question=question, - # Optional parameters - number_of_results=1, - ) - - print(answers) - # Example response: - # ['tabby'] - - # [END generativeaionvertexai_imagen_get_short_form_image_responses] - - return answers - - -if __name__ == "__main__": - get_short_form_image_responses( - input_file="test_resources/cat.png", - question="What breed of cat is this a picture of?", - ) diff --git a/generative_ai/image_generation/get_short_form_image_responses_test.py b/generative_ai/image_generation/get_short_form_image_responses_test.py deleted file mode 100644 index c901a8734bd..00000000000 --- a/generative_ai/image_generation/get_short_form_image_responses_test.py +++ /dev/null @@ -1,38 +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 get_short_form_image_responses - - -_RESOURCES = os.path.join(os.path.dirname(__file__), "test_resources") -_INPUT_FILE = os.path.join(_RESOURCES, "cat.png") -_QUESTION = "What breed of cat is this a picture of?" - - -@pytest.mark.skip("Sample pending deprecation b/452720552") -@backoff.on_exception(backoff.expo, ResourceExhausted, max_time=60) -def test_get_short_form_image_responses() -> None: - response = get_short_form_image_responses.get_short_form_image_responses( - _INPUT_FILE, - _QUESTION, - ) - - assert len(response) > 0 and "tabby" in response[0] diff --git a/generative_ai/image_generation/noxfile_config.py b/generative_ai/image_generation/noxfile_config.py deleted file mode 100644 index 0973c8621c7..00000000000 --- a/generative_ai/image_generation/noxfile_config.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2021 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. - -# Default TEST_CONFIG_OVERRIDE for python repos. - -# You can copy this file into your directory, then it will be imported from -# the noxfile.py. - -# The source of truth: -# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py - -TEST_CONFIG_OVERRIDE = { - # You can opt out from the test for specific Python versions. - "ignored_versions": ["3.8", "3.9", "3.11", "3.12", "3.13"], - # Old samples are opted out of enforcing Python type hints - # All new samples should feature them - "enforce_type_hints": True, - # An envvar key for determining the project id to use. Change it - # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a - # build specific Cloud project. You can also use your own string - # to use your own Cloud project. - "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", - # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - # If you need to use a specific version of pip, - # change pip_version_override to the string representation - # of the version number, for example, "20.2.4" - "pip_version_override": None, - # A dictionary you want to inject into your test. Don't put any - # secrets here. These values will override predefined values. - "envs": {}, -} diff --git a/generative_ai/image_generation/requirements-test.txt b/generative_ai/image_generation/requirements-test.txt deleted file mode 100644 index baa23bf9c3e..00000000000 --- a/generative_ai/image_generation/requirements-test.txt +++ /dev/null @@ -1,4 +0,0 @@ -backoff==2.2.1 -google-api-core==2.19.0 -pytest==9.0.3; python_version >= "3.10" -pytest-asyncio==0.23.6 diff --git a/generative_ai/image_generation/requirements.txt b/generative_ai/image_generation/requirements.txt deleted file mode 100644 index 7ac0ee30a69..00000000000 --- a/generative_ai/image_generation/requirements.txt +++ /dev/null @@ -1,13 +0,0 @@ -pandas==2.2.3; python_version == '3.7' -pandas==2.2.3; python_version == '3.8' -pandas==2.2.3; python_version > '3.8' -pillow==12.3.0 -google-cloud-aiplatform[full]==1.157.0 -sentencepiece==0.2.1 -google-auth==2.38.0 -anthropic[vertex]==0.28.0 -langchain-core==1.4.0 -langchain-google-vertexai==3.2.3 -numpy<3 -openai==1.68.2 -immutabledict==4.2.0 diff --git a/generative_ai/image_generation/test_resources/cat.png b/generative_ai/image_generation/test_resources/cat.png deleted file mode 100644 index 67f2b55a6f4..00000000000 Binary files a/generative_ai/image_generation/test_resources/cat.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/dog.png b/generative_ai/image_generation/test_resources/dog.png deleted file mode 100644 index a5040ca8f75..00000000000 Binary files a/generative_ai/image_generation/test_resources/dog.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/dog_book.png b/generative_ai/image_generation/test_resources/dog_book.png deleted file mode 100644 index a71a7bbf858..00000000000 Binary files a/generative_ai/image_generation/test_resources/dog_book.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/dog_newspaper.png b/generative_ai/image_generation/test_resources/dog_newspaper.png deleted file mode 100644 index cd47e3d7707..00000000000 Binary files a/generative_ai/image_generation/test_resources/dog_newspaper.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/dog_newspaper_mask.png b/generative_ai/image_generation/test_resources/dog_newspaper_mask.png deleted file mode 100644 index d0cceae3a06..00000000000 Binary files a/generative_ai/image_generation/test_resources/dog_newspaper_mask.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/pillow.png b/generative_ai/image_generation/test_resources/pillow.png deleted file mode 100644 index 8803f49defe..00000000000 Binary files a/generative_ai/image_generation/test_resources/pillow.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/pillow_on_beach.png b/generative_ai/image_generation/test_resources/pillow_on_beach.png deleted file mode 100644 index 630d987dae9..00000000000 Binary files a/generative_ai/image_generation/test_resources/pillow_on_beach.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/roller_skaters.png b/generative_ai/image_generation/test_resources/roller_skaters.png deleted file mode 100644 index e63adbfdcec..00000000000 Binary files a/generative_ai/image_generation/test_resources/roller_skaters.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/roller_skaters_downtown.png b/generative_ai/image_generation/test_resources/roller_skaters_downtown.png deleted file mode 100644 index c6c2556c9a1..00000000000 Binary files a/generative_ai/image_generation/test_resources/roller_skaters_downtown.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/roller_skaters_mask.png b/generative_ai/image_generation/test_resources/roller_skaters_mask.png deleted file mode 100644 index 333da898979..00000000000 Binary files a/generative_ai/image_generation/test_resources/roller_skaters_mask.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/sports_car.png b/generative_ai/image_generation/test_resources/sports_car.png deleted file mode 100644 index f4786c9a2ca..00000000000 Binary files a/generative_ai/image_generation/test_resources/sports_car.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/volleyball_game.png b/generative_ai/image_generation/test_resources/volleyball_game.png deleted file mode 100644 index 2a335ef4fba..00000000000 Binary files a/generative_ai/image_generation/test_resources/volleyball_game.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/volleyball_game_inpainting_remove_mask.png b/generative_ai/image_generation/test_resources/volleyball_game_inpainting_remove_mask.png deleted file mode 100644 index 784c1f5a423..00000000000 Binary files a/generative_ai/image_generation/test_resources/volleyball_game_inpainting_remove_mask.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/volleyball_game_single_blue_player.png b/generative_ai/image_generation/test_resources/volleyball_game_single_blue_player.png deleted file mode 100644 index 89c3a720e33..00000000000 Binary files a/generative_ai/image_generation/test_resources/volleyball_game_single_blue_player.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/woman.png b/generative_ai/image_generation/test_resources/woman.png deleted file mode 100644 index f2329243681..00000000000 Binary files a/generative_ai/image_generation/test_resources/woman.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/woman_at_beach.png b/generative_ai/image_generation/test_resources/woman_at_beach.png deleted file mode 100644 index 9f616dd8d3b..00000000000 Binary files a/generative_ai/image_generation/test_resources/woman_at_beach.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/woman_inpainting_insert_mask.png b/generative_ai/image_generation/test_resources/woman_inpainting_insert_mask.png deleted file mode 100644 index d5399635b0b..00000000000 Binary files a/generative_ai/image_generation/test_resources/woman_inpainting_insert_mask.png and /dev/null differ diff --git a/generative_ai/image_generation/test_resources/woman_with_hat.png b/generative_ai/image_generation/test_resources/woman_with_hat.png deleted file mode 100644 index 5f6af7e5de5..00000000000 Binary files a/generative_ai/image_generation/test_resources/woman_with_hat.png and /dev/null differ