Skip to content

Commit 9ffebc8

Browse files
committed
Addressed review comments
1 parent f327ada commit 9ffebc8

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

genai/bounding_box/boundingbox_with_txt_img.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@ def generate_content() -> str:
3030
from pydantic import BaseModel
3131

3232
class BoundingBox(BaseModel):
33+
"""
34+
Represents a bounding box with its 2D coordinates and associated label.
35+
36+
Attributes:
37+
box_2d (list[int]): A list of integers representing the 2D coordinates of the bounding box,
38+
typically in the format [x_min, y_min, x_max, y_max].
39+
label (str): Optional: A string representing the label or class associated with the object within the bounding box.
40+
"""
41+
3342
box_2d: list[int]
34-
label: str
43+
label: str | None = None
3544

3645
def plot_bounding_boxes(image_uri: str, bounding_boxes: list[BoundingBox]) -> None:
3746
"""
@@ -56,7 +65,6 @@ def plot_bounding_boxes(image_uri: str, bounding_boxes: list[BoundingBox]) -> No
5665
abs_y2 = int(y2 / 1000 * height)
5766
abs_x2 = int(x2 / 1000 * width)
5867

59-
# Use a single color selection:
6068
color = colors[i % len(colors)]
6169

6270
draw.rectangle(
@@ -70,8 +78,12 @@ def plot_bounding_boxes(image_uri: str, bounding_boxes: list[BoundingBox]) -> No
7078
client = genai.Client(http_options=HttpOptions(api_version="v1"))
7179

7280
config = GenerateContentConfig(
73-
system_instruction="""Return bounding boxes as an array with labels. Never return masks. Limit to 25 objects.
74-
If an object is present multiple times, give each object a unique label according to its distinct characteristics (colors, size, position, etc..).""",
81+
system_instruction="""
82+
Return bounding boxes as an array with labels.
83+
Never return masks. Limit to 25 objects.
84+
If an object is present multiple times, give each object a unique label
85+
according to its distinct characteristics (colors, size, position, etc..).
86+
""",
7587
temperature=0.5,
7688
safety_settings=[
7789
SafetySetting(

0 commit comments

Comments
 (0)