Files

53 lines
1.4 KiB
Python
Raw Permalink Normal View History

2025-12-29 17:34:58 +08:00
"""Application configuration using Pydantic Settings."""
from functools import lru_cache
from pathlib import Path
from pydantic_settings import BaseSettings, SettingsConfigDict
2025-12-29 20:02:07 +08:00
import torch
2025-12-31 17:38:32 +08:00
from typing import Optional
2025-12-29 17:34:58 +08:00
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
# PaddleOCR-VL Settings
2025-12-31 17:38:32 +08:00
paddleocr_vl_url: str = "http://127.0.0.1:8000/v1"
2026-01-05 17:30:54 +08:00
# MinerOCR Settings
miner_ocr_api_url: str = "http://127.0.0.1:8000/file_parse"
2025-12-29 17:34:58 +08:00
# Model Paths
2025-12-31 17:38:32 +08:00
pp_doclayout_model_dir: Optional[str] = "/home/yoge/.cache/modelscope/hub/models/PaddlePaddle/PP-DocLayoutV2"
2025-12-29 17:34:58 +08:00
# Image Processing
max_image_size_mb: int = 10
image_padding_ratio: float = 0.15 # 15% on each side = 30% total expansion
2025-12-29 20:02:07 +08:00
device: torch.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") # cuda:0 or cpu
2025-12-29 17:34:58 +08:00
# Server Settings
host: str = "0.0.0.0"
port: int = 8053
@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()