DocumentationAPI Reference📓 Tutorials🧑‍🍳 Cookbook🤝 Integrations💜 Discord🎨 Studio (Waitlist)
Documentation

VertexAIImageGenerator

This component enables image generation using Google Vertex AI generative model.

Mandatory run variables“prompt”: A string containing the prompt for the model
Output variables“images”: A list of ByteStream containing images generated by the model
API referenceGoogle Vertex
GitHub linkhttps://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/google_vertex

VertexAIImageGenerator supports the imagegeneration model.

Parameters Overview

VertexAIImageGenerator uses Google Cloud Application Default Credentials (ADCs) for authentication. For more information on how to set up ADCs, see the official documentation.

Keep in mind that it’s essential to use an account that has access to a project authorized to use Google Vertex AI endpoints.

You can find your project ID in the GCP resource manager or locally by running gcloud projects list in your terminal. For more info on the gcloud CLI, see its official documentation.

Usage

You need to install google-vertex-haystack package to use the VertexAIImageGenerator:

pip install google-vertex-haystack

On its own

Basic usage:

from pathlib import Path

from haystack_integrations.components.generators.google_vertex import VertexAIImageGenerator


generator = VertexAIImageGenerator()
result = generator.run(prompt="Generate an image of a cute cat")
result["images"][0].to_file(Path("my_image.png"))

You can also set other parameters like the number of images generated and the guidance scale to change the strength of the prompt.

Let’s also use a negative prompt to omit something from the image:

from pathlib import Path

from haystack_integrations.components.generators.google_vertex import VertexAIImageGenerator


generator = VertexAIImageGenerator(
    number_of_images=3,
    guidance_scale=12,
)

result = generator.run(
    prompt="Generate an image of a cute cat",
    negative_prompt="window, chair",
)

for i, image in enumerate(result["images"]):
    images.to_file(Path(f"image_{i}.png"))

Related Links

Check out the API reference in the GitHub repo or in our docs: