将ocr解析模块独立出来

This commit is contained in:
dzr
2025-10-31 17:50:25 +08:00
parent 4318179904
commit 4603a86df4
5 changed files with 1870 additions and 2140 deletions

View File

@@ -29,25 +29,8 @@ import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
# 处理直接运行时的导入问题
# 当直接运行 python ocr/main.py 时__package__ 为 None
# 当作为模块运行时python -m ocr.main__package__ 为 'ocr'
try:
_package = __package__
except NameError:
_package = None
if _package is None:
# 直接运行脚本时,添加父目录到路径
parent_dir = Path(__file__).parent.parent
if str(parent_dir) not in sys.path:
sys.path.insert(0, str(parent_dir))
from api import router as ocr_router
from config import MODEL_DIR
else:
# 作为模块导入时使用相对导入
from api import router as ocr_router
from config import MODEL_DIR
from ocr.api import ocr_router
from ocr.config import MODEL_DIR
# 配置日志
logging.basicConfig(