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 e2d9888a02..405702d4ef 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 @@ -26,7 +26,7 @@ def generate_content() -> str: image = Image.open("test_resources/example-image-eiffel-tower.png") response = client.models.generate_content( - model="gemini-3-pro-image-preview", + model="gemini-3.1-flash-image", contents=[image, "Edit this image to make it look like a cartoon."], config=GenerateContentConfig(response_modalities=[Modality.TEXT, Modality.IMAGE]), ) diff --git a/genai/image_generation/imggen_mmflash_img_with_vid.py b/genai/image_generation/imggen_mmflash_img_with_vid.py new file mode 100644 index 0000000000..98a0c51f99 --- /dev/null +++ b/genai/image_generation/imggen_mmflash_img_with_vid.py @@ -0,0 +1,51 @@ +# Copyright 2026 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. + + +def generate_content() -> str: + # [START googlegenaisdk_imggen_mmflash_img_with_vid] + from google import genai + from google.genai.types import GenerateContentConfig, Modality, Part + from PIL import Image + from io import BytesIO + + client = genai.Client() + + # A video on 'The ABCs of agent building' + video = "https://www.youtube.com/watch?v=rjoMZyxncUI" + + response = client.models.generate_content( + model="gemini-3.1-flash-image", + contents=[ + Part.from_uri( + file_uri=video, + mime_type="video/mp4" + ), + "Generate an infographic of the topics covered in this video." + ], + config=GenerateContentConfig(response_modalities=[Modality.TEXT, Modality.IMAGE]), + ) + for part in response.candidates[0].content.parts: + if part.text: + print(part.text) + elif part.inline_data: + image = Image.open(BytesIO((part.inline_data.data))) + image.save("output_folder/video-image.png") + + # [END googlegenaisdk_imggen_mmflash_img_with_vid] + return "output_folder/video-image.png" + + +if __name__ == "__main__": + generate_content() diff --git a/genai/image_generation/imggen_mmflash_locale_aware_with_txt.py b/genai/image_generation/imggen_mmflash_locale_aware_with_txt.py index 305be883d2..2e80866a52 100644 --- a/genai/image_generation/imggen_mmflash_locale_aware_with_txt.py +++ b/genai/image_generation/imggen_mmflash_locale_aware_with_txt.py @@ -23,7 +23,7 @@ def generate_content() -> str: client = genai.Client() response = client.models.generate_content( - model="gemini-2.5-flash-image", + model="gemini-3.1-flash-image", contents=("Generate a photo of a breakfast meal."), config=GenerateContentConfig(response_modalities=[Modality.TEXT, Modality.IMAGE]), ) diff --git a/genai/image_generation/imggen_mmflash_multiple_imgs_with_txt.py b/genai/image_generation/imggen_mmflash_multiple_imgs_with_txt.py index 2b831ca97d..884dba9d45 100644 --- a/genai/image_generation/imggen_mmflash_multiple_imgs_with_txt.py +++ b/genai/image_generation/imggen_mmflash_multiple_imgs_with_txt.py @@ -23,7 +23,7 @@ def generate_content() -> str: client = genai.Client() response = client.models.generate_content( - model="gemini-2.5-flash-image", + model="gemini-3.1-flash-image", contents=("Generate 3 images a cat sitting on a chair."), config=GenerateContentConfig(response_modalities=[Modality.TEXT, Modality.IMAGE]), ) 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 7a9d11103a..ff2b9fda9f 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 @@ -23,7 +23,7 @@ def generate_content() -> int: client = genai.Client() response = client.models.generate_content( - model="gemini-3-pro-image-preview", + 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" diff --git a/genai/image_generation/imggen_mmflash_with_txt.py b/genai/image_generation/imggen_mmflash_with_txt.py index cd6c458a75..fd83f89eed 100644 --- a/genai/image_generation/imggen_mmflash_with_txt.py +++ b/genai/image_generation/imggen_mmflash_with_txt.py @@ -25,7 +25,7 @@ def generate_content() -> str: client = genai.Client() response = client.models.generate_content( - model="gemini-3-pro-image-preview", + model="gemini-3.1-flash-image", contents=("Generate an image of the Eiffel tower with fireworks in the background."), config=GenerateContentConfig( response_modalities=[Modality.TEXT, Modality.IMAGE], diff --git a/genai/image_generation/test_image_generation_mmflash.py b/genai/image_generation/test_image_generation_mmflash.py index 2eb4012365..1b6b46bae7 100644 --- a/genai/image_generation/test_image_generation_mmflash.py +++ b/genai/image_generation/test_image_generation_mmflash.py @@ -19,6 +19,7 @@ import os import imggen_mmflash_edit_img_with_txt_img +import imggen_mmflash_img_with_vid import imggen_mmflash_locale_aware_with_txt import imggen_mmflash_multiple_imgs_with_txt import imggen_mmflash_txt_and_img_with_txt @@ -49,3 +50,6 @@ def test_imggen_mmflash_locale_aware_with_txt() -> None: def test_imggen_mmflash_multiple_imgs_with_txt() -> None: assert imggen_mmflash_multiple_imgs_with_txt.generate_content() + +def test_imggen_mmflash_img_with_vid() -> None: + assert imggen_mmflash_img_with_vid.generate_content()