Edwin Salguero commited on
Commit
c2c9316
·
1 Parent(s): 8d5bb7d

Final consolidation: replace load_config() with clean, consolidated version that properly sets both REAL_DATA_MODE and FRED_API_AVAILABLE

Browse files
Files changed (1) hide show
  1. frontend/app.py +22 -18
frontend/app.py CHANGED
@@ -82,32 +82,36 @@ def load_fred_client():
82
 
83
  # Lazy import configuration
84
  def load_config():
85
- """Load configuration only when needed"""
 
 
 
86
  global CONFIG_AVAILABLE, FRED_API_KEY, REAL_DATA_MODE, FRED_API_AVAILABLE
87
-
88
- # pull from env or secrets
89
- fred_key = os.getenv('FRED_API_KEY')
90
  if not fred_key:
91
  fred_key = st.secrets.get("FRED_API_KEY", "")
92
- FRED_API_KEY = fred_key or ''
93
- REAL_DATA_MODE = bool(FRED_API_KEY and FRED_API_KEY != 'your-fred-api-key-here')
94
- # Now mark the client available whenever we have a valid key
95
- FRED_API_AVAILABLE = REAL_DATA_MODE
96
- print(f"DEBUG: load_config() - Updated FRED_API_KEY = {FRED_API_KEY}")
97
- print(f"DEBUG: load_config() - Updated REAL_DATA_MODE = {REAL_DATA_MODE}")
98
- print(f"DEBUG: load_config() - Updated FRED_API_AVAILABLE = {FRED_API_AVAILABLE}")
99
-
 
100
  try:
101
  from config import Config
102
  CONFIG_AVAILABLE = True
103
- if not fred_key:
104
- fred_key = Config.get_fred_api_key()
105
- FRED_API_KEY = fred_key
106
- REAL_DATA_MODE = Config.validate_fred_api_key() if fred_key else False
107
- return True
 
108
  except ImportError:
109
  CONFIG_AVAILABLE = False
110
- return False
111
 
112
  # Custom CSS for enterprise styling
113
  st.markdown("""
 
82
 
83
  # Lazy import configuration
84
  def load_config():
85
+ """
86
+ Pull in your FRED key (from env or Streamlit secrets),
87
+ then flip both REAL_DATA_MODE and FRED_API_AVAILABLE.
88
+ """
89
  global CONFIG_AVAILABLE, FRED_API_KEY, REAL_DATA_MODE, FRED_API_AVAILABLE
90
+
91
+ # 1) Try environment first, then Streamlit secrets
92
+ fred_key = os.getenv("FRED_API_KEY", "")
93
  if not fred_key:
94
  fred_key = st.secrets.get("FRED_API_KEY", "")
95
+ # 2) Normalize
96
+ FRED_API_KEY = fred_key.strip()
97
+ # 3) Determine modes
98
+ REAL_DATA_MODE = bool(FRED_API_KEY and FRED_API_KEY != "your-fred-api-key-here")
99
+ FRED_API_AVAILABLE = REAL_DATA_MODE # ensure downstream checks pass
100
+
101
+ print(f"DEBUG load_config FRED_API_KEY={FRED_API_KEY}, REAL_DATA_MODE={REAL_DATA_MODE}, FRED_API_AVAILABLE={FRED_API_AVAILABLE}")
102
+
103
+ # 4) Optionally load additional Config class if you have one
104
  try:
105
  from config import Config
106
  CONFIG_AVAILABLE = True
107
+ if not REAL_DATA_MODE:
108
+ # fallback to config file
109
+ cfg_key = Config.get_fred_api_key()
110
+ if cfg_key:
111
+ FRED_API_KEY = cfg_key
112
+ REAL_DATA_MODE = FRED_API_AVAILABLE = True
113
  except ImportError:
114
  CONFIG_AVAILABLE = False
 
115
 
116
  # Custom CSS for enterprise styling
117
  st.markdown("""