|
|
""" |
|
|
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""" |
|
|
|
|
|
|
|
|
ENV: str = "development" |
|
|
|
|
|
|
|
|
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_URL: str = "redis://localhost:6379" |
|
|
|
|
|
|
|
|
MAX_VIDEO_SIZE_MB: int = 50 |
|
|
MAX_VIDEO_DURATION_SECONDS: int = 60 |
|
|
TEMP_DIR: str = "./temp" |
|
|
MODELS_DIR: str = "./models" |
|
|
|
|
|
|
|
|
TASK_TIMEOUT_SECONDS: int = 900 |
|
|
TASK_RESULT_TTL_SECONDS: int = 3600 |
|
|
TASK_QUEUE_NAME: str = "swara:tasks" |
|
|
|
|
|
|
|
|
RATE_LIMIT_REQUESTS: int = 10 |
|
|
RATE_LIMIT_PERIOD_SECONDS: int = 3600 |
|
|
|
|
|
|
|
|
LOG_LEVEL: str = "INFO" |
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
|
|
|
settings = get_settings() |
|
|
|