From ce9a27786f62e99abbb0f5b0f2fa36ffafb6bdf7 Mon Sep 17 00:00:00 2001 From: Katie Nguyen <21978337+katiemn@users.noreply.github.com> Date: Tue, 6 Oct 2026 11:16:15 -0700 Subject: [PATCH 1/3] feat: update to latest nano banana model --- .../imggen_mmflash_edit_img_with_txt_img.py | 14 ++++++-------- .../imggen_mmflash_img_with_vid.py | 10 ++++------ .../imggen_mmflash_txt_and_img_with_txt.py | 11 ++++------- .../imggen_mmflash_with_txt.py | 18 ++++++++++-------- ...w-example-image.png => cartooon-image.png} | Bin 5 files changed, 24 insertions(+), 29 deletions(-) rename genai/image_generation/output_folder/{bw-example-image.png => cartooon-image.png} (100%) diff --git a/genai/image_generation/imggen_mmflash_edit_img_with_txt_img.py b/genai/image_generation/imggen_mmflash_edit_img_with_txt_img.py index 405702d4eff..d0a19f633ec 100644 --- a/genai/image_generation/imggen_mmflash_edit_img_with_txt_img.py +++ b/genai/image_generation/imggen_mmflash_edit_img_with_txt_img.py @@ -16,7 +16,7 @@ def generate_content() -> str: # [START googlegenaisdk_imggen_mmflash_edit_img_with_txt_img] from google import genai - from google.genai.types import GenerateContentConfig, Modality + from google.genai.types import GenerateContentConfig from PIL import Image from io import BytesIO @@ -26,19 +26,17 @@ def generate_content() -> str: image = Image.open("test_resources/example-image-eiffel-tower.png") response = client.models.generate_content( - model="gemini-3.1-flash-image", + model="gemini-nano-banana-2.1", contents=[image, "Edit this image to make it look like a cartoon."], - config=GenerateContentConfig(response_modalities=[Modality.TEXT, Modality.IMAGE]), + config=GenerateContentConfig(response_modalities=["IMAGE"]), ) for part in response.candidates[0].content.parts: - if part.text: - print(part.text) - elif part.inline_data: + if part.inline_data: image = Image.open(BytesIO((part.inline_data.data))) - image.save("output_folder/bw-example-image.png") + image.save("output_folder/cartoon-image.png") # [END googlegenaisdk_imggen_mmflash_edit_img_with_txt_img] - return "output_folder/bw-example-image.png" + return "output_folder/cartoon-image.png" if __name__ == "__main__": diff --git a/genai/image_generation/imggen_mmflash_img_with_vid.py b/genai/image_generation/imggen_mmflash_img_with_vid.py index 98a0c51f996..447d9e17464 100644 --- a/genai/image_generation/imggen_mmflash_img_with_vid.py +++ b/genai/image_generation/imggen_mmflash_img_with_vid.py @@ -16,7 +16,7 @@ def generate_content() -> str: # [START googlegenaisdk_imggen_mmflash_img_with_vid] from google import genai - from google.genai.types import GenerateContentConfig, Modality, Part + from google.genai.types import GenerateContentConfig, Part from PIL import Image from io import BytesIO @@ -26,7 +26,7 @@ def generate_content() -> str: video = "https://www.youtube.com/watch?v=rjoMZyxncUI" response = client.models.generate_content( - model="gemini-3.1-flash-image", + model="gemini-nano-banana-2.1", contents=[ Part.from_uri( file_uri=video, @@ -34,12 +34,10 @@ def generate_content() -> str: ), "Generate an infographic of the topics covered in this video." ], - config=GenerateContentConfig(response_modalities=[Modality.TEXT, Modality.IMAGE]), + config=GenerateContentConfig(response_modalities=["IMAGE"]), ) for part in response.candidates[0].content.parts: - if part.text: - print(part.text) - elif part.inline_data: + if part.inline_data: image = Image.open(BytesIO((part.inline_data.data))) image.save("output_folder/video-image.png") diff --git a/genai/image_generation/imggen_mmflash_txt_and_img_with_txt.py b/genai/image_generation/imggen_mmflash_txt_and_img_with_txt.py index ff2b9fda9f9..8eaf77312a8 100644 --- a/genai/image_generation/imggen_mmflash_txt_and_img_with_txt.py +++ b/genai/image_generation/imggen_mmflash_txt_and_img_with_txt.py @@ -16,19 +16,16 @@ def generate_content() -> int: # [START googlegenaisdk_imggen_mmflash_txt_and_img_with_txt] from google import genai - from google.genai.types import GenerateContentConfig, Modality + from google.genai.types import GenerateContentConfig from PIL import Image from io import BytesIO client = genai.Client() response = client.models.generate_content( - model="gemini-3.1-flash-image", - contents=( - "Generate an illustrated recipe for a paella." - "Create images to go alongside the text as you generate the recipe" - ), - config=GenerateContentConfig(response_modalities=[Modality.TEXT, Modality.IMAGE]), + model="gemini-nano-banana-2.1", + contents="Generate an illustrated recipe for paella. Create images to go alongside the text as you generate the recipe.", + config=GenerateContentConfig(response_modalities=["TEXT", "IMAGE"]), ) with open("output_folder/paella-recipe.md", "w") as fp: for i, part in enumerate(response.candidates[0].content.parts): diff --git a/genai/image_generation/imggen_mmflash_with_txt.py b/genai/image_generation/imggen_mmflash_with_txt.py index fd83f89eeda..1c0e7ead785 100644 --- a/genai/image_generation/imggen_mmflash_with_txt.py +++ b/genai/image_generation/imggen_mmflash_with_txt.py @@ -19,27 +19,29 @@ def generate_content() -> str: from io import BytesIO from google import genai - from google.genai.types import GenerateContentConfig, Modality + from google.genai.types import GenerateContentConfig, ImageConfig from PIL import Image client = genai.Client() response = client.models.generate_content( - model="gemini-3.1-flash-image", - contents=("Generate an image of the Eiffel tower with fireworks in the background."), + model="gemini-nano-banana-2.1", + contents="Generate a high-contrast, grainy black and white street photography shot.", config=GenerateContentConfig( - response_modalities=[Modality.TEXT, Modality.IMAGE], + response_modalities=["IMAGE"], + image_config=ImageConfig( + aspect_ratio="3:2", + image_size="1K", + ), ), ) for part in response.candidates[0].content.parts: - if part.text: - print(part.text) - elif part.inline_data: + if part.inline_data: image = Image.open(BytesIO((part.inline_data.data))) # Ensure the output directory exists output_dir = "output_folder" os.makedirs(output_dir, exist_ok=True) - image.save(os.path.join(output_dir, "example-image-eiffel-tower.png")) + image.save(os.path.join(output_dir, "example-image.png")) # [END googlegenaisdk_imggen_mmflash_with_txt] return True diff --git a/genai/image_generation/output_folder/bw-example-image.png b/genai/image_generation/output_folder/cartooon-image.png similarity index 100% rename from genai/image_generation/output_folder/bw-example-image.png rename to genai/image_generation/output_folder/cartooon-image.png From 073644a91dbcadaa61f644a53c761c9d835a0439 Mon Sep 17 00:00:00 2001 From: Katie Nguyen <21978337+katiemn@users.noreply.github.com> Date: Tue, 6 Oct 2026 11:24:27 -0700 Subject: [PATCH 2/3] feat: update SDK version --- genai/image_generation/requirements.txt | 2 +- genai/image_generation/test_image_generation.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/genai/image_generation/requirements.txt b/genai/image_generation/requirements.txt index cc8e5d32af3..c588f27c1db 100644 --- a/genai/image_generation/requirements.txt +++ b/genai/image_generation/requirements.txt @@ -1,2 +1,2 @@ -google-genai==1.42.0 +google-genai==2.28.0 pillow==12.2.0; python_version >= "3.10" diff --git a/genai/image_generation/test_image_generation.py b/genai/image_generation/test_image_generation.py index f5cf14bb62c..82f4d432cd1 100644 --- a/genai/image_generation/test_image_generation.py +++ b/genai/image_generation/test_image_generation.py @@ -42,7 +42,7 @@ import imggen_with_txt os.environ["GOOGLE_GENAI_USE_ENTERPRISE"] = "True" -os.environ["GOOGLE_CLOUD_LOCATION"] = "us-central1" +os.environ["GOOGLE_CLOUD_LOCATION"] = "global" # The project name is included in the CICD pipeline # os.environ['GOOGLE_CLOUD_PROJECT'] = "add-your-project-name" From d9a51af9dcf7e62e2fc902b7f0f21c0eaf039189 Mon Sep 17 00:00:00 2001 From: Katie Nguyen <21978337+katiemn@users.noreply.github.com> Date: Tue, 6 Oct 2026 11:39:39 -0700 Subject: [PATCH 3/3] fix: lint --- genai/image_generation/test_image_generation.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/genai/image_generation/test_image_generation.py b/genai/image_generation/test_image_generation.py index 82f4d432cd1..9cc81ad147a 100644 --- a/genai/image_generation/test_image_generation.py +++ b/genai/image_generation/test_image_generation.py @@ -22,8 +22,6 @@ from google.cloud import storage -import pytest - import imggen_canny_ctrl_type_with_txt_img import imggen_inpainting_insert_mask_with_txt_img import imggen_inpainting_insert_with_txt_img @@ -40,6 +38,7 @@ import imggen_upscale_with_img import imggen_virtual_try_on_with_txt_img import imggen_with_txt +import pytest os.environ["GOOGLE_GENAI_USE_ENTERPRISE"] = "True" os.environ["GOOGLE_CLOUD_LOCATION"] = "global"