|
|
@@ -0,0 +1,48 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+"""
|
|
|
+PaddleX 服务启动包装器 - 自动激活适配器
|
|
|
+
|
|
|
+用于启动 PaddleX HTTP API 服务并自动激活增强适配器。
|
|
|
+适配器位于同一目录下的 adapters/ 子目录中。
|
|
|
+
|
|
|
+使用方法:
|
|
|
+ python start_paddlex_with_adapter.py --serve --port 8111 --device gpu --pipeline config.yaml
|
|
|
+"""
|
|
|
+import os
|
|
|
+import sys
|
|
|
+from pathlib import Path
|
|
|
+
|
|
|
+def main():
|
|
|
+ # 🎯 在当前进程中激活适配器
|
|
|
+ if os.getenv("PADDLEX_ENABLE_ADAPTER", "").lower() in ("true", "1", "yes"):
|
|
|
+ # 适配器位于同一目录下的 adapters/ 子目录
|
|
|
+ script_dir = Path(__file__).parent
|
|
|
+ adapters_path = script_dir / "adapters"
|
|
|
+
|
|
|
+ if str(adapters_path) not in sys.path:
|
|
|
+ sys.path.insert(0, str(adapters_path))
|
|
|
+
|
|
|
+ try:
|
|
|
+ from adapters import apply_table_recognition_adapter, apply_enhanced_doc_preprocessor
|
|
|
+ if apply_table_recognition_adapter() and apply_enhanced_doc_preprocessor():
|
|
|
+ print("✅ Adapter activated in wrapper process")
|
|
|
+ else:
|
|
|
+ print("⚠️ Failed to activate adapter")
|
|
|
+ except Exception as e:
|
|
|
+ print(f"⚠️ Failed to activate adapter: {e}")
|
|
|
+
|
|
|
+ # 🎯 解析命令行参数
|
|
|
+ args = sys.argv[1:] # 去掉脚本名
|
|
|
+
|
|
|
+ # 🎯 导入 PaddleX CLI 主函数并在当前进程执行
|
|
|
+ from paddlex.paddlex_cli import main as paddlex_main
|
|
|
+
|
|
|
+ # 替换 sys.argv 以传递参数
|
|
|
+ sys.argv = ['paddlex'] + args
|
|
|
+
|
|
|
+ # 执行 PaddleX
|
|
|
+ paddlex_main()
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ main()
|
|
|
+
|