File size: 1,740 Bytes
9bc1376
 
 
 
 
7dc1789
 
9bc1376
 
 
15063fc
3d81e4d
 
 
 
 
 
15063fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9bc1376
 
 
 
 
 
178a27b
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
import os
from typing import Dict, Any, Optional

from dotenv import dotenv_values
from pydantic import BaseModel, ConfigDict
from pydantic_settings import BaseSettings




def load_env_config():
    # Try to load from .env file first, then fall back to environment variables
    env_file_config = dotenv_values()
    env_vars = dict(os.environ)
    
    # Merge .env file values with environment variables (env vars take precedence)
    return {**env_file_config, **env_vars}


def get_config() -> Dict[str, Any]:
    env_config = load_env_config()

    config_model = GlobalConfig.model_construct()


    final_config = {**config_model.model_dump(), **env_config}

    return final_config

class AppConfig(BaseModel):
    """Application configurations."""

    app_name: str = "Creative AdGenesis"
    app_version: str = "0.1.0"
    app_description: str = (
        "Creative AdGenesis"
    )
    debug_mode: bool = False


class GlobalConfig(BaseSettings):
    """Typed global core object."""
    APP_CONFIG: AppConfig = AppConfig()
    model_config = ConfigDict(extra="ignore")

    # Environment
    APP_ENV: Optional[str] = "dev"
    DEBUG: Optional[bool] = False

    MONGO_DB: Optional[str] = None
    MONGO_URI: Optional[str] = None


    # Cloudflare R2
    R2_BUCKET_NAME: Optional[str] = None
    R2_ACCESS_KEY: Optional[str] = None
    R2_SECRET_KEY: Optional[str] = None
    R2_ENDPOINT: Optional[str] = None


    # OpenAI
    OPENAI_API_KEY: Optional[str] = None

    # Replicate
    REPLICATE_API_KEY: Optional[str] = None
    GEMINI_API_KEY:  Optional[str] = None


    # Custom
    NEW_BASE: Optional[str] = None

# Load configurations
config_data = get_config()
cnf = GlobalConfig(**config_data)
app_cnf = cnf.APP_CONFIG