Skip to content

Commit 7451abe

Browse files
committed
chore: remove the images_folder
Simplify the code footprint by using samples available in GCS bucket.
1 parent 5fae3da commit 7451abe

13 files changed

+17
-20
lines changed

genai/code_execution/codeexecution_annotateimage_with_txt_gcsimg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def generate_content() -> bool:
4848
if part.as_image() is not None:
4949
print("####################### 3. Save Output #######################")
5050
img_count += 1
51-
output_location = f"sample_images/output-annotate-image-{img_count}.jpg"
51+
output_location = f"robotic-annotate-output-{img_count}.jpg"
5252
image_data = part.as_image().image_bytes
5353
image = Image.open(io.BytesIO(image_data))
5454
image = image.convert("RGB")
@@ -134,7 +134,7 @@ def generate_content() -> bool:
134134
# ####################### 2. Executing Python Code #######################
135135
# None
136136
# ####################### 3. Save Output #######################
137-
# Output is saved to sample_images/output-annotate-image-1.jpg
137+
# Output is saved to output-annotate-image-1.jpg
138138
# The image has been annotated with arrows indicating the appropriate bin for each object based on standard waste sorting practices:
139139
#
140140
# - **Green Arrows (Compost):** Organic items such as the green pepper, red pepper, grapes, and cherries are directed to the **green bin**.

genai/code_execution/codeexecution_barplot_with_txt_img.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ def generate_content() -> bool:
2020
from google import genai
2121
from google.genai import types
2222

23-
# Read a local image as input
24-
image_pil = Image.open("sample_images/tabular_data.png")
25-
image_pil = image_pil.convert("RGB")
26-
byte_io = io.BytesIO()
27-
image_pil.save(byte_io, format="JPEG")
28-
image_bytes = byte_io.getvalue()
29-
image = types.Part.from_bytes(data=image_bytes, mime_type="image/jpeg")
23+
# Use to the benchmark image in Cloud Storage
24+
image = types.Part.from_uri(
25+
file_uri="https://storage.googleapis.com/cloud-samples-data/generative-ai/image/benchmark.jpeg",
26+
mime_type="image/jpeg",
27+
)
3028

3129
client = genai.Client()
3230

@@ -54,7 +52,7 @@ def generate_content() -> bool:
5452
if part.as_image() is not None:
5553
print("####################### 3. Save Output #######################")
5654
img_count += 1
57-
output_location = f"sample_images/output-barplot-{img_count}.jpg"
55+
output_location = f"output-barplot-{img_count}.jpg"
5856
image_data = part.as_image().image_bytes
5957
image = Image.open(io.BytesIO(image_data))
6058
image = image.convert("RGB")
@@ -140,9 +138,9 @@ def generate_content() -> bool:
140138
# {'Visual Reasoning': np.float64(1.3065950426525028), 'Document': np.float64(1.1065092453773113), 'Spatial': np.float64(1.3636746436001959), 'Screen': np.float64(1.4856952211773211), 'Video': np.float64(1.0620548283943443), 'Education': np.float64(1.0563204005006257), 'Biomedical': np.float64(1.1138909257119955)}
141139
#
142140
# ####################### 3. Save Output #######################
143-
# Output is saved to sample_images/output-barplot-1.jpg
141+
# Output is saved to output-barplot-1.jpg
144142
# ####################### 3. Save Output #######################
145-
# Output is saved to sample_images/output-barplot-2.jpg
143+
# Output is saved to output-barplot-2.jpg
146144
# Based on the data provided in the table, I have calculated the per-category performance of Gemini 3 Pro normalized against the prior state-of-the-art (SOTA), which is defined as the best performance among Gemini 2.5 Pro, Claude Opus 4.5, and GPT-5.1 for each benchmark.
147145
#
148146
# For benchmarks where lower values are better (indicated by an asterisk, e.g., OmniDocBench1.5*), the normalization was calculated as $\text{Prior SOTA} / \text{Gemini 3 Pro Score}$. For all other benchmarks, it was calculated as $\text{Gemini 3 Pro Score} / \text{Prior SOTA}$. The values were then averaged within each category.

genai/code_execution/codeexecution_cropimage_with_txt_img.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
def generate_content() -> bool:
1717
# [START googlegenaisdk_codeexecution_cropimage_with_txt_img]
1818
import io
19+
import requests
1920
from PIL import Image
2021
from google import genai
2122
from google.genai import types
2223

23-
# Read a local image as input
24-
image_pil = Image.open("sample_images/instrument-img.jpg")
25-
byte_io = io.BytesIO()
26-
image_pil.save(byte_io, format="JPEG")
27-
image_bytes = byte_io.getvalue()
24+
# Download the input image
25+
image_path = "https://storage.googleapis.com/cloud-samples-data/generative-ai/image/chips.jpeg"
26+
image_bytes = requests.get(image_path).content
2827
image = types.Part.from_bytes(data=image_bytes, mime_type="image/jpeg")
2928

3029
client = genai.Client()
@@ -33,7 +32,7 @@ def generate_content() -> bool:
3332
model="gemini-3-flash-preview",
3433
contents=[
3534
image,
36-
"Zoom into the expression pedals and tell me how many pedals are there?",
35+
"Locate the ESMT chip. What are the numbers on the chip?",
3736
],
3837
config=types.GenerateContentConfig(tools=[types.Tool(code_execution=types.ToolCodeExecution)]),
3938
)
@@ -52,7 +51,7 @@ def generate_content() -> bool:
5251
print("####################### 3. Save Output #######################")
5352
image_data = part.as_image().image_bytes
5453
image = Image.open(io.BytesIO(image_data))
55-
output_location = "sample_images/instrument-img-output.jpg"
54+
output_location = "ESMT-chip-output.jpg"
5655
image.save(output_location)
5756
print(f"Output is saved to {output_location}")
5857
# Example response:
@@ -86,7 +85,7 @@ def generate_content() -> bool:
8685
# ####################### 2. Executing Python Code #######################
8786
# None
8887
# ####################### 3. Save Output #######################
89-
# Output is saved to sample_images/instrument-img-output.jpg
88+
# Output is saved to instrument-img-output.jpg
9089
# Based on the zoomed-in image, there are 4 expression pedals located in the center of the organ console, above the pedalboard.
9190
# [END googlegenaisdk_codeexecution_cropimage_with_txt_img]
9291
return True
-1.71 MB
Binary file not shown.
-9.37 KB
Binary file not shown.
-1.22 MB
Binary file not shown.
-140 KB
Binary file not shown.
-145 KB
Binary file not shown.
-48 KB
Binary file not shown.
-127 KB
Binary file not shown.

0 commit comments

Comments
 (0)