Easy Image Captioning with Gemini 1.5 Pro n8n Workflow Template

n8n workflow template · 11 nodes · Google Gemini

Easy Image Captioning with Gemini 1.5 Pro is a free n8n workflow template that starts when you run it manually in the n8n editor and works with Google Gemini. It has 11 nodes, 3 of them AI nodes (Google Gemini Chat Model, Structured Output Parser and Basic LLM Chain). The notes inside the workflow say: “Additional, we'll use the Edit Image node to overlay the generated caption onto the image. This can be useful for publications or can be repurposed for copyrights and/or watermarks.” To run it, you add your own credentials for Google Gemini (PaLM) API.

At a glance

Trigger
Manual Trigger (When clicking ‘Test workflow’)
Nodes
11
Apps
Google Gemini
AI nodes
3
Credentials
1 type
Category
AI agents and LLM tools

Apps and integrations

  • Google Gemini

Node types used

  • Manual Trigger
  • Google Gemini Chat Model
  • Structured Output Parser
  • Edit Image
  • Code
  • Merge
  • HTTP Request
  • Basic LLM Chain

How it works

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Try it out!

This workflow takes an image and generates a caption for it using AI. The OpenAI node has been able to do this for a while but this workflow demonstrates how to achieve the same with other multimodal vision models such as Google's Gemini.

Additional, we'll use the Edit Image node to overlay the generated caption onto the image. This can be useful for publications or can be repurposed for copyrights and/or watermarks.

Need Help?

Join the Discord or ask in the Forum!

2. Using Vision Model to Generate Caption

Learn more about the Basic LLM Chain

n8n's basic LLM node supports multimodal input by allowing you to specify either a binary or an image url to send to a compatible LLM. This makes it easy to start utilising this powerful feature for visual classification or OCR tasks which have previously depended on more dedicated OCR models.

Here, we've simply passed our image binary as a "user message" option, asking the LLM to help us generate a caption title and text which is appropriate for the given subject. Once generated, we'll pass this text along with the image to combine them both.

3. Overlay Caption on Image

Read more about the Edit Image node

Finally, we’ll perform some basic calculations to place the generated caption onto the image. With n8n's user-friendly image editing features, this can be done entirely within the workflow!

The Code node tool is ideal for these types of calculations and is used here to position the caption at the bottom of the image. To create the overlay, the Edit Image node enables us to insert text onto the image, which we’ll use to add the generated caption.

FIG 1. Example input image with AI generated caption

Setup notes

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

1. Import an Image

Read more about the HTTP request node

For this demonstration, we'll grab an image off Pexels.com - a popular free stock photography site - by using the HTTP request node to download.

In your own workflows, this can be replaces by other triggers such as webhooks.

Nodes in this workflow

The 11 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:

  1. When clicking ‘Test workflow’ (Manual Trigger)
  2. Google Gemini Chat Model (Google Gemini Chat Model)
  3. Structured Output Parser (Structured Output Parser)
  4. Get Info (Edit Image)
  5. Resize For AI (Edit Image)
  6. Calculate Positioning (Code)
  7. Apply Caption to Image (Edit Image)
  8. Merge Image & Caption (Merge)
  9. Merge Caption & Positions (Merge)
  10. Get Image (HTTP Request)
  11. Image Captioning Agent (Basic LLM Chain)

Credentials you need

  • Google Gemini (PaLM) API – used by Google Gemini Chat Model

Configure your own credentials after importing. Create each credential in n8n, then select it in the node.

How to import into n8n

  1. Download the JSON file with the button above.
  2. In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
  3. Open each node that shows a warning and select or create its credential.
  4. Read the notes on the canvas, test the workflow with sample data, then activate it.

Do you need somewhere to run it? Read our guide to self-hosted n8n.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us