VertexAIImageCaptioner
VertexAIImageCaptioner
Google Vertex AI의 imagetext 생성 모델로 이미지에 대한 캡션을 생성해 주는 컴포넌트예요. 업로드한 이미지에 부탁해서 그 이미지를 설명하는 텍스트를 받을 수 있어요.
필수 run 변수: image — 이미지를 담은 ByteStream 객체
출력 변수: captions — 모델이 생성한 문자열 리스트
API 레퍼런스: Google Vertex
GitHub 링크: https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/google_vertex
패키지 이름: google-vertex-haystack
출처: 문서
본문
파라미터 개요 (Parameters Overview)
VertexAIImageCaptioner는 인증에 Google Cloud Application Default Credentials (ADC)를 사용해요. ADC 설정 방법은 공식 문서를 참고하세요.
Google Vertex AI 엔드포인트를 사용하도록 승인된 프로젝트에 접근 권한이 있는 계정을 쓰는 게 중요하다는 점을 기억하세요.
프로젝트 ID는 GCP 리소스 매니저에서 찾거나, 터미널에서 gcloud projects list를 실행해 찾을 수 있어요. gcloud CLI에 대한 자세한 내용은 공식 문서를 참고하세요.
사용법 (Usage)
VertexAIImageCaptioner를 쓰려면 google-vertex-haystack 패키지를 설치해야 해요:
pip install google-vertex-haystack
단독으로 사용하기 (On its own)
기본 사용법:
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
캡션 언어와 결과 개수도 설정할 수 있어요:
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