feat(ocr): update TypeScript bridge for quality tiers

This commit is contained in:
Siddharth Kumar Sah
2026-04-12 18:34:47 +08:00
parent 49b9bcecfe
commit 4235875f78
+7 -3
View File
@@ -2,14 +2,18 @@ import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { type ProgressCallback, runPythonWithProgress } from "./bridge.js";
export type OcrQuality = "fast" | "balanced" | "best";
export interface OcrOptions {
engine?: "tesseract" | "paddleocr";
quality?: OcrQuality;
language?: string;
enhance?: boolean;
/** @deprecated Use quality instead. Kept for backward compat. */
engine?: "tesseract" | "paddleocr";
}
export interface OcrResult {
text: string;
engine: string;
}
export async function extractText(
@@ -23,6 +27,7 @@ export async function extractText(
await writeFile(inputPath, inputBuffer);
const { stdout } = await runPythonWithProgress("ocr.py", [inputPath, JSON.stringify(options)], {
onProgress,
timeout: 600_000, // 10 min timeout for VLM on CPU
});
const result = JSON.parse(stdout);
@@ -32,6 +37,5 @@ export async function extractText(
return {
text: result.text,
engine: result.engine,
};
}