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.
Files changed (2) hide show
  1. package/README.md +49 -334
  2. 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: **MinerU** — a free cloud API. No install, no GPU, no API key.
6
- > Just `pi install npm:pi-ocr` and OCR anything.
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
- Multi-backend OCR for [Pi Coding Agent](https://pi.dev) extract text, LaTeX math formulas, and tables from images and PDFs. Choose the backend that fits your needs: free cloud API, local GPU, or pure Python.
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 it.** The default backend is ☁️ **MinerU** — a free cloud API with zero setup.
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
- ### Optional: set up other backends
24
+ ## Backends
63
25
 
64
- Only needed if you want to switch from the default MinerU.
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
- ### 🦙 Ollama setup
36
+ ## MinerU (default)
69
37
 
70
- #### macOS
38
+ Free cloud API. Handles PDF, PNG, JPG, Docx, PPTx, Xlsx.
71
39
 
72
- ```bash
73
- # 1. Install Ollama
74
- brew install ollama
40
+ **Limits:** ≤10MB per file, ≤20 pages per request.
75
41
 
76
- # 2. Pull the default OCR model (~2.2 GB)
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
- # 3. Multi-page PDF support (optional but recommended)
80
- brew install poppler
81
- ```
44
+ ---
82
45
 
83
- > macOS uses built-in `sips` for single-page PDFs — zero extra deps for those.
84
- > Multi-page PDFs need `poppler` for the `pdftoppm` tool.
46
+ ## Ollama (optional, for math formulas)
85
47
 
86
- #### Linux
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
- # 1. Install Ollama
90
- curl -fsSL https://ollama.com/install.sh | sh
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
- # 3. PDF support (required on Linux)
96
- sudo apt install poppler-utils # Debian/Ubuntu
97
- sudo dnf install poppler-utils # Fedora
98
- sudo pacman -S poppler # Arch
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
- #### Verify
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
- ### 📐 Pix2Text setup
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
- ```bash
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
- python3 -c "from pix2text import Pix2Text; print('OK')"
71
+ pip install pix2text
143
72
  ```
144
73
 
145
- > First run downloads ONNX models (~50MB) to `~/.pix2text/`.
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
- ### ☁️ MinerU (default — already working!)
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
- | Example | Result |
80
+ | Command | |
198
81
  |---|---|
199
- | `/ocr ./scan.png` | Auto-detect all content |
200
- | `/ocr ./equation.jpg formula` | LaTeX formula output |
201
- | `/ocr ./contract.pdf text` | Text-only extraction |
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 | Description | Output format |
207
- |---|---|---|
208
- | `auto` | Full document OCR (default) | Markdown + LaTeX mixed |
209
- | `text` | Plain text recognition | Markdown |
210
- | `formula` | Math formula recognition | LaTeX |
211
- | `table` | Table structure recognition | Markdown tables |
212
- | `figure` | Figure / diagram description | Natural language |
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
- ### Ollama: "fetch failed" / "ECONNREFUSED"
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
- ### MinerU: "file page count exceeds lightweight API limit"
102
+ **MinerU 429** Rate limited. Wait a minute or switch backend.
345
103
 
346
- Enable PDF splitting: `/ocr`toggle "MinerU: Split PDF" to ON.
104
+ **"python3 not found" (Pix2Text)**`python3 -m pip install pix2text`
347
105
 
348
- ### MinerU: "File too large for free MinerU API"
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.1",
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",