"""Application configuration using Pydantic Settings.""" from functools import lru_cache from pathlib import Path from pydantic_settings import BaseSettings, SettingsConfigDict import torch from typing import Optional class Settings(BaseSettings): """Application settings loaded from environment variables.""" model_config = SettingsConfigDict( env_file=".env", env_file_encoding="utf-8", case_sensitive=False, ) # API Settings api_prefix: str = "/doc_process/v1" debug: bool = False # Base Host Settings (can be overridden via .env file) # Default: 127.0.0.1 (production) # Dev: Set BASE_HOST=100.115.184.74 in .env file base_host: str = "127.0.0.1" # PaddleOCR-VL Settings @property def paddleocr_vl_url(self) -> str: """Get PaddleOCR-VL URL based on base_host.""" return f"http://{self.base_host}:8001/v1" # MinerOCR Settings @property def miner_ocr_api_url(self) -> str: """Get MinerOCR API URL based on base_host.""" return f"http://{self.base_host}:8000/file_parse" # GLM OCR Settings @property def glm_ocr_url(self) -> str: """Get GLM OCR URL based on base_host.""" return f"http://{self.base_host}:8002/v1" # padding ratio is_padding: bool = True padding_ratio: float = 0.15 # Model Paths pp_doclayout_model_dir: Optional[str] = "/home/yoge/.cache/modelscope/hub/models/PaddlePaddle/PP-DocLayoutV3" # Image Processing max_image_size_mb: int = 10 image_padding_ratio: float = 0.15 # 15% on each side = 30% total expansion device: torch.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") # cuda:0 or cpu # Server Settings host: str = "0.0.0.0" port: int = 8053 # Logging Settings log_dir: Optional[str] = None # Defaults to /app/logs in container or ./logs locally log_level: str = "INFO" # DEBUG, INFO, WARNING, ERROR, CRITICAL @property def pp_doclayout_dir(self) -> Path: """Get the PP-DocLayout model directory path.""" return Path(self.pp_doclayout_model_dir) @lru_cache def get_settings() -> Settings: """Get cached settings instance.""" return Settings()