Skip to content

Commit cbab284

Browse files
feat: Nano Banana GA and video input samples (#14246)
* feat: Nano Banana GA and video input samples * Update genai/image_generation/imggen_mmflash_img_with_vid.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 5974915 commit cbab284

7 files changed

Lines changed: 60 additions & 5 deletions

genai/image_generation/imggen_mmflash_edit_img_with_txt_img.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def generate_content() -> str:
2626
image = Image.open("test_resources/example-image-eiffel-tower.png")
2727

2828
response = client.models.generate_content(
29-
model="gemini-3-pro-image-preview",
29+
model="gemini-3.1-flash-image",
3030
contents=[image, "Edit this image to make it look like a cartoon."],
3131
config=GenerateContentConfig(response_modalities=[Modality.TEXT, Modality.IMAGE]),
3232
)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
def generate_content() -> str:
17+
# [START googlegenaisdk_imggen_mmflash_img_with_vid]
18+
from google import genai
19+
from google.genai.types import GenerateContentConfig, Modality, Part
20+
from PIL import Image
21+
from io import BytesIO
22+
23+
client = genai.Client()
24+
25+
# A video on 'The ABCs of agent building'
26+
video = "https://www.youtube.com/watch?v=rjoMZyxncUI"
27+
28+
response = client.models.generate_content(
29+
model="gemini-3.1-flash-image",
30+
contents=[
31+
Part.from_uri(
32+
file_uri=video,
33+
mime_type="video/mp4"
34+
),
35+
"Generate an infographic of the topics covered in this video."
36+
],
37+
config=GenerateContentConfig(response_modalities=[Modality.TEXT, Modality.IMAGE]),
38+
)
39+
for part in response.candidates[0].content.parts:
40+
if part.text:
41+
print(part.text)
42+
elif part.inline_data:
43+
image = Image.open(BytesIO((part.inline_data.data)))
44+
image.save("output_folder/video-image.png")
45+
46+
# [END googlegenaisdk_imggen_mmflash_img_with_vid]
47+
return "output_folder/video-image.png"
48+
49+
50+
if __name__ == "__main__":
51+
generate_content()

genai/image_generation/imggen_mmflash_locale_aware_with_txt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def generate_content() -> str:
2323
client = genai.Client()
2424

2525
response = client.models.generate_content(
26-
model="gemini-2.5-flash-image",
26+
model="gemini-3.1-flash-image",
2727
contents=("Generate a photo of a breakfast meal."),
2828
config=GenerateContentConfig(response_modalities=[Modality.TEXT, Modality.IMAGE]),
2929
)

genai/image_generation/imggen_mmflash_multiple_imgs_with_txt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def generate_content() -> str:
2323
client = genai.Client()
2424

2525
response = client.models.generate_content(
26-
model="gemini-2.5-flash-image",
26+
model="gemini-3.1-flash-image",
2727
contents=("Generate 3 images a cat sitting on a chair."),
2828
config=GenerateContentConfig(response_modalities=[Modality.TEXT, Modality.IMAGE]),
2929
)

genai/image_generation/imggen_mmflash_txt_and_img_with_txt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def generate_content() -> int:
2323
client = genai.Client()
2424

2525
response = client.models.generate_content(
26-
model="gemini-3-pro-image-preview",
26+
model="gemini-3.1-flash-image",
2727
contents=(
2828
"Generate an illustrated recipe for a paella."
2929
"Create images to go alongside the text as you generate the recipe"

genai/image_generation/imggen_mmflash_with_txt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def generate_content() -> str:
2525
client = genai.Client()
2626

2727
response = client.models.generate_content(
28-
model="gemini-3-pro-image-preview",
28+
model="gemini-3.1-flash-image",
2929
contents=("Generate an image of the Eiffel tower with fireworks in the background."),
3030
config=GenerateContentConfig(
3131
response_modalities=[Modality.TEXT, Modality.IMAGE],

genai/image_generation/test_image_generation_mmflash.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import os
2020

2121
import imggen_mmflash_edit_img_with_txt_img
22+
import imggen_mmflash_img_with_vid
2223
import imggen_mmflash_locale_aware_with_txt
2324
import imggen_mmflash_multiple_imgs_with_txt
2425
import imggen_mmflash_txt_and_img_with_txt
@@ -49,3 +50,6 @@ def test_imggen_mmflash_locale_aware_with_txt() -> None:
4950

5051
def test_imggen_mmflash_multiple_imgs_with_txt() -> None:
5152
assert imggen_mmflash_multiple_imgs_with_txt.generate_content()
53+
54+
def test_imggen_mmflash_img_with_vid() -> None:
55+
assert imggen_mmflash_img_with_vid.generate_content()

0 commit comments

Comments
 (0)