Spaces:
Running
Running
| """Configuration module for the multi-utility server.""" | |
| from typing import List, Set | |
| from pydantic import computed_field, field_validator | |
| from pydantic_settings import BaseSettings | |
| class Settings(BaseSettings): | |
| """Application settings loaded from environment variables.""" | |
| # API Security - no default keys for security | |
| api_keys: str = "" | |
| # CORS Configuration | |
| cors_origins: str = "" | |
| # Rate Limiting | |
| rate_limit_requests: int = 100 | |
| rate_limit_window: int = 60 | |
| # Logging | |
| log_level: str = "INFO" | |
| # yt-dlp configuration | |
| yt_dlp_timeout_download: int = 120 | |
| # Whisper configuration | |
| whisper_model: str = "base" | |
| # Embedding configuration | |
| embedding_model: str = "mixedbread-ai/mxbai-embed-large-v1" | |
| # Server configuration | |
| host: str = "0.0.0.0" | |
| port: int = 8000 | |
| reload: bool = False | |
| model_config = {"env_file": ".env", "env_file_encoding": "utf-8"} | |
| def api_keys_set(self) -> Set[str]: | |
| """Get API keys as a set.""" | |
| if not self.api_keys: | |
| return set() | |
| return {key.strip() for key in self.api_keys.split(",") if key.strip()} | |
| def cors_origins_list(self) -> List[str]: | |
| """Get CORS origins as a list.""" | |
| if not self.cors_origins: | |
| return ["*"] | |
| return [ | |
| origin.strip() for origin in self.cors_origins.split(",") if origin.strip() | |
| ] | |
| def validate_log_level(cls, v: str) -> str: | |
| """Validate log level.""" | |
| valid_levels = {"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"} | |
| upper_v = v.upper() | |
| if upper_v not in valid_levels: | |
| raise ValueError(f"Invalid log level: {v}. Must be one of {valid_levels}") | |
| return upper_v | |
| settings = Settings() | |