blip-caption


Nameblip-caption JSON
Version 0.1 PyPI version JSON
download
home_page
SummaryGenerate captions for images with Salesforce BLIP
upload_time2023-09-10 06:21:19
maintainer
docs_urlNone
authorSimon Willison
requires_python
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # blip-caption

[![PyPI](https://img.shields.io/pypi/v/blip-caption.svg)](https://pypi.org/project/blip-caption/)
[![Changelog](https://img.shields.io/github/v/release/simonw/blip-caption?include_prereleases&label=changelog)](https://github.com/simonw/blip-caption/releases)
[![Tests](https://github.com/simonw/blip-caption/workflows/Test/badge.svg)](https://github.com/simonw/blip-caption/actions?query=workflow%3ATest)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/blip-caption/blob/main/LICENSE)

A CLI tool for generating captions for images using [Salesforce BLIP](https://huggingface.co/Salesforce/blip-image-captioning-base).

## Installation

Install this tool using `pip` or `pipx`:
```bash
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:

```bash
blip-caption IMG_5825.jpeg
```
Example output:
```
a lizard is sitting on a branch in the woods
```
To use the larger model, add `--large`:
```bash
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](https://static.simonwillison.net/static/2023/IMG_5924.jpeg):

![It is ineded a chameleon](https://static.simonwillison.net/static/2023/IMG_5924.jpeg)

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

```bash
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
```
```bash
[{"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:
```bash
cd blip-caption
python3 -m venv venv
source venv/bin/activate
```
Now install the dependencies and test dependencies:
```bash
pip install -e '.[test]'
```
To run the tests:
```bash
pytest
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "blip-caption",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Simon Willison",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/39/8d/29fd9679683a1e974effa8db0fbe85798aaa88bb82cedfc4f387fc2f5aad/blip-caption-0.1.tar.gz",
    "platform": null,
    "description": "# blip-caption\n\n[![PyPI](https://img.shields.io/pypi/v/blip-caption.svg)](https://pypi.org/project/blip-caption/)\n[![Changelog](https://img.shields.io/github/v/release/simonw/blip-caption?include_prereleases&label=changelog)](https://github.com/simonw/blip-caption/releases)\n[![Tests](https://github.com/simonw/blip-caption/workflows/Test/badge.svg)](https://github.com/simonw/blip-caption/actions?query=workflow%3ATest)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/blip-caption/blob/main/LICENSE)\n\nA CLI tool for generating captions for images using [Salesforce BLIP](https://huggingface.co/Salesforce/blip-image-captioning-base).\n\n## Installation\n\nInstall this tool using `pip` or `pipx`:\n```bash\npipx install blip-caption\n```\nThe first time you use the tool it will download the model from the Hugging Face model hub.\n\nThe 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.\n\n## Usage\n\nTo generate captions for an image using the small model, run:\n\n```bash\nblip-caption IMG_5825.jpeg\n```\nExample output:\n```\na lizard is sitting on a branch in the woods\n```\nTo use the larger model, add `--large`:\n```bash\nblip-caption IMG_5825.jpeg --large\n```\nExample output:\n```\nthere is a chamelon sitting on a branch in the woods\n```\nHere's [the image I used](https://static.simonwillison.net/static/2023/IMG_5924.jpeg):\n\n![It is ineded a chameleon](https://static.simonwillison.net/static/2023/IMG_5924.jpeg)\n\nIf you pass multiple files the path to each file will be output before its caption:\n\n```bash\nblip-caption /tmp/photos/*.jpeg\n/tmp/photos/IMG_2146.jpeg\na man holding a bowl of salad and laughing\n/tmp/photos/IMG_0151.jpeg\na cat laying on a red blanket\n```\n\n## JSON output\n\nThe `--json` flag changes the output to look like this:\n\n```\nblip-caption /tmp/photos/*.* --json\n```\n```bash\n[{\"path\": \"/tmp/photos/IMG_2146.jpeg\", \"caption\": \"a man holding a bowl of salad and laughing\"},,\n {\"path\": \"/tmp/photos/IMG_0151.jpeg\", \"caption\": \"a cat laying on a red blanket\"},\n {\"path\": \"/tmp/photos/IMG_3099.MOV\", \"error\": \"cannot identify image file '/tmp/photos/IMG_3099.MOV'\"}]\n```\nAny errors are returned as a `{\"path\": \"...\", \"error\": \"error message\"}` object.\n\n\n## Development\n\nTo set up this plugin locally, first checkout the code. Then create a new virtual environment:\n```bash\ncd blip-caption\npython3 -m venv venv\nsource venv/bin/activate\n```\nNow install the dependencies and test dependencies:\n```bash\npip install -e '.[test]'\n```\nTo run the tests:\n```bash\npytest\n```\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Generate captions for images with Salesforce BLIP",
    "version": "0.1",
    "project_urls": {
        "Changelog": "https://github.com/simonw/blip-caption/releases",
        "Homepage": "https://github.com/simonw/blip-caption",
        "Issues": "https://github.com/simonw/blip-caption/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "22a6ebf7a0b8022fe1b1fa40176498e16cd4c652521c7c199135e4638b9eff87",
                "md5": "6fd2bc4b92ad054b077302afac788e86",
                "sha256": "7a45a04d1ea01ef636871ffe078f0d3102c7a689fedefdc72329d4bba8e183d1"
            },
            "downloads": -1,
            "filename": "blip_caption-0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6fd2bc4b92ad054b077302afac788e86",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 3301,
            "upload_time": "2023-09-10T06:21:17",
            "upload_time_iso_8601": "2023-09-10T06:21:17.450466Z",
            "url": "https://files.pythonhosted.org/packages/22/a6/ebf7a0b8022fe1b1fa40176498e16cd4c652521c7c199135e4638b9eff87/blip_caption-0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "398d29fd9679683a1e974effa8db0fbe85798aaa88bb82cedfc4f387fc2f5aad",
                "md5": "8091ef68fb526e9b0a424cb2e305c9e2",
                "sha256": "3c63350b0b595bcbe14cd879e0f1ca9ef38ba85d75ef903a9808275f6494248a"
            },
            "downloads": -1,
            "filename": "blip-caption-0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8091ef68fb526e9b0a424cb2e305c9e2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3780,
            "upload_time": "2023-09-10T06:21:19",
            "upload_time_iso_8601": "2023-09-10T06:21:19.178508Z",
            "url": "https://files.pythonhosted.org/packages/39/8d/29fd9679683a1e974effa8db0fbe85798aaa88bb82cedfc4f387fc2f5aad/blip-caption-0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-10 06:21:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "simonw",
    "github_project": "blip-caption",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "blip-caption"
}
        
Elapsed time: 0.42875s