Hello, I am confused about file, uri and what else. I just want to feed the model with the first frame and the last frame. Do I need to manually upload the images to the cloud firstly? Thanks,
Lei
Here is my code:
import time
from google import genai
from google.genai.types import GenerateVideosConfig, Image
client = genai.Client(api_key=“xxx”)
prompt = “”“Based on the first and last keyframes, Generate a high-quality, photorealistic video of a woman using that product to cleanse her face in a luxurious bathroom setting. Ensure the generated video is a new, creative scene based on this product.”“”
# Load images using the correct method
first_frame = client.files.upload(file=“/Users/path/1.png”)
last_frame = client.files.upload(file=“/Users/path/video_generation_project/2.png”)
print(first_frame.uri)
operation = client.models.generate_videos(
model=“veo-3.1-generate-001”,
prompt=“a hand reaches in and places a glass of milk next to the plate of cookies”,
image=Image(
uri=first_frame.uri,
mime_type=“image/png”,
),
config=GenerateVideosConfig(
aspect_ratio=“16:9”,
last_frame=Image(
uri=last_frame.uri,
mime_type=“image/png”,
),
),
)
# Poll the operation status until the video is ready.
while not operation.done:
print(“Waiting for video generation to complete…”)
time.sleep(10)
operation = client.operations.get(operation)
# Download the generated video.
generated_video = operation.response.generated_videos[0]
client.files.download(file=generated_video.video)
generated_video.video.save(“my_video.mp4”)
print(“Generated video saved to my_video.mp4”)