Australia/Sydney
BlogAugust 2, 2023

Step by Step Demo of Image Captioning in AI

Fahd Mirza

This is a step by step guide to use AI to caption an image. This is a complete demo of installing and running locally salesforce blip image model to caption any image. 




Commands Used:


import os

import io

import IPython.display

from PIL import Image

import base64 

hf_api_key = '<Your Hugging Face API Token>'


!pip install transformers


from transformers import pipeline


get_completion = pipeline("image-to-text",model="Salesforce/blip-image-captioning-base")


def summarize(input):

    output = get_completion(input)

    return output[0]['generated_text']

image_url = "https://free-images.com/tn/9f10/delicate_arch_sunset_rock.jpg"

display(IPython.display.Image(url=image_url))

get_completion(image_url)

Share this post:
On this page

Let's Partner

If you are looking to build, deploy or scale AI solutions — whether you're just starting or facing production-scale challenges — let's chat.

Subscribe to Fahd's Newsletter

Weekly updates on AI, cloud engineering, and tech innovations