"""应用配置(从环境变量 / .env 读取)""" from pathlib import Path from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): # 服务 app_host: str = "0.0.0.0" app_port: int = 8801 # OCR use_gpu: bool = False ocr_lang: str = "ch" # 模型: "mobile" (CPU 友好, 默认) / "server" (高精度, GPU 适用) ocr_engine: str = "mobile" # 上传 / PDF max_upload_mb: int = 20 # 默认 150 DPI:清晰数字 PDF 150 已够,扫描件需调到 250~300 pdf_dpi: int = 150 # 路径接口允许的根目录(逗号分隔)。空 = 禁用路径接口 # 示例: "E:\\gitee\\guoju-hegui;D:\\uploads" allowed_dirs: str = "" # 识别超时(秒)- 单页 OCR / 整流程任一超时即返回失败 # CPU mobile 模型单页约 4 秒, 设 15s 留余量 ocr_page_timeout_s: int = 15 ocr_total_timeout_s: int = 60 # QR 识别: # true = 扫到 QR 后仍跑全量 OCR + 字段抽取 (默认, 向后兼容) # false = 扫到 QR 后直接返回 QR 里的 3 个核心字段 (开票时间/发票号/金额), 跳过 OCR # 没扫到 QR 或 QR 格式不合法时一律回退到 OCR 流水线, 不受此开关影响 qr_full_ocr: bool = True # 日志 log_level: str = "INFO" model_config = SettingsConfigDict( env_file=str(Path(__file__).resolve().parent.parent / ".env"), env_file_encoding="utf-8", extra="ignore", ) settings = Settings()