""" Configuration Management """ import os from pathlib import Path from typing import Optional from pydantic_settings import BaseSettings from functools import lru_cache class Settings(BaseSettings): """Application Settings""" # Environment ENV: str = "development" # API Configuration API_HOST: str = "0.0.0.0" API_PORT: int = 7860 API_WORKERS: int = 1 API_TITLE: str = "SWARA API" API_VERSION: str = "1.0.0" API_DESCRIPTION: str = "AI-Powered Public Speaking Evaluation API" # Redis Configuration REDIS_URL: str = "redis://localhost:6379" # Processing Configuration MAX_VIDEO_SIZE_MB: int = 50 MAX_VIDEO_DURATION_SECONDS: int = 60 TEMP_DIR: str = "./temp" MODELS_DIR: str = "./models" # Task Configuration TASK_TIMEOUT_SECONDS: int = 900 # 15 minutes untuk sequential processing TASK_RESULT_TTL_SECONDS: int = 3600 # 1 hour TASK_QUEUE_NAME: str = "swara:tasks" # Rate Limiting RATE_LIMIT_REQUESTS: int = 10 RATE_LIMIT_PERIOD_SECONDS: int = 3600 # Logging LOG_LEVEL: str = "INFO" # Model Paths FACIAL_EXPRESSION_MODEL: str = "models/best.onnx" class Config: env_file = ".env" case_sensitive = True def get_temp_dir(self) -> Path: """Get temporary directory path""" path = Path(self.TEMP_DIR) path.mkdir(parents=True, exist_ok=True) return path def get_models_dir(self) -> Path: """Get models directory path""" path = Path(self.MODELS_DIR) path.mkdir(parents=True, exist_ok=True) return path @property def max_video_size_bytes(self) -> int: """Get max video size in bytes""" return self.MAX_VIDEO_SIZE_MB * 1024 * 1024 @lru_cache() def get_settings() -> Settings: """Get cached settings instance""" return Settings() # Global settings instance settings = get_settings()