文档API 参考📓 教程🧑‍🍳 食谱🤝 集成💜 Discord🎨 Studio
文档

VertexAIImageCaptioner

VertexAIImageCaptioner enables text generation using Google Vertex AIimagetext generative model.

强制运行变量“image”: A ByteStream object storing an image
输出变量“captions”: A list of strings generated by the model
API 参考Google Vertex
GitHub 链接https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/google_vertex

参数概述

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

请记住,使用有权访问已授权使用 Google Vertex AI 端点的项目的帐户至关重要。

您可以在GCP 资源管理器中找到您的项目 ID,或者通过在终端中运行gcloud projects list 来在本地找到。有关 gcloud CLI 的更多信息,请参阅其官方文档

用法

您需要首先安装google-vertex-haystack 包以使用VertexAIImageCaptioner:

pip install google-vertex-haystack

单独使用

基本用法

import requests

from haystack.dataclasses.byte_stream import ByteStream
from haystack_integrations.components.generators.google_vertex import VertexAIImageCaptioner


captioner = VertexAIImageCaptioner()

image = ByteStream(data=requests.get("https://raw.githubusercontent.com/silvanocerza/robots/main/robot1.jpg").content)
result = captioner.run(image=image)

for caption in result["captions"]:
    print(caption)

>>> two gold robots are standing next to each other in the desert

You can also set the caption language and the number of results

import requests

from haystack.dataclasses.byte_stream import ByteStream
from haystack_integrations.components.generators.google_vertex import VertexAIImageCaptioner


captioner = VertexAIImageCaptioner(
	number_of_results=3, # Can't be greater than 3
	language="it",
)

image = ByteStream(data=requests.get("https://raw.githubusercontent.com/silvanocerza/robots/main/robot1.jpg").content)
result = captioner.run(image=image)

for caption in result["captions"]:
    print(caption)

>>> due robot dorati sono in piedi uno accanto all'altro in un deserto
>>> un c3p0 e un r2d2 stanno in piedi uno accanto all'altro in un deserto
>>> due robot dorati sono in piedi uno accanto all'altro

相关链接

请查看 GitHub 仓库或我们的文档中的 API 参考