Skip to content

Commit 152209c

Browse files
matthew29tangcopybara-github
authored andcommitted
feat: Add ImageResizeMode for GenerateVideos
PiperOrigin-RevId: 869306823
1 parent ec8ca87 commit 152209c

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

google/genai/models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,6 +2115,9 @@ def _GenerateVideosConfig_to_mldev(
21152115
if getv(from_object, ['labels']) is not None:
21162116
raise ValueError('labels parameter is not supported in Gemini API.')
21172117

2118+
if getv(from_object, ['resize_mode']) is not None:
2119+
raise ValueError('resize_mode parameter is not supported in Gemini API.')
2120+
21182121
return to_object
21192122

21202123

@@ -2241,6 +2244,13 @@ def _GenerateVideosConfig_to_vertex(
22412244
if getv(from_object, ['labels']) is not None:
22422245
setv(parent_object, ['labels'], getv(from_object, ['labels']))
22432246

2247+
if getv(from_object, ['resize_mode']) is not None:
2248+
setv(
2249+
parent_object,
2250+
['parameters', 'resizeMode'],
2251+
getv(from_object, ['resize_mode']),
2252+
)
2253+
22442254
return to_object
22452255

22462256

google/genai/tests/models/test_generate_videos.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ def test_text_and_image_to_video_poll(client):
304304
image=GCS_IMAGE if client.vertexai else LOCAL_IMAGE,
305305
config=types.GenerateVideosConfig(
306306
output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None,
307+
resize_mode=(types.ImageResizeMode.CROP
308+
if client.vertexai else None),
307309
),
308310
)
309311
while not operation.done:

google/genai/types.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,17 @@ class VideoCompressionQuality(_common.CaseInSensitiveEnum):
10061006
with a larger file size."""
10071007

10081008

1009+
class ImageResizeMode(_common.CaseInSensitiveEnum):
1010+
"""Resize mode for the image input for video generation."""
1011+
1012+
CROP = 'CROP'
1013+
"""Crop the image to fit the correct aspect ratio (so we lose parts
1014+
of the image in the process)."""
1015+
PAD = 'PAD'
1016+
"""Pad the image to fit the correct aspect ratio (so we don't lose
1017+
any parts of the image in the process)."""
1018+
1019+
10091020
class TuningMethod(_common.CaseInSensitiveEnum):
10101021
"""Enum representing the tuning method."""
10111022

@@ -11159,6 +11170,10 @@ class GenerateVideosConfig(_common.BaseModel):
1115911170
default=None,
1116011171
description="""User specified labels to track billing usage.""",
1116111172
)
11173+
resize_mode: Optional[ImageResizeMode] = Field(
11174+
default=None,
11175+
description="""Resize mode of the image input for video generation.""",
11176+
)
1116211177

1116311178

1116411179
class GenerateVideosConfigDict(TypedDict, total=False):
@@ -11231,6 +11246,9 @@ class GenerateVideosConfigDict(TypedDict, total=False):
1123111246
labels: Optional[dict[str, str]]
1123211247
"""User specified labels to track billing usage."""
1123311248

11249+
resize_mode: Optional[ImageResizeMode]
11250+
"""Resize mode of the image input for video generation."""
11251+
1123411252

1123511253
GenerateVideosConfigOrDict = Union[
1123611254
GenerateVideosConfig, GenerateVideosConfigDict

0 commit comments

Comments
 (0)