Skip to content

96ibman/image_captioning_gradio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Describe Any Image Using AI

🚀 Try it live on Hugging Face Spaces

This is a simple Gradio-powered app that uses a pre-trained vision-language model to describe the content of images. Upload any image and see how AI interprets the scene.


What is Image Captioning?

Image captioning is a task where a deep learning model generates a textual description of an image. It combines computer vision and natural language processing in one pipeline.


Packages

import gradio as gr
from transformers import BlipProcessor, BlipForConditionalGeneration
from PIL import Image

🤗 BlipProcessor

I used BlipProcessor which is a class from 🤗 transformers library. It is designed for Bootstrapping Language-Image Pretraining (BLIP) models. It basically combines image and text preprocessing

processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")

generate_caption Function

def generate_caption(image):
    if image is None:
        return "Please upload an image to generate a caption."
    inputs = processor(images=image, return_tensors="pt")
    out = model.generate(**inputs)
    caption = processor.decode(out[0], skip_special_tokens=True)
    return caption

Gradio Interface

iface = gr.Interface(
    fn=generate_caption, 
    inputs=gr.Image(type="pil", label="Upload Image"), 
    outputs="text", 
    live=True,
    title="Image Captioning App",
    description="Upload an image and get a description of what the image contains.",
    allow_flagging="never"
)

iface.launch()

Run Locally

git clone https://github.com/96ibman/image_captioning_gradio.git
cd image_captioning_gradio
python -m venv venv
venv/Scripts/activate
pip install -r requirements.txt
python app.py

About me

Website

About

Image Captioning Gradio App Deployed on Hugging Face Spaces

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages