Batch OCR Processing for Thai Documents using Typhoon OCR API
Project description
PTM-OCR
Batch OCR Processing for Thai Documents using Typhoon OCR API
Installation
pip install ptm-ocr
Quick Start
1. Set Environment Variables
Create a .env file or export environment variables:
export OCR_BASE_URL=https://openai.com/v1
export OCR_API_KEY=your_api_key_here
export OCR_MODEL=ocr
2. Run OCR
Command Line:
# Basic usage
ptm-ocr data/pdfs
# With options
ptm-ocr data/pdfs -o output -w 8 -t structure
Python API:
from ptm_ocr import process_folder, process_pdf_file
# Process entire folder
summary = process_folder(
input_folder="data/pdfs",
output_folder="output",
task_type="default",
max_workers=4
)
# Process single PDF
summary = process_pdf_file(
pdf_path="document.pdf",
output_path="document.jsonl"
)
CLI Options
| Option | Short | Default | Description |
|---|---|---|---|
--output |
-o |
output |
Output folder for JSONL files |
--task-type |
-t |
default |
OCR task type: default or structure |
--workers |
-w |
4 |
Number of parallel workers |
--base-url |
env | Override OCR_BASE_URL | |
--api-key |
env | Override OCR_API_KEY | |
--model |
env | Override OCR_MODEL |
Output Format (JSONL)
Each line in the output file is a JSON object:
{"page": 1, "text": "ข้อความที่ OCR ได้", "status": "success", "error": null}
{"page": 2, "text": "ข้อความหน้า 2", "status": "success", "error": null}
Task Types
- default: General documents, infographics
- structure: Complex layouts (tables, forms, mixed content)
Reading Output
import json
with open('output/document.jsonl', 'r', encoding='utf-8') as f:
for line in f:
page = json.loads(line)
print(f"Page {page['page']}: {page['text'][:100]}...")
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ptm_ocr-0.1.1.tar.gz
(6.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ptm_ocr-0.1.1.tar.gz.
File metadata
- Download URL: ptm_ocr-0.1.1.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
578dad22add1f8fe4c5943733b4d686d03354228194d8f59eb3006f6f10d56df
|
|
| MD5 |
69bd18aa1addaa5a3676fe5628c6d812
|
|
| BLAKE2b-256 |
863b3cd7e7302297c1a22b07671847a3df9933c2c4977d1122e374bd92116637
|
File details
Details for the file ptm_ocr-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ptm_ocr-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e5c6d86cbd0b1ae7f9cfdb0e8d3e0b781433a87d35da84f5aa3b3c8267838ce
|
|
| MD5 |
f29688ac5f809019f9e04b0b18271cb5
|
|
| BLAKE2b-256 |
ad9854b975470628ad0dba986350437c63cf0f6aa0093105e58b78da711ffcc2
|