Skip to main content

Generate captions for images with Salesforce BLIP

Project description

blip-caption

PyPI Changelog Tests License

A CLI tool for generating captions for images using Salesforce BLIP.

Installation

Install this tool using pip or pipx:

pipx install blip-caption

The first time you use the tool it will download the model from the Hugging Face model hub.

The small model is 945MB. The large model is 1.8GB. The models will be downloaded and stored in ~/.cache/huggingface/hub/ the first time you use them.

Usage

To generate captions for an image using the small model, run:

blip-caption IMG_5825.jpeg

Example output:

a lizard is sitting on a branch in the woods

To use the larger model, add --large:

blip-caption IMG_5825.jpeg --large

Example output:

there is a chamelon sitting on a branch in the woods

Here's the image I used:

It is ineded a chameleon

If you pass multiple files the path to each file will be output before its caption:

blip-caption /tmp/photos/*.jpeg
/tmp/photos/IMG_2146.jpeg
a man holding a bowl of salad and laughing
/tmp/photos/IMG_0151.jpeg
a cat laying on a red blanket

JSON output

The --json flag changes the output to look like this:

blip-caption /tmp/photos/*.* --json
[{"path": "/tmp/photos/IMG_2146.jpeg", "caption": "a man holding a bowl of salad and laughing"},,
 {"path": "/tmp/photos/IMG_0151.jpeg", "caption": "a cat laying on a red blanket"},
 {"path": "/tmp/photos/IMG_3099.MOV", "error": "cannot identify image file '/tmp/photos/IMG_3099.MOV'"}]

Any errors are returned as a {"path": "...", "error": "error message"} object.

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd blip-caption
python3 -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

pytest

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blip-caption-0.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

blip_caption-0.1-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file blip-caption-0.1.tar.gz.

File metadata

  • Download URL: blip-caption-0.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for blip-caption-0.1.tar.gz
Algorithm Hash digest
SHA256 3c63350b0b595bcbe14cd879e0f1ca9ef38ba85d75ef903a9808275f6494248a
MD5 8091ef68fb526e9b0a424cb2e305c9e2
BLAKE2b-256 398d29fd9679683a1e974effa8db0fbe85798aaa88bb82cedfc4f387fc2f5aad

See more details on using hashes here.

File details

Details for the file blip_caption-0.1-py3-none-any.whl.

File metadata

  • Download URL: blip_caption-0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for blip_caption-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a45a04d1ea01ef636871ffe078f0d3102c7a689fedefdc72329d4bba8e183d1
MD5 6fd2bc4b92ad054b077302afac788e86
BLAKE2b-256 22a6ebf7a0b8022fe1b1fa40176498e16cd4c652521c7c199135e4638b9eff87

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page