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

Fix FRED_API_AVAILABLE wiring: set to True when valid key is detected and restore production streamlit_app.py

Browse files
Files changed (2) hide show
  1. frontend/app.py +5 -15
  2. streamlit_app.py +14 -6
frontend/app.py CHANGED
@@ -85,24 +85,14 @@ def load_config():
85
  """Load configuration only when needed"""
86
  global CONFIG_AVAILABLE, FRED_API_KEY, REAL_DATA_MODE, FRED_API_AVAILABLE
87
 
88
- # Try multiple sources for FRED API key
89
  fred_key = os.getenv('FRED_API_KEY')
90
- print(f"DEBUG: load_config() - FRED_API_KEY from os.getenv = {fred_key}")
91
  if not fred_key:
92
- try:
93
- fred_key = st.secrets["FRED_API_KEY"]
94
- print(f"DEBUG: load_config() - FRED_API_KEY from st.secrets = {fred_key}")
95
- except Exception as e:
96
- print(f"DEBUG: load_config() - Error getting from st.secrets: {e}")
97
- pass
98
-
99
- print("DEBUG: Final FRED_API_KEY =", fred_key)
100
-
101
- # Update global variables
102
  FRED_API_KEY = fred_key or ''
103
- REAL_DATA_MODE = FRED_API_KEY and FRED_API_KEY != 'your-fred-api-key-here'
104
- # Now that we know the key exists, mark the API client as available
105
- FRED_API_AVAILABLE = bool(REAL_DATA_MODE)
106
  print(f"DEBUG: load_config() - Updated FRED_API_KEY = {FRED_API_KEY}")
107
  print(f"DEBUG: load_config() - Updated REAL_DATA_MODE = {REAL_DATA_MODE}")
108
  print(f"DEBUG: load_config() - Updated FRED_API_AVAILABLE = {FRED_API_AVAILABLE}")
 
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}")
streamlit_app.py CHANGED
@@ -1,8 +1,16 @@
1
  #!/usr/bin/env python3
2
- """Diagnostic wrapper to verify Streamlit secrets."""
3
- import os, streamlit as st
4
 
5
- st.write("πŸ”‘ os.environ:", {k: v for k, v in os.environ.items() if "FRED" in k})
6
- st.write("πŸ”‘ st.secrets:", list(st.secrets.keys()))
7
- st.write("πŸ”‘ st.secrets FRED_API_KEY:", st.secrets.get("FRED_API_KEY", "NOT_FOUND"))
8
- st.stop()
 
 
 
 
 
 
 
 
 
1
  #!/usr/bin/env python3
2
+ """Streamlit-native entry point for Streamlit Cloud deployment."""
3
+ import streamlit as st, os
4
 
5
+ # **no** load_dotenv() here
6
+ fred_key = st.secrets["FRED_API_KEY"]
7
+ if not fred_key:
8
+ st.error("❌ FRED API key not found in Streamlit secrets.")
9
+ st.stop()
10
+
11
+ # make it available to downstream code
12
+ os.environ["FRED_API_KEY"] = fred_key
13
+
14
+ # now import and run your real app
15
+ from frontend.app import main as app_main
16
+ app_main()