Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: validated that this was the correct model

contents=[image, "Edit this image to make it look like a cartoon."],
config=GenerateContentConfig(response_modalities=[Modality.TEXT, Modality.IMAGE]),
)
Expand Down
51 changes: 51 additions & 0 deletions genai/image_generation/imggen_mmflash_img_with_vid.py
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion genai/image_generation/imggen_mmflash_with_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
4 changes: 4 additions & 0 deletions genai/image_generation/test_image_generation_mmflash.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()