Spaces:
Running on Zero
Running on Zero
Download src/config.py from pareshmishra/document-Intelligence-OCR: direct link, hf CLI and curl.
- Browser
- Download file 2.07 kB
-
https://huggingface.co/spaces/pareshmishra/document-Intelligence-OCR/resolve/main/src/config.py
- Command line
-
hf download hf://spaces/pareshmishra/document-Intelligence-OCR/src/config.py
-
curl -L -o config.py https://huggingface.co/spaces/pareshmishra/document-Intelligence-OCR/resolve/main/src/config.py
2.07 kB
| import os | |
| import logging | |
| from typing import Optional | |
| from dotenv import load_dotenv | |
| # Load environment variables from local .env if present | |
| env_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), ".env") | |
| if os.path.exists(env_path): | |
| load_dotenv(dotenv_path=env_path) | |
| os.environ["GRADIO_ANALYTICS_ENABLED"] = "False" | |
| # Logging configuration | |
| LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper() | |
| logging.basicConfig( | |
| level=getattr(logging, LOG_LEVEL, logging.INFO), | |
| format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", | |
| datefmt="%Y-%m-%d %H:%M:%S", | |
| ) | |
| logger = logging.getLogger("document_intelligence") | |
| class Settings: | |
| """Application configuration loaded from environment variables.""" | |
| NVIDIA_API_KEY: Optional[str] = os.getenv("NVIDIA_API_KEY") | |
| NVIDIA_BASE_URL: str = os.getenv( | |
| "NVIDIA_BASE_URL", "https://integrate.api.nvidia.com/v1" | |
| ) | |
| NVIDIA_MODEL: str = os.getenv( | |
| "NVIDIA_MODEL", "nvidia/nemotron-3-nano-omni-30b-a3b-reasoning" | |
| ) | |
| MAX_IMAGE_SIZE_MB: float = float(os.getenv("MAX_IMAGE_SIZE_MB", "10.0")) | |
| MAX_IMAGE_DIMENSION: int = int(os.getenv("MAX_IMAGE_DIMENSION", "4096")) | |
| OCR_ENGINE: str = os.getenv("OCR_ENGINE", "auto").lower() | |
| HOST: str = os.getenv("HOST", "0.0.0.0") | |
| PORT: int = int(os.getenv("PORT", "8000")) | |
| BACKEND_URL: str = os.getenv("BACKEND_URL", "http://localhost:8000") | |
| def validate(cls) -> None: | |
| """Validate critical configuration settings without exposing sensitive values.""" | |
| if not cls.NVIDIA_API_KEY: | |
| logger.warning( | |
| "NVIDIA_API_KEY is not set. Requests to LLM document intelligence will fail until configured." | |
| ) | |
| else: | |
| logger.info("NVIDIA_API_KEY is configured (length: %d chars)", len(cls.NVIDIA_API_KEY)) | |
| logger.info("Using NVIDIA Model: %s", cls.NVIDIA_MODEL) | |
| logger.info("NVIDIA Base URL: %s", cls.NVIDIA_BASE_URL) | |
| logger.info("Max Image Size: %.1f MB", cls.MAX_IMAGE_SIZE_MB) | |
| settings = Settings() | |