Repository navigation
Expand file tree
/
Copy pathrun.py
More file actions
53 lines (43 loc) · 2.01 KB
/
Copy pathrun.py
File metadata and controls
53 lines (43 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import sys
import argparse
import logging
from pathlib import Path
# Setup logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
log = logging.getLogger("OCR_Runner")
def main():
parser = argparse.ArgumentParser(description="Clean & Public OCR Repository Runner")
parser.add_argument("input", help="Path to the input PDF file")
parser.add_argument("--engine", choices=["docling", "paddle", "hybrid"], default="docling",
help="OCR engine to use (default: docling)")
parser.add_argument("--output", default="output", help="Output directory (default: output)")
parser.add_argument("--gpu", action="store_true", default=True, help="Use GPU if available (default: True)")
parser.add_argument("--no-gpu", action="store_false", dest="gpu", help="Force CPU usage")
args = parser.parse_args()
input_path = Path(args.input)
if not input_path.exists():
log.error(f"❌ Input file not found: {args.input}")
sys.exit(1)
log.info(f"🚀 Starting OCR with {args.engine} engine...")
try:
if args.engine == "docling":
from engines.docling_engine import DoclingEngine
engine = DoclingEngine(use_gpu=args.gpu)
elif args.engine == "paddle":
from engines.paddle_engine import PaddleEngine
engine = PaddleEngine(use_gpu=args.gpu)
elif args.engine == "hybrid":
from engines.hybrid_engine import HybridEngine
engine = HybridEngine(use_gpu=args.gpu)
text_path, meta_path = engine.run(str(input_path), output_dir=args.output)
log.info("✅ OCR Process Completed Successfully!")
log.info(f"📄 Text saved to: {text_path}")
if meta_path:
log.info(f"🧠 Metadata saved to: {meta_path}")
except Exception as e:
log.error(f"❌ An error occurred: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()