Skip to main content

AI-powered alt text generation and labeling tools for markdown content

Project description

alt-text-llm

AI-powered alt text generation and labeling tools for markdown content. Originally developed for my website (repo).

Features

  • Intelligent scanning - Detects images/videos missing meaningful alt text (ignores empty alt="")
  • AI-powered generation - Uses LLM of your choice to create context-aware alt text suggestions
  • Interactive labeling - Manually review and edit LLM suggestions. Images display directly in your terminal
  • Automatic application - Apply approved captions back to your markdown files

A labeled example of the labeling pipeline: 1) view the context for an image, 2) view the image itself, while 3) editing the AI-generated label suggestion.

Installation

From PyPI

pip install alt-text-llm

Automated setup (includes system dependencies)

git clone https://github.com/alexander-turner/alt-text-llm.git
cd alt-text-llm
./setup.sh

Prerequisites

macOS:

brew install imagemagick ffmpeg imgcat
pip install llm

Linux:

sudo apt-get install imagemagick ffmpeg
pip install llm
# imgcat: curl -sL https://iterm2.com/utilities/imgcat -o ~/.local/bin/imgcat && chmod +x ~/.local/bin/imgcat

Usage

The tool provides four main commands: scan, generate, label, and apply.

1. Scan for missing alt text

Scan your markdown files to find images without meaningful alt text:

alt-text-llm scan --root /path/to/markdown/files

This creates asset_queue.json with all assets needing alt text.

2. Generate AI suggestions

Generate alt text suggestions using an LLM:

alt-text-llm generate \
  --root /path/to/markdown/files \
  --model gemini-2.5-flash \
  --suggestions-file suggested_alts.json

Available options:

  • --model (required) - LLM model to use (e.g., gemini-2.5-flash, gpt-4o-mini, claude-3-5-sonnet)
  • --max-chars - Maximum characters for alt text (default: 300)
  • --timeout - LLM timeout in seconds (default: 120)
  • --estimate-only - Only show cost estimate without generating
  • --process-existing - Also process assets that already have captions

Cost estimation:

alt-text-llm generate \
  --root /path/to/markdown/files \
  --model gemini-2.5-flash \
  --estimate-only

3. Label and approve suggestions

Interactively review and approve the AI-generated suggestions:

alt-text-llm label \
  --suggestions-file suggested_alts.json \
  --output asset_captions.json

Interactive commands:

  • Edit the suggested alt text (vim keybindings enabled)
  • Press Enter to accept the suggestion as-is
  • Submit undo or u to go back to the previous item
  • Images display in your terminal (requires imgcat)

4. Apply approved captions

Apply the approved captions back to your markdown files:

alt-text-llm apply \
  --captions-file asset_captions.json

Available options:

  • --captions-file - Path to the captions JSON file with final_alt populated (default: asset_captions.json)
  • --dry-run - Preview changes without modifying files

What it does:

  • Reads approved captions from the captions file
  • Locates corresponding images/videos in markdown files
  • Updates alt text for all supported formats:
    • Markdown images: ![alt](path)
    • HTML img tags: <img src="path" alt="alt">
    • Wikilink images: ![[path|alt]]
  • Preserves file formatting and handles special characters

Example workflow

# 1. Scan markdown files for missing alt text
alt-text-llm scan --root ./content

# 2. Estimate the cost
alt-text-llm generate \
  --root ./content \
  --model gemini-2.5-flash \
  --estimate-only

# 3. Generate suggestions (if cost is acceptable)
alt-text-llm generate \
  --root ./content \
  --model gemini-2.5-flash

# 4. Review and approve suggestions
alt-text-llm label

# 5. Apply approved captions to markdown files
alt-text-llm apply

Configuration

LLM Integration

This tool uses the llm CLI tool to generate alt text. This provides access to many different AI models including:

Setting up your model

For Gemini models (default):

llm install llm-gemini
llm keys set gemini # enter API key
llm -m gemini-2.5-flash "Hello, world!"

For other models:

  1. Install the appropriate llm plugin (e.g., llm install llm-openai)
  2. Configure your API key (e.g., llm keys set openai)
  3. Use the model name with --model flag (e.g., --model gpt-4o-mini)

See the llm documentation for setup instructions and the plugin directory for available models.

Output files

  • asset_queue.json - Queue of assets needing alt text (from scan)
  • suggested_alts.json - AI-generated suggestions (from generate)
  • asset_captions.json - Approved final captions (from label)

Project details


Download files

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

Source Distribution

alt_text_llm-1.1.tar.gz (44.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alt_text_llm-1.1-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

Details for the file alt_text_llm-1.1.tar.gz.

File metadata

  • Download URL: alt_text_llm-1.1.tar.gz
  • Upload date:
  • Size: 44.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for alt_text_llm-1.1.tar.gz
Algorithm Hash digest
SHA256 41866cfddf158ea5d5f8102a040821eb7f47ce523168894beea703b434ea65df
MD5 5bbf5840f88f2ea7c184ce81ba8d32cc
BLAKE2b-256 f94627d9397fdd4476df593546efcc3b50b9d7b678f149ab9f32beac1c727aa3

See more details on using hashes here.

File details

Details for the file alt_text_llm-1.1-py3-none-any.whl.

File metadata

  • Download URL: alt_text_llm-1.1-py3-none-any.whl
  • Upload date:
  • Size: 24.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for alt_text_llm-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2acfd019bc9682eb2434d2f2128a91ca69d2cc8fa718a2d6e7b4751b9b476503
MD5 ac8b93ba4f80b9319b80daf714a6aea8
BLAKE2b-256 599b76da2d50bc9dab7b38239361576e025fe9d0ed7df6230c6c6e30de69888a

See more details on using hashes here.

Supported by

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