pi-ocr 1.0.1 → 1.0.2
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.
- package/README.md +49 -334
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,396 +2,111 @@
|
|
|
2
2
|
|
|
3
3
|
> ### ⚡ Zero setup. Works out of the box.
|
|
4
4
|
>
|
|
5
|
-
> Default backend
|
|
6
|
-
> Just `pi install
|
|
5
|
+
> Default backend is **MinerU** — a free cloud API.
|
|
6
|
+
> No GPU, no API key, no pip install. Just `pi install` and `/ocr`.
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
> Bridges the multimodal gap for non-vision LLMs like **DeepSeek**. When your model can't see images, `pi_ocr` acts as its eyes.
|
|
11
|
-
|
|
12
|
-
## Three Backends — One Tool
|
|
13
|
-
|
|
14
|
-
| Backend | Type | Best For |
|
|
15
|
-
|---|---|---|
|
|
16
|
-
| 🦙 **Ollama** | Local GPU | Math formulas (LaTeX), privacy, offline |
|
|
17
|
-
| ☁️ **MinerU** | Free cloud API | Complex PDFs, no GPU, zero setup |
|
|
18
|
-
| 📐 **Pix2Text** | Local Python | Math formulas + text, free Mathpix alternative |
|
|
19
|
-
|
|
20
|
-
Switch anytime with `/ocr` (no args) — a visual `SettingsList` menu lets you pick and configure everything without editing JSON:
|
|
21
|
-
|
|
22
|
-
```
|
|
23
|
-
/ocr → opens settings: backend, model, PDF split toggle
|
|
24
|
-
/ocr <file> [task] → OCR a file
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Features
|
|
28
|
-
|
|
29
|
-
| | |
|
|
30
|
-
|---|---|
|
|
31
|
-
| 🔤 **Text** | General text recognition → Markdown |
|
|
32
|
-
| 🧮 **Formulas** | Math formulas → LaTeX (Ollama glm-ocr: 94.6 OmniDocBench) |
|
|
33
|
-
| 📊 **Tables** | Table structure → Markdown tables |
|
|
34
|
-
| 🖼️ **Figures** | Diagrams and illustrations → descriptions |
|
|
35
|
-
| 📄 **PDF** | Full PDF support across all backends |
|
|
36
|
-
| 🎛️ **Any model** | Ollama works with glm-ocr, llama3.2-vision, minicpm-v, etc. |
|
|
37
|
-
| ☁️ **Free cloud** | MinerU Agent API: no token, ≤10MB, ≤20 pages free |
|
|
38
|
-
| 📦 **Auto-split** | MinerU splits PDFs >20 pages into free-tier chunks |
|
|
8
|
+
OCR for [Pi Coding Agent](https://pi.dev). Bridges the multimodal gap for non-vision LLMs like DeepSeek: when your model can't see images, `pi_ocr` reads them for you.
|
|
39
9
|
|
|
40
10
|
---
|
|
41
11
|
|
|
42
12
|
## Quickstart
|
|
43
13
|
|
|
44
|
-
### One command
|
|
45
|
-
|
|
46
14
|
```bash
|
|
47
15
|
pi install npm:pi-ocr
|
|
16
|
+
/ocr ./screenshot.png
|
|
17
|
+
/ocr ./paper.pdf
|
|
48
18
|
```
|
|
49
19
|
|
|
50
|
-
**That's
|
|
51
|
-
Start OCR'ing immediately:
|
|
52
|
-
|
|
53
|
-
```
|
|
54
|
-
/ocr ./scan.png
|
|
55
|
-
/ocr ./document.pdf
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
> 💡 Want offline OCR or math formulas? Switch backends anytime with `/ocr` (no args).
|
|
20
|
+
**That's all.** MinerU (free cloud API) is the default and requires nothing.
|
|
59
21
|
|
|
60
22
|
---
|
|
61
23
|
|
|
62
|
-
|
|
24
|
+
## Backends
|
|
63
25
|
|
|
64
|
-
|
|
26
|
+
Switch anytime with `/ocr` (no args).
|
|
27
|
+
|
|
28
|
+
| | Backend | Best for | Setup |
|
|
29
|
+
|---|---|---|---|
|
|
30
|
+
| ☁️ | **MinerU** (default) | PDFs, tables, general docs | None — works instantly |
|
|
31
|
+
| 🦙 | Ollama | Math formulas → LaTeX, offline | `brew install ollama && ollama pull glm-ocr` |
|
|
32
|
+
| 📐 | Pix2Text | Math + text, CPU-only | `pip install pix2text` |
|
|
65
33
|
|
|
66
34
|
---
|
|
67
35
|
|
|
68
|
-
|
|
36
|
+
## MinerU (default)
|
|
69
37
|
|
|
70
|
-
|
|
38
|
+
Free cloud API. Handles PDF, PNG, JPG, Docx, PPTx, Xlsx.
|
|
71
39
|
|
|
72
|
-
|
|
73
|
-
# 1. Install Ollama
|
|
74
|
-
brew install ollama
|
|
40
|
+
**Limits:** ≤10MB per file, ≤20 pages per request.
|
|
75
41
|
|
|
76
|
-
|
|
77
|
-
ollama pull glm-ocr
|
|
42
|
+
PDFs >20 pages can be auto-split (enabled by default in `/ocr` settings). Splitting needs `pip install pypdfium2`.
|
|
78
43
|
|
|
79
|
-
|
|
80
|
-
brew install poppler
|
|
81
|
-
```
|
|
44
|
+
---
|
|
82
45
|
|
|
83
|
-
|
|
84
|
-
> Multi-page PDFs need `poppler` for the `pdftoppm` tool.
|
|
46
|
+
## Ollama (optional, for math formulas)
|
|
85
47
|
|
|
86
|
-
|
|
48
|
+
Local GPU OCR via [glm-ocr](https://ollama.com) — state-of-the-art formula recognition (94.6 OmniDocBench). Outputs LaTeX.
|
|
87
49
|
|
|
88
50
|
```bash
|
|
89
|
-
#
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
# 2. Pull the default OCR model (~2.2 GB)
|
|
51
|
+
# macOS
|
|
52
|
+
brew install ollama
|
|
93
53
|
ollama pull glm-ocr
|
|
54
|
+
brew install poppler # multi-page PDFs only
|
|
94
55
|
|
|
95
|
-
#
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
sudo
|
|
56
|
+
# Linux
|
|
57
|
+
curl -fsSL https://ollama.com/install.sh | sh
|
|
58
|
+
ollama pull glm-ocr
|
|
59
|
+
sudo apt install poppler-utils
|
|
99
60
|
```
|
|
100
61
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
```bash
|
|
104
|
-
# Check Ollama is running and model is pulled
|
|
105
|
-
ollama list | grep glm-ocr
|
|
106
|
-
```
|
|
62
|
+
Switch with `/ocr` → "OCR Backend" → ollama.
|
|
107
63
|
|
|
108
64
|
---
|
|
109
65
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
Pix2Text runs entirely in Python. Handles images and PDFs via a single API call — no manual conversion needed.
|
|
113
|
-
|
|
114
|
-
#### Step 1: Make sure you have Python 3.9+ (macOS/Linux)
|
|
115
|
-
|
|
116
|
-
| System | Check |
|
|
117
|
-
|---|---|
|
|
118
|
-
| macOS/Linux | `python3 --version` |
|
|
119
|
-
|
|
120
|
-
> ⚠️ **Important:** Know which Python you're using. Run `which python3` — if it shows `conda`, `brew`, or `/usr/bin/python3`, your `pip install` must target the same Python:
|
|
121
|
-
> ```bash
|
|
122
|
-
> # Conda Python
|
|
123
|
-
> pip install pix2text
|
|
124
|
-
>
|
|
125
|
-
> # System Python (may need --user or sudo)
|
|
126
|
-
> pip install --user pix2text
|
|
127
|
-
>
|
|
128
|
-
> # Brew Python (macOS)
|
|
129
|
-
> /opt/homebrew/bin/pip3 install pix2text
|
|
130
|
-
> ```
|
|
131
|
-
> If unsure, use `python3 -m pip install ...` — this always installs for the active `python3`.
|
|
132
|
-
|
|
133
|
-
#### Step 2: Install packages
|
|
66
|
+
## Pix2Text (optional, for offline CPU)
|
|
134
67
|
|
|
135
|
-
|
|
136
|
-
python3 -m pip install pix2text
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
#### Step 3: Verify
|
|
68
|
+
Local Python OCR. Mathpix alternative — handles text + formulas on CPU.
|
|
140
69
|
|
|
141
70
|
```bash
|
|
142
|
-
|
|
71
|
+
pip install pix2text
|
|
143
72
|
```
|
|
144
73
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
> First run downloads ONNX models (~50MB) to `~/.pix2text/`.
|
|
148
|
-
|
|
74
|
+
First run downloads ONNX models (~50MB). Switch with `/ocr` → "OCR Backend" → pix2text.
|
|
149
75
|
|
|
150
76
|
---
|
|
151
77
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
**No setup required.** The free Agent API works immediately. No token, no account, no install.
|
|
155
|
-
|
|
156
|
-
Free tier limits:
|
|
157
|
-
- ≤ 10 MB per file
|
|
158
|
-
- ≤ 20 pages per request
|
|
159
|
-
- IP-based rate limiting
|
|
160
|
-
|
|
161
|
-
> 💡 PDFs >20 pages: auto-splitting needs `python3` + `pypdfium2` (`pip install pypdfium2`).
|
|
162
|
-
> Most PDFs are under 20 pages — you'll likely never need this.
|
|
163
|
-
|
|
164
|
-
For files >10MB, compress first at [ilovepdf.com/compress_pdf](https://ilovepdf.com/compress_pdf).
|
|
165
|
-
|
|
166
|
-
---
|
|
167
|
-
|
|
168
|
-
## Usage
|
|
169
|
-
|
|
170
|
-
### Settings UI
|
|
171
|
-
|
|
172
|
-
```
|
|
173
|
-
/ocr
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
Opens an interactive `SettingsList` with keyboard navigation:
|
|
177
|
-
|
|
178
|
-
```
|
|
179
|
-
┌─ OCR Settings ─────────────────────────────────┐
|
|
180
|
-
│ OCR Backend [ollama / mineru / pix2text] │
|
|
181
|
-
│ MinerU: Split PDF [ON / OFF] │
|
|
182
|
-
│ Ollama Model [glm-ocr] │
|
|
183
|
-
│ ↑↓ navigate • ← → toggle • enter select • esc close │
|
|
184
|
-
└──────────────────────────────────────────────────┘
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
- **Backend**: ← → to cycle ollama/mineru/pix2text — saves immediately
|
|
188
|
-
- **MinerU Split**: ← → to toggle ON/OFF — when ON, PDFs >20 pages are auto-split
|
|
189
|
-
- **Model**: Enter opens a sub-menu with recommended models + custom input
|
|
190
|
-
|
|
191
|
-
### OCR a file
|
|
192
|
-
|
|
193
|
-
```
|
|
194
|
-
/ocr <file> [task] [model]
|
|
195
|
-
```
|
|
78
|
+
## Commands
|
|
196
79
|
|
|
197
|
-
|
|
|
80
|
+
| Command | |
|
|
198
81
|
|---|---|
|
|
199
|
-
| `/ocr
|
|
200
|
-
| `/ocr
|
|
201
|
-
| `/ocr
|
|
202
|
-
| `/ocr ./paper.pdf auto glm-ocr:q8_0` | Use specific model |
|
|
82
|
+
| `/ocr` | Open settings (backend, model, split toggle) |
|
|
83
|
+
| `/ocr <file> [task]` | OCR a file |
|
|
84
|
+
| `/ocr <file> formula` | Math LaTeX output |
|
|
203
85
|
|
|
204
86
|
### Tasks
|
|
205
87
|
|
|
206
|
-
| Task |
|
|
207
|
-
|
|
208
|
-
| `auto`
|
|
209
|
-
| `text` | Plain
|
|
210
|
-
| `formula` |
|
|
211
|
-
| `table` |
|
|
212
|
-
| `figure` |
|
|
213
|
-
|
|
214
|
-
### LLM-invoked (automatic)
|
|
215
|
-
|
|
216
|
-
The extension registers a `pi_ocr` tool. The agent invokes it automatically:
|
|
217
|
-
|
|
218
|
-
```
|
|
219
|
-
> What formula is written in this screenshot?
|
|
220
|
-
> OCR this 50-page PDF into markdown.
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
---
|
|
224
|
-
|
|
225
|
-
## MinerU PDF Splitting
|
|
226
|
-
|
|
227
|
-
When `MinerU: Split PDF >20 pages` is ON (default), large PDFs are automatically split into ≤20-page chunks. Each chunk is a separate request with 3s spacing:
|
|
228
|
-
|
|
229
|
-
```
|
|
230
|
-
Splitting 85-page PDF into ≤20-page chunks…
|
|
231
|
-
[1/5] uploading…
|
|
232
|
-
[1/5] running (12s)
|
|
233
|
-
[1/5] done
|
|
234
|
-
[2/5] waiting rate limit…
|
|
235
|
-
[2/5] uploading…
|
|
236
|
-
[2/5] running (18s)
|
|
237
|
-
[2/5] done
|
|
238
|
-
...
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
---
|
|
242
|
-
|
|
243
|
-
## Backend Comparison
|
|
244
|
-
|
|
245
|
-
| | 🦙 Ollama | ☁️ MinerU | 📐 **Pix2Text** |
|
|
246
|
-
|---|---|---|---|
|
|
247
|
-
| **Setup** | Install Ollama + pull model | None | `pip install` 3 packages |
|
|
248
|
-
| **GPU needed** | Recommended | No | No |
|
|
249
|
-
| **Internet** | No | Yes | No (first run: yes) |
|
|
250
|
-
| **Math formulas** | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐ |
|
|
251
|
-
| **Complex PDFs** | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐ |
|
|
252
|
-
| **Chinese text** | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
|
|
253
|
-
| **File size limit** | None | 10MB (free) | None |
|
|
254
|
-
| **Page limit** | None | 20/request (free) | None |
|
|
255
|
-
| **Cost** | Free (local) | Free (rate-limited) | Free (local) |
|
|
256
|
-
|
|
257
|
-
---
|
|
258
|
-
|
|
259
|
-
## Supported File Types
|
|
260
|
-
|
|
261
|
-
| Format | Ollama | MinerU | Pix2Text |
|
|
262
|
-
|---|---|---|---|
|
|
263
|
-
| PNG, JPG, GIF, WEBP, BMP, TIFF | ✅ | ✅ | ✅ |
|
|
264
|
-
| PDF | ✅ | ✅ | ✅ |
|
|
265
|
-
| Docx, PPTx, Xlsx | ❌ | ✅ | ❌ |
|
|
266
|
-
|
|
267
|
-
---
|
|
268
|
-
|
|
269
|
-
## PDF Support Details
|
|
270
|
-
|
|
271
|
-
| Backend | Conversion method | System deps |
|
|
272
|
-
|---|---|---|
|
|
273
|
-
| **Ollama** | `sips` (macOS page 1) / `pdftoppm` (multi-page, Linux) | `poppler` (multi-page only) |
|
|
274
|
-
| **MinerU** | Direct PDF upload — no conversion | None |
|
|
275
|
-
| **Pix2Text** | Built-in `recognize_pdf()` — no system deps | None |
|
|
276
|
-
|
|
277
|
-
---
|
|
278
|
-
|
|
279
|
-
## Configuration
|
|
280
|
-
|
|
281
|
-
All settings are persisted to `~/.pi/agent/settings.json`:
|
|
282
|
-
|
|
283
|
-
```json
|
|
284
|
-
{
|
|
285
|
-
"minimodelOcr": {
|
|
286
|
-
"backend": "ollama",
|
|
287
|
-
"model": "glm-ocr",
|
|
288
|
-
"ollamaHost": "http://localhost:11434",
|
|
289
|
-
"mineruSplitPdf": true
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
Change settings via `/ocr` (interactive) or edit directly. Environment variables override file settings:
|
|
295
|
-
|
|
296
|
-
```bash
|
|
297
|
-
export OLLAMA_HOST="http://localhost:11434"
|
|
298
|
-
export OCR_MODEL="glm-ocr"
|
|
299
|
-
```
|
|
88
|
+
| Task | Output |
|
|
89
|
+
|---|---|
|
|
90
|
+
| `auto` (default) | Markdown + LaTeX |
|
|
91
|
+
| `text` | Plain Markdown |
|
|
92
|
+
| `formula` | LaTeX only |
|
|
93
|
+
| `table` | Markdown tables |
|
|
94
|
+
| `figure` | Description |
|
|
300
95
|
|
|
301
96
|
---
|
|
302
97
|
|
|
303
98
|
## Troubleshooting
|
|
304
99
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
```bash
|
|
308
|
-
# Start Ollama in the background
|
|
309
|
-
ollama serve
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
### Ollama: "model not found"
|
|
313
|
-
|
|
314
|
-
```bash
|
|
315
|
-
ollama pull glm-ocr
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
### Pix2Text: "python3 not found"
|
|
319
|
-
|
|
320
|
-
```bash
|
|
321
|
-
# Check your python:
|
|
322
|
-
which python3 && python3 --version
|
|
323
|
-
|
|
324
|
-
# If using conda:
|
|
325
|
-
conda activate base && pip install pix2text
|
|
326
|
-
|
|
327
|
-
# If using system python:
|
|
328
|
-
python3 -m pip install --user pix2text
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
### Pix2Text: "No module named 'pix2text'"
|
|
332
|
-
|
|
333
|
-
You likely installed with a different `pip` than your active `python3`:
|
|
334
|
-
|
|
335
|
-
```bash
|
|
336
|
-
python3 -m pip install pix2text
|
|
337
|
-
```
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
### MinerU: "429 Too Many Requests"
|
|
341
|
-
|
|
342
|
-
IP rate limit hit. Wait 1-2 minutes, or switch to Ollama/Pix2Text with `/ocr`.
|
|
100
|
+
**"Is Ollama running?"** → `ollama serve`
|
|
343
101
|
|
|
344
|
-
|
|
102
|
+
**MinerU 429** → Rate limited. Wait a minute or switch backend.
|
|
345
103
|
|
|
346
|
-
|
|
104
|
+
**"python3 not found" (Pix2Text)** → `python3 -m pip install pix2text`
|
|
347
105
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
Compress the PDF at [ilovepdf.com/compress_pdf](https://ilovepdf.com/compress_pdf) or switch to a local backend with `/ocr`.
|
|
351
|
-
|
|
352
|
-
### macOS multi-page PDF: "pdftoppm not found"
|
|
353
|
-
|
|
354
|
-
```bash
|
|
355
|
-
brew install poppler
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
### Linux multi-page PDF: "pdftoppm not found"
|
|
359
|
-
|
|
360
|
-
```bash
|
|
361
|
-
# Debian/Ubuntu
|
|
362
|
-
sudo apt install poppler-utils
|
|
363
|
-
|
|
364
|
-
# Fedora
|
|
365
|
-
sudo dnf install poppler-utils
|
|
366
|
-
|
|
367
|
-
# Arch
|
|
368
|
-
sudo pacman -S poppler
|
|
369
|
-
```
|
|
106
|
+
**"pdftoppm not found" (Ollama multi-page)** → `brew install poppler` (macOS) / `sudo apt install poppler-utils` (Linux)
|
|
370
107
|
|
|
371
108
|
---
|
|
372
109
|
|
|
373
|
-
## How It Works
|
|
374
|
-
|
|
375
|
-
```
|
|
376
|
-
┌──────────────────┐ ┌──────────────────┐ ┌──────────────────────┐
|
|
377
|
-
│ pi (DeepSeek) │────▶│ pi_ocr │────▶│ Ollama / MinerU │
|
|
378
|
-
│ (no vision) │ │ pi extension │ │ / Pix2Text │
|
|
379
|
-
└──────────────────┘ └──────────────────┘ └──────────────────────┘
|
|
380
|
-
│ │ │
|
|
381
|
-
│ "read this image" │ POST /api/generate │
|
|
382
|
-
│────────────────────────▶│ (Ollama) │
|
|
383
|
-
│ │ or POST /api/v1/agent │
|
|
384
|
-
│ │ (MinerU) │
|
|
385
|
-
│ │ or python3 subprocess │
|
|
386
|
-
│ │ (Pix2Text) │
|
|
387
|
-
│ │──────────────────────────▶│
|
|
388
|
-
│ │ OCR text response │
|
|
389
|
-
│ LaTeX / Markdown │◀──────────────────────────│
|
|
390
|
-
│◀────────────────────────│ │
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
The tool dispatches to your selected backend. Switch anytime with `/ocr` — no restart needed.
|
|
394
|
-
|
|
395
110
|
## License
|
|
396
111
|
|
|
397
112
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ocr",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Pi extension: Zero-setup multi-backend OCR — MinerU (free cloud), Ollama (local GPU, LaTeX formulas), Pix2Text (local Python). Extract text, formulas, and tables from images and PDFs. Default: zero config, works out of the box.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|