mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat(ocr): update TypeScript bridge for quality tiers
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user