Google Imagen
Imagen on Vertex AI brings Google's state of the art image generative AI capabilities to application developers. With Imagen on Vertex AI, application developers can build next-generation AI products that transform their user's imagination into high quality visual assets using AI generation, in seconds.
With Imagen on Langchain , You can do the following tasks
- VertexAIImageGeneratorChat : Generate novel images using only a text prompt (text-to-image AI generation).
- VertexAIImageEditorChat : Edit an entire uploaded or generated image with a text prompt.
- VertexAIImageCaptioning : Get text descriptions of images with visual captioning.
- VertexAIVisualQnAChat : Get answers to a question about an image with Visual Question Answering (VQA).
- NOTE : Currently we support only only single-turn chat for Visual QnA (VQA)
Image Generationโ
Generate novel images using only a text prompt (text-to-image AI generation)
from langchain_core.messages import AIMessage, HumanMessage
from langchain_google_vertexai.vision_models import VertexAIImageGeneratorChat
API Reference:AIMessage | HumanMessage
# Create Image Gentation model Object
generator = VertexAIImageGeneratorChat()
messages = [HumanMessage(content=["a cat at the beach"])]
response = generator.invoke(messages)
# To view the generated Image
generated_image = response.content[0]
import base64
import io
from PIL import Image
# Parse response object to get base64 string for image
img_base64 = generated_image["image_url"]["url"].split(",")[-1]
# Convert base64 string to Image
img = Image.open(io.BytesIO(base64.decodebytes(bytes(img_base64, "utf-8"))))
# view Image
img