Skip to content

Commit 2527a43

Browse files
matthew29tangcopybara-github
authored andcommitted
feat: Add ImageResizeMode for GenerateVideos
PiperOrigin-RevId: 869306823
1 parent 841bf22 commit 2527a43

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
@@ -2155,6 +2155,9 @@ def _GenerateVideosConfig_to_mldev(
21552155
if getv(from_object, ['labels']) is not None:
21562156
raise ValueError('labels parameter is not supported in Gemini API.')
21572157

2158+
if getv(from_object, ['resize_mode']) is not None:
2159+
raise ValueError('resize_mode parameter is not supported in Gemini API.')
2160+
21582161
return to_object
21592162

21602163

@@ -2281,6 +2284,13 @@ def _GenerateVideosConfig_to_vertex(
22812284
if getv(from_object, ['labels']) is not None:
22822285
setv(parent_object, ['labels'], getv(from_object, ['labels']))
22832286

2287+
if getv(from_object, ['resize_mode']) is not None:
2288+
setv(
2289+
parent_object,
2290+
['parameters', 'resizeMode'],
2291+
getv(from_object, ['resize_mode']),
2292+
)
2293+
22842294
return to_object
22852295

22862296

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

@@ -11181,6 +11192,10 @@ class GenerateVideosConfig(_common.BaseModel):
1118111192
default=None,
1118211193
description="""User specified labels to track billing usage.""",
1118311194
)
11195+
resize_mode: Optional[ImageResizeMode] = Field(
11196+
default=None,
11197+
description="""Resize mode of the image input for video generation.""",
11198+
)
1118411199

1118511200

1118611201
class GenerateVideosConfigDict(TypedDict, total=False):
@@ -11253,6 +11268,9 @@ class GenerateVideosConfigDict(TypedDict, total=False):
1125311268
labels: Optional[dict[str, str]]
1125411269
"""User specified labels to track billing usage."""
1125511270

11271+
resize_mode: Optional[ImageResizeMode]
11272+
"""Resize mode of the image input for video generation."""
11273+
1125611274

1125711275
GenerateVideosConfigOrDict = Union[
1125811276
GenerateVideosConfig, GenerateVideosConfigDict

0 commit comments

Comments
 (0)