Skip to content

Commit 2947b35

Browse files
feat(genai): Update samples to use Gemini 2.5 Flash MM (#13552)
* feat(genai): Update samples to use Gemini 2.5 Flash MM and separate test to use global endpoint. * fix(genai): fix return status error
1 parent f748924 commit 2947b35

8 files changed

+64
-34
lines changed

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-2.0-flash-preview-image-generation",
29+
model="gemini-2.5-flash-image-preview",
3030
contents=[image, "Edit this image to make it look like a cartoon."],
3131
config=GenerateContentConfig(response_modalities=[Modality.TEXT, Modality.IMAGE]),
3232
)

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.0-flash-preview-image-generation",
26+
model="gemini-2.5-flash-image-preview",
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.0-flash-preview-image-generation",
26+
model="gemini-2.5-flash-image-preview",
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: 2 additions & 2 deletions
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-2.0-flash-preview-image-generation",
26+
model="gemini-2.5-flash-image-preview",
2727
contents=(
2828
"Generate an illustrated recipe for a paella."
2929
"Create images to go alongside the text as you generate the recipe"
@@ -42,7 +42,7 @@ def generate_content() -> int:
4242
# A markdown page for a Paella recipe(`paella-recipe.md`) has been generated.
4343
# It includes detailed steps and several images illustrating the cooking process.
4444
# [END googlegenaisdk_imggen_mmflash_txt_and_img_with_txt]
45-
return i
45+
return True
4646

4747

4848
if __name__ == "__main__":

genai/image_generation/imggen_mmflash_with_txt.py

Lines changed: 2 additions & 2 deletions
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.0-flash-preview-image-generation",
26+
model="gemini-2.5-flash-image-preview",
2727
contents=("Generate an image of the Eiffel tower with fireworks in the background."),
2828
config=GenerateContentConfig(
2929
response_modalities=[Modality.TEXT, Modality.IMAGE],
@@ -32,7 +32,7 @@ def generate_content() -> str:
3232
{"method": "PROBABILITY"},
3333
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT"},
3434
{"threshold": "BLOCK_MEDIUM_AND_ABOVE"},
35-
]
35+
],
3636
),
3737
)
3838
for part in response.candidates[0].content.parts:

genai/image_generation/imggen_virtual_try_on_with_txt_img.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def virtual_try_on(output_file: str) -> Image:
2929
model="virtual-try-on-preview-08-04",
3030
source=RecontextImageSource(
3131
person_image=Image.from_file(location="test_resources/man.png"),
32-
product_images=[ProductImage(product_image=Image.from_file(location="test_resources/sweater.jpg"))],
32+
product_images=[
33+
ProductImage(product_image=Image.from_file(location="test_resources/sweater.jpg"))
34+
],
3335
),
3436
)
3537

genai/image_generation/test_image_generation.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@
3030
import imggen_inpainting_removal_mask_with_txt_img
3131
import imggen_inpainting_removal_with_txt_img
3232
import imggen_mask_free_edit_with_txt_img
33-
import imggen_mmflash_edit_img_with_txt_img
34-
import imggen_mmflash_locale_aware_with_txt
35-
import imggen_mmflash_multiple_imgs_with_txt
36-
import imggen_mmflash_txt_and_img_with_txt
37-
import imggen_mmflash_with_txt
3833
import imggen_outpainting_with_txt_img
3934
import imggen_product_background_mask_with_txt_img
4035
import imggen_product_background_with_txt_img
@@ -122,7 +117,9 @@ def test_img_edit_mask_free() -> None:
122117

123118

124119
def test_img_customization_subject(output_gcs_uri: str) -> None:
125-
response = imggen_subj_refer_ctrl_refer_with_txt_imgs.subject_customization(output_gcs_uri=output_gcs_uri)
120+
response = imggen_subj_refer_ctrl_refer_with_txt_imgs.subject_customization(
121+
output_gcs_uri=output_gcs_uri
122+
)
126123
assert response
127124

128125

@@ -150,23 +147,3 @@ def test_img_virtual_try_on() -> None:
150147
OUTPUT_FILE = os.path.join(RESOURCES, "man_in_sweater.png")
151148
response = imggen_virtual_try_on_with_txt_img.virtual_try_on(OUTPUT_FILE)
152149
assert response
153-
154-
155-
def test_imggen_mmflash_with_txt() -> None:
156-
assert imggen_mmflash_with_txt.generate_content()
157-
158-
159-
def test_imggen_mmflash_edit_img_with_txt_img() -> None:
160-
assert imggen_mmflash_edit_img_with_txt_img.generate_content()
161-
162-
163-
def test_imggen_mmflash_txt_and_img_with_txt() -> None:
164-
assert imggen_mmflash_txt_and_img_with_txt.generate_content()
165-
166-
167-
def test_imggen_mmflash_locale_aware_with_txt() -> None:
168-
assert imggen_mmflash_locale_aware_with_txt.generate_content()
169-
170-
171-
def test_imggen_mmflash_multiple_imgs_with_txt() -> None:
172-
assert imggen_mmflash_multiple_imgs_with_txt.generate_content()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2025 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+
# Using Google Cloud Vertex AI to test the code samples.
17+
#
18+
19+
import os
20+
21+
import imggen_mmflash_edit_img_with_txt_img
22+
import imggen_mmflash_locale_aware_with_txt
23+
import imggen_mmflash_multiple_imgs_with_txt
24+
import imggen_mmflash_txt_and_img_with_txt
25+
import imggen_mmflash_with_txt
26+
27+
28+
os.environ["GOOGLE_GENAI_USE_VERTEXAI"] = "True"
29+
os.environ["GOOGLE_CLOUD_LOCATION"] = "global"
30+
# The project name is included in the CICD pipeline
31+
# os.environ['GOOGLE_CLOUD_PROJECT'] = "add-your-project-name"
32+
33+
34+
def test_imggen_mmflash_with_txt() -> None:
35+
assert imggen_mmflash_with_txt.generate_content()
36+
37+
38+
def test_imggen_mmflash_edit_img_with_txt_img() -> None:
39+
assert imggen_mmflash_edit_img_with_txt_img.generate_content()
40+
41+
42+
def test_imggen_mmflash_txt_and_img_with_txt() -> None:
43+
assert imggen_mmflash_txt_and_img_with_txt.generate_content()
44+
45+
46+
def test_imggen_mmflash_locale_aware_with_txt() -> None:
47+
assert imggen_mmflash_locale_aware_with_txt.generate_content()
48+
49+
50+
def test_imggen_mmflash_multiple_imgs_with_txt() -> None:
51+
assert imggen_mmflash_multiple_imgs_with_txt.generate_content()

0 commit comments

Comments
 (0)