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)
No comments:
Post a Comment