Skip to content

Commit ff1820f

Browse files
katiemnholtskinner
andauthored
feat: Veo sample with image input (#13226)
* feat: Veo sample with image input * fix: linter errors * fix: extra lines * Update genai/video_generation/test_video_generation_examples.py * Update genai/video_generation/test_video_generation_examples.py --------- Co-authored-by: Holt Skinner <13262395+holtskinner@users.noreply.github.com>
1 parent c2c14fb commit ff1820f

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
google-genai==1.3.0
1+
google-genai==1.5.0

genai/video_generation/test_video_generation_examples.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
import pytest
2626

27+
import videogen_with_img
28+
2729
import videogen_with_txt
2830

2931

@@ -51,3 +53,8 @@ def output_gcs_uri() -> str:
5153
def test_videogen_with_txt(output_gcs_uri: str) -> None:
5254
response = videogen_with_txt.generate_videos(output_gcs_uri=output_gcs_uri)
5355
assert response
56+
57+
58+
def test_videogen_with_img(output_gcs_uri: str) -> None:
59+
response = videogen_with_img.generate_videos_from_image(output_gcs_uri=output_gcs_uri)
60+
assert response
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
def generate_videos_from_image(output_gcs_uri: str) -> str:
17+
# [START googlegenaisdk_videogen_with_img]
18+
import time
19+
from google import genai
20+
from google.genai.types import GenerateVideosConfig, Image
21+
22+
client = genai.Client()
23+
24+
# TODO(developer): Update and un-comment below line
25+
# output_gcs_uri = "gs://your-bucket/your-prefix"
26+
27+
operation = client.models.generate_videos(
28+
model="veo-2.0-generate-001",
29+
image=Image(
30+
gcs_uri="gs://cloud-samples-data/generative-ai/image/flowers.png",
31+
mime_type="image/png",
32+
),
33+
config=GenerateVideosConfig(
34+
aspect_ratio="16:9",
35+
output_gcs_uri=output_gcs_uri,
36+
),
37+
)
38+
39+
while not operation.done:
40+
time.sleep(15)
41+
operation = client.operations.get(operation)
42+
print(operation)
43+
44+
if operation.response:
45+
print(operation.result.generated_videos[0].video.uri)
46+
47+
# Example response:
48+
# gs://your-bucket/your-prefix
49+
# [END googlegenaisdk_videogen_with_img]
50+
return operation.result.generated_videos[0].video.uri
51+
52+
53+
if __name__ == "__main__":
54+
generate_videos_from_image(output_gcs_uri="gs://your-bucket/your-prefix")

0 commit comments

Comments
 (0)