alt-text-llm 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- alt_text_llm-1.0.1/LICENSE +21 -0
- alt_text_llm-1.0.1/MANIFEST.in +1 -0
- alt_text_llm-1.0.1/PKG-INFO +182 -0
- alt_text_llm-1.0.1/README.md +157 -0
- alt_text_llm-1.0.1/alt_text_llm/__init__.py +14 -0
- alt_text_llm-1.0.1/alt_text_llm/apply.py +510 -0
- alt_text_llm-1.0.1/alt_text_llm/generate.py +208 -0
- alt_text_llm-1.0.1/alt_text_llm/label.py +348 -0
- alt_text_llm-1.0.1/alt_text_llm/main.py +255 -0
- alt_text_llm-1.0.1/alt_text_llm/scan.py +222 -0
- alt_text_llm-1.0.1/alt_text_llm/utils.py +516 -0
- alt_text_llm-1.0.1/alt_text_llm.egg-info/PKG-INFO +182 -0
- alt_text_llm-1.0.1/alt_text_llm.egg-info/SOURCES.txt +23 -0
- alt_text_llm-1.0.1/alt_text_llm.egg-info/dependency_links.txt +1 -0
- alt_text_llm-1.0.1/alt_text_llm.egg-info/entry_points.txt +2 -0
- alt_text_llm-1.0.1/alt_text_llm.egg-info/requires.txt +13 -0
- alt_text_llm-1.0.1/alt_text_llm.egg-info/top_level.txt +1 -0
- alt_text_llm-1.0.1/pyproject.toml +40 -0
- alt_text_llm-1.0.1/setup.cfg +4 -0
- alt_text_llm-1.0.1/tests/test_apply.py +940 -0
- alt_text_llm-1.0.1/tests/test_generate.py +261 -0
- alt_text_llm-1.0.1/tests/test_helpers.py +89 -0
- alt_text_llm-1.0.1/tests/test_label.py +490 -0
- alt_text_llm-1.0.1/tests/test_scan.py +201 -0
- alt_text_llm-1.0.1/tests/test_utils.py +1457 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alexander Turner (TurnTrout)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include README.md LICENSE
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: alt-text-llm
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: AI-powered alt text generation and labeling tools for markdown content
|
|
5
|
+
Author: TurnTrout
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/alexander-turner/alt-text-llm
|
|
8
|
+
Keywords: alt-text,accessibility,markdown,llm,ai
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: gitpython
|
|
13
|
+
Requires-Dist: requests
|
|
14
|
+
Requires-Dist: ruamel.yaml
|
|
15
|
+
Requires-Dist: markdown-it-py
|
|
16
|
+
Requires-Dist: rich
|
|
17
|
+
Requires-Dist: tqdm
|
|
18
|
+
Requires-Dist: prompt_toolkit
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest; extra == "dev"
|
|
21
|
+
Requires-Dist: mypy; extra == "dev"
|
|
22
|
+
Requires-Dist: types-requests; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# alt-text-llm
|
|
27
|
+
|
|
28
|
+
AI-powered alt text generation and labeling tools for markdown content. Originally developed for [my website](https://turntrout.com/design) ([repo](https://github.com/alexander-turner/TurnTrout.com)).
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- **Intelligent scanning** - Detects images/videos missing meaningful alt text (ignores empty `alt=""`)
|
|
33
|
+
- **AI-powered generation** - Uses LLM of your choice to create context-aware alt text suggestions
|
|
34
|
+
- **Interactive labeling** - Manually review and edit LLM suggestions. Images display directly in your terminal
|
|
35
|
+
- **Automatic application** - Apply approved captions back to your markdown files
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
### From PyPI
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install alt-text-llm
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Automated setup (includes system dependencies)
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
git clone https://github.com/alexander-turner/alt-text-llm.git
|
|
49
|
+
cd alt-text-llm
|
|
50
|
+
./setup.sh
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Prerequisites
|
|
54
|
+
|
|
55
|
+
**macOS:**
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
brew install imagemagick ffmpeg imgcat
|
|
59
|
+
pip install llm
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Linux:**
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
sudo apt-get install imagemagick ffmpeg
|
|
66
|
+
pip install llm
|
|
67
|
+
# imgcat: curl -sL https://iterm2.com/utilities/imgcat -o ~/.local/bin/imgcat && chmod +x ~/.local/bin/imgcat
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
The tool provides three main commands: `scan`, `generate`, and `label`.
|
|
73
|
+
|
|
74
|
+
### 1. Scan for missing alt text
|
|
75
|
+
|
|
76
|
+
Scan your markdown files to find images without meaningful alt text:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
alt-text-llm scan --root /path/to/markdown/files
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
This creates `asset_queue.json` with all assets needing alt text.
|
|
83
|
+
|
|
84
|
+
### 2. Generate AI suggestions
|
|
85
|
+
|
|
86
|
+
Generate alt text suggestions using an LLM:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
alt-text-llm generate \
|
|
90
|
+
--root /path/to/markdown/files \
|
|
91
|
+
--model gemini-2.5-flash \
|
|
92
|
+
--suggestions-file suggested_alts.json
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Available options:**
|
|
96
|
+
|
|
97
|
+
- `--model` (required) - LLM model to use (e.g., `gemini-2.5-flash`, `gpt-4o-mini`, `claude-3-5-sonnet`)
|
|
98
|
+
- `--max-chars` - Maximum characters for alt text (default: 300)
|
|
99
|
+
- `--timeout` - LLM timeout in seconds (default: 120)
|
|
100
|
+
- `--estimate-only` - Only show cost estimate without generating
|
|
101
|
+
- `--process-existing` - Also process assets that already have captions
|
|
102
|
+
|
|
103
|
+
**Cost estimation:**
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
alt-text-llm generate \
|
|
107
|
+
--root /path/to/markdown/files \
|
|
108
|
+
--model gemini-2.5-flash \
|
|
109
|
+
--estimate-only
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 3. Label and approve suggestions
|
|
113
|
+
|
|
114
|
+
Interactively review and approve the AI-generated suggestions:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
alt-text-llm label \
|
|
118
|
+
--suggestions-file suggested_alts.json \
|
|
119
|
+
--output asset_captions.json
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Interactive commands:**
|
|
123
|
+
|
|
124
|
+
- Edit the suggested alt text (vim keybindings enabled)
|
|
125
|
+
- Press Enter to accept the suggestion as-is
|
|
126
|
+
- Submit `undo` or `u` to go back to the previous item
|
|
127
|
+
- Images display in your terminal (requires `imgcat`)
|
|
128
|
+
|
|
129
|
+
## Example workflow
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# 1. Scan markdown files for missing alt text
|
|
133
|
+
alt-text-llm scan --root ./content
|
|
134
|
+
|
|
135
|
+
# 2. Estimate the cost
|
|
136
|
+
alt-text-llm generate \
|
|
137
|
+
--root ./content \
|
|
138
|
+
--model gemini-2.5-flash \
|
|
139
|
+
--estimate-only
|
|
140
|
+
|
|
141
|
+
# 3. Generate suggestions (if cost is acceptable)
|
|
142
|
+
alt-text-llm generate \
|
|
143
|
+
--root ./content \
|
|
144
|
+
--model gemini-2.5-flash
|
|
145
|
+
|
|
146
|
+
# 4. Review and approve suggestions
|
|
147
|
+
alt-text-llm label
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Configuration
|
|
151
|
+
|
|
152
|
+
### LLM Integration
|
|
153
|
+
|
|
154
|
+
This tool uses the [`llm` CLI tool](https://llm.datasette.io/) to generate alt text. This provides access to many different AI models including:
|
|
155
|
+
|
|
156
|
+
- **Gemini** (Google) via the [llm-gemini plugin](https://github.com/simonw/llm-gemini)
|
|
157
|
+
- **Claude** (Anthropic) via the [llm-claude-3 plugin](https://github.com/tomviner/llm-claude-3)
|
|
158
|
+
- And [many more via plugins](https://llm.datasette.io/en/stable/plugins/directory.html)
|
|
159
|
+
|
|
160
|
+
### Setting up your model
|
|
161
|
+
|
|
162
|
+
**For Gemini models (default):**
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
llm install llm-gemini
|
|
166
|
+
llm keys set gemini # enter API key
|
|
167
|
+
llm -m gemini-2.5-flash "Hello, world!"
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**For other models:**
|
|
171
|
+
|
|
172
|
+
1. Install the appropriate llm plugin (e.g., `llm install llm-openai`)
|
|
173
|
+
2. Configure your API key (e.g., `llm keys set openai`)
|
|
174
|
+
3. Use the model name with `--model` flag (e.g., `--model gpt-4o-mini`)
|
|
175
|
+
|
|
176
|
+
See the [llm documentation](https://llm.datasette.io/en/stable/setup.html) for setup instructions and the [plugin directory](https://llm.datasette.io/en/stable/plugins/directory.html) for available models.
|
|
177
|
+
|
|
178
|
+
## Output files
|
|
179
|
+
|
|
180
|
+
- `asset_queue.json` - Queue of assets needing alt text (from `scan`)
|
|
181
|
+
- `suggested_alts.json` - AI-generated suggestions (from `generate`)
|
|
182
|
+
- `asset_captions.json` - Approved final captions (from `label`)
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# alt-text-llm
|
|
2
|
+
|
|
3
|
+
AI-powered alt text generation and labeling tools for markdown content. Originally developed for [my website](https://turntrout.com/design) ([repo](https://github.com/alexander-turner/TurnTrout.com)).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Intelligent scanning** - Detects images/videos missing meaningful alt text (ignores empty `alt=""`)
|
|
8
|
+
- **AI-powered generation** - Uses LLM of your choice to create context-aware alt text suggestions
|
|
9
|
+
- **Interactive labeling** - Manually review and edit LLM suggestions. Images display directly in your terminal
|
|
10
|
+
- **Automatic application** - Apply approved captions back to your markdown files
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
### From PyPI
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install alt-text-llm
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Automated setup (includes system dependencies)
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
git clone https://github.com/alexander-turner/alt-text-llm.git
|
|
24
|
+
cd alt-text-llm
|
|
25
|
+
./setup.sh
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Prerequisites
|
|
29
|
+
|
|
30
|
+
**macOS:**
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
brew install imagemagick ffmpeg imgcat
|
|
34
|
+
pip install llm
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Linux:**
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
sudo apt-get install imagemagick ffmpeg
|
|
41
|
+
pip install llm
|
|
42
|
+
# imgcat: curl -sL https://iterm2.com/utilities/imgcat -o ~/.local/bin/imgcat && chmod +x ~/.local/bin/imgcat
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
The tool provides three main commands: `scan`, `generate`, and `label`.
|
|
48
|
+
|
|
49
|
+
### 1. Scan for missing alt text
|
|
50
|
+
|
|
51
|
+
Scan your markdown files to find images without meaningful alt text:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
alt-text-llm scan --root /path/to/markdown/files
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
This creates `asset_queue.json` with all assets needing alt text.
|
|
58
|
+
|
|
59
|
+
### 2. Generate AI suggestions
|
|
60
|
+
|
|
61
|
+
Generate alt text suggestions using an LLM:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
alt-text-llm generate \
|
|
65
|
+
--root /path/to/markdown/files \
|
|
66
|
+
--model gemini-2.5-flash \
|
|
67
|
+
--suggestions-file suggested_alts.json
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Available options:**
|
|
71
|
+
|
|
72
|
+
- `--model` (required) - LLM model to use (e.g., `gemini-2.5-flash`, `gpt-4o-mini`, `claude-3-5-sonnet`)
|
|
73
|
+
- `--max-chars` - Maximum characters for alt text (default: 300)
|
|
74
|
+
- `--timeout` - LLM timeout in seconds (default: 120)
|
|
75
|
+
- `--estimate-only` - Only show cost estimate without generating
|
|
76
|
+
- `--process-existing` - Also process assets that already have captions
|
|
77
|
+
|
|
78
|
+
**Cost estimation:**
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
alt-text-llm generate \
|
|
82
|
+
--root /path/to/markdown/files \
|
|
83
|
+
--model gemini-2.5-flash \
|
|
84
|
+
--estimate-only
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 3. Label and approve suggestions
|
|
88
|
+
|
|
89
|
+
Interactively review and approve the AI-generated suggestions:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
alt-text-llm label \
|
|
93
|
+
--suggestions-file suggested_alts.json \
|
|
94
|
+
--output asset_captions.json
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Interactive commands:**
|
|
98
|
+
|
|
99
|
+
- Edit the suggested alt text (vim keybindings enabled)
|
|
100
|
+
- Press Enter to accept the suggestion as-is
|
|
101
|
+
- Submit `undo` or `u` to go back to the previous item
|
|
102
|
+
- Images display in your terminal (requires `imgcat`)
|
|
103
|
+
|
|
104
|
+
## Example workflow
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# 1. Scan markdown files for missing alt text
|
|
108
|
+
alt-text-llm scan --root ./content
|
|
109
|
+
|
|
110
|
+
# 2. Estimate the cost
|
|
111
|
+
alt-text-llm generate \
|
|
112
|
+
--root ./content \
|
|
113
|
+
--model gemini-2.5-flash \
|
|
114
|
+
--estimate-only
|
|
115
|
+
|
|
116
|
+
# 3. Generate suggestions (if cost is acceptable)
|
|
117
|
+
alt-text-llm generate \
|
|
118
|
+
--root ./content \
|
|
119
|
+
--model gemini-2.5-flash
|
|
120
|
+
|
|
121
|
+
# 4. Review and approve suggestions
|
|
122
|
+
alt-text-llm label
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Configuration
|
|
126
|
+
|
|
127
|
+
### LLM Integration
|
|
128
|
+
|
|
129
|
+
This tool uses the [`llm` CLI tool](https://llm.datasette.io/) to generate alt text. This provides access to many different AI models including:
|
|
130
|
+
|
|
131
|
+
- **Gemini** (Google) via the [llm-gemini plugin](https://github.com/simonw/llm-gemini)
|
|
132
|
+
- **Claude** (Anthropic) via the [llm-claude-3 plugin](https://github.com/tomviner/llm-claude-3)
|
|
133
|
+
- And [many more via plugins](https://llm.datasette.io/en/stable/plugins/directory.html)
|
|
134
|
+
|
|
135
|
+
### Setting up your model
|
|
136
|
+
|
|
137
|
+
**For Gemini models (default):**
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
llm install llm-gemini
|
|
141
|
+
llm keys set gemini # enter API key
|
|
142
|
+
llm -m gemini-2.5-flash "Hello, world!"
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**For other models:**
|
|
146
|
+
|
|
147
|
+
1. Install the appropriate llm plugin (e.g., `llm install llm-openai`)
|
|
148
|
+
2. Configure your API key (e.g., `llm keys set openai`)
|
|
149
|
+
3. Use the model name with `--model` flag (e.g., `--model gpt-4o-mini`)
|
|
150
|
+
|
|
151
|
+
See the [llm documentation](https://llm.datasette.io/en/stable/setup.html) for setup instructions and the [plugin directory](https://llm.datasette.io/en/stable/plugins/directory.html) for available models.
|
|
152
|
+
|
|
153
|
+
## Output files
|
|
154
|
+
|
|
155
|
+
- `asset_queue.json` - Queue of assets needing alt text (from `scan`)
|
|
156
|
+
- `suggested_alts.json` - AI-generated suggestions (from `generate`)
|
|
157
|
+
- `asset_captions.json` - Approved final captions (from `label`)
|