vertexaiimagecaptioner.mdx
 1  ---
 2  title: "VertexAIImageCaptioner"
 3  id: vertexaiimagecaptioner
 4  slug: "/vertexaiimagecaptioner"
 5  description: "`VertexAIImageCaptioner` enables text generation using Google Vertex AI `imagetext` generative model."
 6  ---
 7  
 8  # VertexAIImageCaptioner
 9  
10  `VertexAIImageCaptioner` enables text generation using Google Vertex AI `imagetext` generative model.
11  
12  <div className="key-value-table">
13  
14  |  |  |
15  | --- | --- |
16  | **Mandatory run variables** | `image`: A [`ByteStream`](../../concepts/data-classes.mdx#bytestream)  object storing an image               |
17  | **Output variables**        | `captions`: A list of strings generated by the model                                            |
18  | **API reference**           | [Google Vertex](/reference/integrations-google-vertex)                                                 |
19  | **GitHub link**             | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/google_vertex |
20  
21  </div>
22  
23  ### Parameters Overview
24  
25  `VertexAIImageCaptioner` uses Google Cloud Application Default Credentials (ADCs) for authentication. For more information on how to set up ADCs, see the [official documentation](https://cloud.google.com/docs/authentication/provide-credentials-adc).
26  
27  Keep in mind that it’s essential to use an account that has access to a project authorized to use Google Vertex AI endpoints.
28  
29  You can find your project ID in the [GCP resource manager](https://console.cloud.google.com/cloud-resource-manager) or locally by running `gcloud projects list` in your terminal. For more info on the gcloud CLI, see its [official documentation](https://cloud.google.com/cli).
30  
31  ## Usage
32  
33  You need to install `google-vertex-haystack` package to use the  `VertexAIImageCaptioner`:
34  
35  ```shell
36  pip install google-vertex-haystack
37  ```
38  
39  ### On its own
40  
41  Basic usage:
42  
43  ```python
44  import requests
45  
46  from haystack.dataclasses.byte_stream import ByteStream
47  from haystack_integrations.components.generators.google_vertex import VertexAIImageCaptioner
48  
49  captioner = VertexAIImageCaptioner()
50  
51  image = ByteStream(data=requests.get("https://raw.githubusercontent.com/silvanocerza/robots/main/robot1.jpg").content)
52  result = captioner.run(image=image)
53  
54  for caption in result["captions"]:
55      print(caption)
56  
57  >>> two gold robots are standing next to each other in the desert
58  ```
59  
60  You can also set the caption language and the number of results:
61  
62  ```python
63  import requests
64  
65  from haystack.dataclasses.byte_stream import ByteStream
66  from haystack_integrations.components.generators.google_vertex import VertexAIImageCaptioner
67  
68  captioner = VertexAIImageCaptioner(
69  	number_of_results=3, # Can't be greater than 3
70  	language="it",
71  )
72  
73  image = ByteStream(data=requests.get("https://raw.githubusercontent.com/silvanocerza/robots/main/robot1.jpg").content)
74  result = captioner.run(image=image)
75  
76  for caption in result["captions"]:
77      print(caption)
78  
79  >>> due robot dorati sono in piedi uno accanto all'altro in un deserto
80  >>> un c3p0 e un r2d2 stanno in piedi uno accanto all'altro in un deserto
81  >>> due robot dorati sono in piedi uno accanto all'altro
82  ```