fix: improve OCR indexing and evidence review
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import subprocess
|
||||
import tempfile
|
||||
from functools import lru_cache
|
||||
from importlib.metadata import version
|
||||
from pathlib import Path
|
||||
from threading import Lock
|
||||
|
||||
@@ -30,11 +31,21 @@ def _ocr_engine(model_dir: str):
|
||||
from paddleocr import PaddleOCR
|
||||
except ImportError as exc:
|
||||
raise RuntimeError("扫描PDF需要PaddleOCR;请安装OCR依赖或交由教师处理") from exc
|
||||
try:
|
||||
return PaddleOCR(lang="ch", text_detection_model_dir=str(detection), text_recognition_model_dir=str(recognition),
|
||||
use_textline_orientation=False, use_doc_orientation_classify=False, use_doc_unwarping=False)
|
||||
except TypeError:
|
||||
return PaddleOCR(lang="ch", det_model_dir=str(detection), rec_model_dir=str(recognition), use_angle_cls=False, show_log=False)
|
||||
if int(version("paddleocr").split(".")[0]) >= 3:
|
||||
def model_name(directory):
|
||||
config = directory / "inference.yml"
|
||||
if not config.is_file():
|
||||
raise RuntimeError(f"离线OCR模型缺少 inference.yml: {directory}")
|
||||
for line in config.read_text(encoding="utf-8").splitlines():
|
||||
if line.strip().startswith("model_name:"):
|
||||
return line.split(":", 1)[1].strip().strip("'\"")
|
||||
raise RuntimeError(f"离线OCR模型未声明 model_name: {config}")
|
||||
|
||||
return PaddleOCR(text_detection_model_name=model_name(detection), text_detection_model_dir=str(detection),
|
||||
text_recognition_model_name=model_name(recognition), text_recognition_model_dir=str(recognition),
|
||||
use_textline_orientation=False, use_doc_orientation_classify=False, use_doc_unwarping=False,
|
||||
device="cpu", enable_mkldnn=False)
|
||||
return PaddleOCR(lang="ch", det_model_dir=str(detection), rec_model_dir=str(recognition), use_angle_cls=False, show_log=False)
|
||||
|
||||
|
||||
def _ocr(image_path: str):
|
||||
|
||||
Reference in New Issue
Block a user