Skip to content

Commit 317d2af

Browse files
matthew29tangcopybara-github
authored andcommitted
feat: Add ImageResizeMode for GenerateVideos
PiperOrigin-RevId: 905140128
1 parent 88d9b4a commit 317d2af

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
@@ -2163,6 +2163,9 @@ def _GenerateVideosConfig_to_mldev(
21632163
parent_object, ['webhookConfig'], getv(from_object, ['webhook_config'])
21642164
)
21652165

2166+
if getv(from_object, ['resize_mode']) is not None:
2167+
raise ValueError('resize_mode parameter is not supported in Gemini API.')
2168+
21662169
return to_object
21672170

21682171

@@ -2295,6 +2298,13 @@ def _GenerateVideosConfig_to_vertex(
22952298
' Platform.'
22962299
)
22972300

2301+
if getv(from_object, ['resize_mode']) is not None:
2302+
setv(
2303+
parent_object,
2304+
['parameters', 'resizeMode'],
2305+
getv(from_object, ['resize_mode']),
2306+
)
2307+
22982308
return to_object
22992309

23002310

google/genai/tests/models/test_generate_videos.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ def test_text_and_image_to_video_poll(client):
335335
image=GCS_IMAGE if client.vertexai else LOCAL_IMAGE,
336336
config=types.GenerateVideosConfig(
337337
output_gcs_uri=OUTPUT_GCS_URI if client.vertexai else None,
338+
resize_mode=(types.ImageResizeMode.CROP
339+
if client.vertexai else None),
338340
),
339341
)
340342
while not operation.done:

google/genai/types.py

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

10071007

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

@@ -11233,6 +11244,10 @@ class GenerateVideosConfig(_common.BaseModel):
1123311244
description="""Webhook configuration for receiving notifications when the
1123411245
video generation operation completes.""",
1123511246
)
11247+
resize_mode: Optional[ImageResizeMode] = Field(
11248+
default=None,
11249+
description="""Resize mode of the image input for video generation.""",
11250+
)
1123611251

1123711252

1123811253
class GenerateVideosConfigDict(TypedDict, total=False):
@@ -11309,6 +11324,9 @@ class GenerateVideosConfigDict(TypedDict, total=False):
1130911324
"""Webhook configuration for receiving notifications when the
1131011325
video generation operation completes."""
1131111326

11327+
resize_mode: Optional[ImageResizeMode]
11328+
"""Resize mode of the image input for video generation."""
11329+
1131211330

1131311331
GenerateVideosConfigOrDict = Union[
1131411332
GenerateVideosConfig, GenerateVideosConfigDict

0 commit comments

Comments
 (0)