Spaces:
Sleeping
Sleeping
Enhance application configuration: add MongoDB settings and directory management for audio, text, and temporary files, ensuring necessary directories are created at initialization.
6fae15f
| """Application configuration.""" | |
| import os | |
| from functools import lru_cache | |
| from pydantic_settings import BaseSettings | |
| class Settings(BaseSettings): | |
| """Application settings.""" | |
| # MongoDB settings | |
| MONGO_URI: str = os.getenv("MONGO_URI", "mongodb://localhost:27017") | |
| DB_NAME: str = os.getenv("DB_NAME", "tts_api") | |
| # Storage paths | |
| STORAGE_PATH: str = os.getenv("STORAGE_PATH", "/app/storage") | |
| AUDIO_DIR: str = os.path.join(STORAGE_PATH, "audio") | |
| TEXT_DIR: str = os.path.join(STORAGE_PATH, "text") | |
| TEMP_DIR: str = os.path.join(STORAGE_PATH, "temp") | |
| # Ensure directories exist | |
| def __init__(self, **kwargs): | |
| super().__init__(**kwargs) | |
| os.makedirs(self.AUDIO_DIR, exist_ok=True) | |
| os.makedirs(self.TEXT_DIR, exist_ok=True) | |
| os.makedirs(self.TEMP_DIR, exist_ok=True) | |
| class Config: | |
| """Pydantic config.""" | |
| env_file = ".env" | |
| def get_settings() -> Settings: | |
| """Get cached settings.""" | |
| return Settings() | |
| # Create settings instance | |
| settings = get_settings() | |
| # Export directory paths | |
| AUDIO_DIR = settings.AUDIO_DIR | |
| TEXT_DIR = settings.TEXT_DIR | |
| TEMP_DIR = settings.TEMP_DIR |