From 027689238b370f504b2843db7975877c78ebee9d Mon Sep 17 00:00:00 2001 From: madhavmadupu Date: Sun, 11 Jan 2026 07:35:33 +0530 Subject: [PATCH 1/2] fix: ensure output folder exists before saving image (#13695) --- genai/image_generation/imggen_mmflash_with_txt.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/genai/image_generation/imggen_mmflash_with_txt.py b/genai/image_generation/imggen_mmflash_with_txt.py index 0ee371b7e84..7fc9d42156e 100644 --- a/genai/image_generation/imggen_mmflash_with_txt.py +++ b/genai/image_generation/imggen_mmflash_with_txt.py @@ -19,6 +19,7 @@ def generate_content() -> str: from google.genai.types import GenerateContentConfig, Modality from PIL import Image from io import BytesIO + import os client = genai.Client() @@ -34,6 +35,7 @@ def generate_content() -> str: print(part.text) elif part.inline_data: image = Image.open(BytesIO((part.inline_data.data))) + os.makedirs("output_folder", exist_ok=True) image.save("output_folder/example-image-eiffel-tower.png") # [END googlegenaisdk_imggen_mmflash_with_txt] From b4833fde955338df28c2d2052006508f7b1429ee Mon Sep 17 00:00:00 2001 From: madhavmadupu Date: Sun, 11 Jan 2026 07:58:59 +0530 Subject: [PATCH 2/2] refactor: apply bot suggestions for PEP8 imports and path handling --- genai/image_generation/imggen_mmflash_with_txt.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/genai/image_generation/imggen_mmflash_with_txt.py b/genai/image_generation/imggen_mmflash_with_txt.py index 7fc9d42156e..cd6c458a757 100644 --- a/genai/image_generation/imggen_mmflash_with_txt.py +++ b/genai/image_generation/imggen_mmflash_with_txt.py @@ -15,11 +15,12 @@ def generate_content() -> str: # [START googlegenaisdk_imggen_mmflash_with_txt] + import os + from io import BytesIO + from google import genai from google.genai.types import GenerateContentConfig, Modality from PIL import Image - from io import BytesIO - import os client = genai.Client() @@ -35,8 +36,10 @@ def generate_content() -> str: print(part.text) elif part.inline_data: image = Image.open(BytesIO((part.inline_data.data))) - os.makedirs("output_folder", exist_ok=True) - image.save("output_folder/example-image-eiffel-tower.png") + # 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")) # [END googlegenaisdk_imggen_mmflash_with_txt] return True