This project demonstrates how to generate natural language captions for images using the BLIP (Bootstrapped Language Image Pretraining) model from Salesforce, powered by Hugging Face's transformers library.
Using a pretrained model, this script can take an image (local file or URL) and output a human-like caption describing the image content.
- 🖼️ Accepts both image URLs and local image files
- 🤖 Uses the powerful BLIP model (
Salesforce/blip-image-captioning-base) - ⚡ Fast and efficient inference with PyTorch
- 🔁 Easily extendable for batch processing, web apps, or AI-powered galleries
> python main.py
A bird is standing on a rock
A colorful bird is sitting on a branch- Python 3.7+
- PyTorch
- Hugging Face Transformers
- PIL (Pillow)
- Requests
Install dependencies using:
pip install -r requirements.txtgit clone https://github.com/HirthikBalaji/ImageCaptioning.git
cd ImageCaptioning
python main.pyMake sure to replace the sample image paths (download.jpeg, bird.jpeg) with valid file paths or image URLs.
-
Load BLIP Processor and Model The script loads a pretrained processor and model from Hugging Face.
-
Input Image (URL or Local) It supports both local images and remote images via URL.
-
Image Preprocessing & Caption Generation The image is preprocessed using the processor, passed to the model, and the generated output tokens are decoded into a human-readable sentence.
-
Display the Result The script prints a caption describing the image content.
- Integrate with a Flask or Streamlit app for a web UI
- Add batch processing for datasets
- Save and display images with their captions
- Use in accessibility tools or educational software
Pull requests are welcome! For major changes, please open an issue first to discuss what you'd like to change.
This project uses models and tools that are open source. Check individual dependencies for their respective licenses.