File size: 2,605 Bytes
58de40c
 
 
1ed6720
048c3fc
1ed6720
5a007ca
58de40c
 
 
ad1ff58
1ed6720
9ed181c
abaeb0b
1f58459
abaeb0b
0e508c8
1ed6720
 
 
 
 
 
 
 
 
 
9ed181c
1ed6720
 
 
1f58459
 
 
 
 
 
1ed6720
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0e508c8
1ed6720
 
 
048c3fc
5ed9749
048c3fc
1ed6720
 
048c3fc
9ed181c
048c3fc
1ed6720
 
 
 
 
 
 
 
9ed181c
048c3fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Standard Library Imports
import logging
import os
from dataclasses import dataclass
from pathlib import Path
from typing import TYPE_CHECKING, ClassVar, Optional

# Third-Party Library Imports
from dotenv import load_dotenv

# Local Application Imports
if TYPE_CHECKING:
    from src.integrations import AnthropicConfig, ElevenLabsConfig, HumeConfig, OpenAIConfig

logger: logging.Logger = logging.getLogger("expressive_tts_arena")


@dataclass(frozen=True)
class Config:
    _config: ClassVar[Optional["Config"]] = None
    app_env: str
    debug: bool
    database_url: Optional[str]
    audio_dir: Path
    anthropic_config: "AnthropicConfig"
    hume_config: "HumeConfig"
    elevenlabs_config: "ElevenLabsConfig"
    openai_config: "OpenAIConfig"

    @classmethod
    def get(cls) -> "Config":
        if cls._config:
            return cls._config

        _config = Config._init()
        cls._config = _config
        return _config

    @staticmethod
    def _init():
        app_env = os.getenv("APP_ENV", "dev").lower()
        if app_env not in {"dev", "prod"}:
            app_env = "dev"

        # In development, load environment variables from .env file (not used in production)
        if app_env == "dev" and Path(".env").exists():
            load_dotenv(".env", override=True)

        # Enable debug mode if in development (or if explicitly set in env variables)
        debug = app_env == "dev" or os.getenv("DEBUG", "false").lower() == "true"

        database_url = os.getenv("DATABASE_URL")

        # Configure the logger
        logging.basicConfig(
            level=logging.DEBUG if debug else logging.INFO,
            format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
        )
        logger.info(f'App running in "{app_env}" mode.')
        logger.info(f"Debug mode is {'enabled' if debug else 'disabled'}.")

        # Define the directory for audio files relative to the project root
        audio_dir = Path.cwd() / "static" / "audio"
        audio_dir.mkdir(parents=True, exist_ok=True)

        logger.debug(f"Audio directory set to {audio_dir}")

        if debug:
            logger.debug("DEBUG mode enabled.")

        from src.integrations import AnthropicConfig, ElevenLabsConfig, HumeConfig, OpenAIConfig

        return Config(
            app_env=app_env,
            debug=debug,
            database_url=database_url,
            audio_dir=audio_dir,
            anthropic_config=AnthropicConfig(),
            hume_config=HumeConfig(),
            elevenlabs_config=ElevenLabsConfig(),
            openai_config=OpenAIConfig(),
        )