|
|
@@ -45,6 +45,13 @@ except ImportError:
|
|
|
MINERU_LOCK_FILE = "/tmp/mineru_service_lock"
|
|
|
MINERU_COUNT_FILE = "/tmp/mineru_service_count"
|
|
|
|
|
|
+
|
|
|
+def _should_release_mineru_for_paddle() -> bool:
|
|
|
+ """是否在调用 PaddleOCR 前释放 MinerU 服务(停止 mineru-api.service 以腾出显存)。
|
|
|
+ 可通过环境变量 MINERU_RELEASE_BEFORE_PADDLE_OCR 控制:设为 false/0/no 时不释放,MinerU 保持运行。"""
|
|
|
+ v = os.getenv("MINERU_RELEASE_BEFORE_PADDLE_OCR", "true").strip().lower()
|
|
|
+ return v not in ("false", "0", "no")
|
|
|
+
|
|
|
def _get_paddleocr_executable() -> str:
|
|
|
"""返回 paddleocr 可执行文件路径或命令名,供 subprocess 使用。
|
|
|
当以 systemd 等方式运行时 PATH 可能不包含 venv/bin,故优先使用当前 Python 同目录下的 paddleocr。
|
|
|
@@ -519,9 +526,9 @@ def call_paddleocr(image_path: str) -> Optional[Dict[str, Any]]:
|
|
|
Returns:
|
|
|
paddleocr解析结果,如果失败返回None
|
|
|
"""
|
|
|
- # 在调用PaddleOCR前停止mineru服务以释放GPU内存
|
|
|
- mineru_stopped = stop_mineru_service()
|
|
|
-
|
|
|
+ # 在调用PaddleOCR前按配置决定是否停止mineru服务以释放GPU内存
|
|
|
+ mineru_stopped = stop_mineru_service() if _should_release_mineru_for_paddle() else False
|
|
|
+
|
|
|
try:
|
|
|
# 检查图片文件是否存在
|
|
|
if not os.path.exists(image_path):
|
|
|
@@ -868,9 +875,9 @@ def call_paddleocr_ocr(image_path: str, save_path: str) -> tuple[Optional[List[s
|
|
|
Returns:
|
|
|
(OCR识别的文本列表, JSON文件路径),如果失败返回(None, None)
|
|
|
"""
|
|
|
- # 在调用PaddleOCR前停止mineru服务以释放GPU内存
|
|
|
- mineru_stopped = stop_mineru_service()
|
|
|
-
|
|
|
+ # 在调用PaddleOCR前按配置决定是否停止mineru服务以释放GPU内存
|
|
|
+ mineru_stopped = stop_mineru_service() if _should_release_mineru_for_paddle() else False
|
|
|
+
|
|
|
try:
|
|
|
if not os.path.exists(image_path):
|
|
|
logger.error(f"[PaddleOCR OCR] 图片文件不存在: {image_path}")
|