userIdc2024 commited on
Commit
15063fc
·
verified ·
1 Parent(s): 162df7b

Update core/settings.py

Browse files
Files changed (1) hide show
  1. core/settings.py +76 -1
core/settings.py CHANGED
@@ -14,7 +14,82 @@ def load_json_config(json_file: str) -> Dict[str, Any]:
14
  try:
15
  file_path = os.path.join('/mnt/secrets-store', json_file)
16
  if os.path.exists(file_path):
17
- logger.info(f"The file is located at: {file_path}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  else:
19
  logger.error("JSON file not found.")
20
  except FileNotFoundError:
 
14
  try:
15
  file_path = os.path.join('/mnt/secrets-store', json_file)
16
  if os.path.exists(file_path):
17
+ logger.info(f"The file from dataclasses import dataclass
18
+ import os
19
+ import os
20
+ from typing import Dict, Any, Optional
21
+
22
+ from dotenv import dotenv_values
23
+ from pydantic import BaseModel, ConfigDict
24
+ from pydantic_settings import BaseSettings, JsonConfigSettingsSource
25
+
26
+ from core.logger import logger
27
+
28
+
29
+ def load_env_config():
30
+ if GlobalConfig().APP_ENV == "dev":
31
+ return dotenv_values()
32
+ else:
33
+ return dict(os.environ)
34
+
35
+
36
+ def get_config() -> Dict[str, Any]:
37
+ env_config = load_env_config()
38
+
39
+ config_model = GlobalConfig.model_construct()
40
+
41
+
42
+ final_config = {**config_model.model_dump(), **env_config}
43
+
44
+ return final_config
45
+
46
+ class AppConfig(BaseModel):
47
+ """Application configurations."""
48
+
49
+ app_name: str = "Creative AdGenesis"
50
+ app_version: str = "0.1.0"
51
+ app_description: str = (
52
+ "Creative AdGenesis"
53
+ )
54
+ debug_mode: bool = False
55
+
56
+
57
+ class GlobalConfig(BaseSettings):
58
+ """Typed global core object."""
59
+ APP_CONFIG: AppConfig = AppConfig()
60
+ model_config = ConfigDict(extra="ignore")
61
+
62
+ # Environment
63
+ APP_ENV: Optional[str] = "dev"
64
+ DEBUG: Optional[bool] = False
65
+
66
+ MONGO_DB: Optional[str] = None
67
+ MONGO_URI: Optional[str] = None
68
+
69
+
70
+ # Cloudflare R2
71
+ R2_BUCKET_NAME: Optional[str] = None
72
+ R2_ACCESS_KEY: Optional[str] = None
73
+ R2_SECRET_KEY: Optional[str] = None
74
+ R2_ENDPOINT: Optional[str] = None
75
+
76
+
77
+ # OpenAI
78
+ OPENAI_API_KEY: Optional[str] = None
79
+
80
+ # Replicate
81
+ REPLICATE_API_KEY: Optional[str] = None
82
+ GEMINI_API_KEY: Optional[str] = None
83
+
84
+
85
+ # Custom
86
+ NEW_BASE: Optional[str] = None
87
+
88
+ # Load configurations
89
+ config_data = get_config()
90
+ cnf = GlobalConfig(**config_data)
91
+ app_cnf = cnf.APP_CONFIG
92
+ is located at: {file_path}")
93
  else:
94
  logger.error("JSON file not found.")
95
  except FileNotFoundError: