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- frontend/app.py +5 -15
- 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 |
-
#
|
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 |
-
|
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
|
105 |
-
FRED_API_AVAILABLE =
|
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 |
-
"""
|
3 |
-
import
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|