Skip to content

AI Gateway: How to for generating animated videos from static images using Vertex AI #3800

@tomek-labuk

Description

@tomek-labuk

How to for generating animated videos from static images using Vertex AI's Veo model through Kong AI Gateway. Combine image data with a text prompt to create the animation.

Python script:

from google import genai

client = genai.Client(
    vertexai=True,
    project="your-project-id",
    location="us-central1",
    http_options={
        "api_version": "v1",
        "base_url": "http://localhost:8000/gemini"
    }
)

with open("input_image.jpg", "rb") as f:
    image_data = f.read()

response = client.models.generate_content(
    model="veo-001",
    contents=[
        {
            "inline_data": {
                "mime_type": "image/jpeg",
                "data": image_data
            }
        },
        "Animate this image: make the water ripple and clouds move"
    ]
)

# Extract and save video
for part in response.candidates[0].content.parts:
    if part.inline_data:
        with open("animated_video.mp4", "wb") as f:
            f.write(part.inline_data.data)
        print("Animated video saved!")

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions