Edwin Salguero
commited on
Commit
·
48056ef
1
Parent(s):
04ccda7
Add diagnostic version of streamlit_app.py to isolate FRED API key issues in Streamlit Cloud
Browse files- streamlit_app.py +41 -18
streamlit_app.py
CHANGED
@@ -1,26 +1,49 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
-
"""
|
3 |
import os, sys
|
|
|
4 |
from dotenv import load_dotenv
|
5 |
|
6 |
# 1) Load .env (locally) and merge in Streamlit secrets
|
7 |
-
load_dotenv()
|
8 |
-
from streamlit import secrets # for Cloud
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
sys.path.insert(0, os.path.join(HERE, "frontend"))
|
13 |
-
sys.path.insert(0, HERE)
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
st.stop()
|
21 |
|
22 |
-
#
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
+
"""Diagnostic entry‐point for Streamlit Cloud deployment."""
|
3 |
import os, sys
|
4 |
+
import streamlit as st
|
5 |
from dotenv import load_dotenv
|
6 |
|
7 |
# 1) Load .env (locally) and merge in Streamlit secrets
|
8 |
+
load_dotenv() # Local .env, no-op on Cloud
|
|
|
9 |
|
10 |
+
st.write("🌱 os.environ keys with 'FRED': ", [k for k in os.environ if "FRED" in k])
|
11 |
+
st.write("🌱 st.secrets keys: ", list(st.secrets.keys()))
|
|
|
|
|
12 |
|
13 |
+
# Now fetch the key from both places
|
14 |
+
env_key = os.getenv("FRED_API_KEY")
|
15 |
+
secrets_key = st.secrets.get("FRED_API_KEY")
|
16 |
+
st.write("🌱 os.getenv FRED_API_KEY:", env_key or "‹None›")
|
17 |
+
st.write("🌱 st.secrets FRED_API_KEY:", secrets_key or "‹None›")
|
|
|
18 |
|
19 |
+
# Test FRED API call if we have a key
|
20 |
+
fred_key = env_key or secrets_key
|
21 |
+
if fred_key:
|
22 |
+
try:
|
23 |
+
from fredapi import Fred
|
24 |
+
fred = Fred(api_key=fred_key)
|
25 |
+
|
26 |
+
# Quick sanity check:
|
27 |
+
pts = fred.get_series("GDP", observation_start="2020-01-01", observation_end="2020-01-01")
|
28 |
+
st.write("✅ Fetched test point:", pts.iloc[0])
|
29 |
+
st.success("🎉 FRED API connection successful!")
|
30 |
+
|
31 |
+
# If we get here, the API works - let's try the real app
|
32 |
+
st.write("🚀 Attempting to load real app...")
|
33 |
+
|
34 |
+
# 2) Ensure our code is importable
|
35 |
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
36 |
+
sys.path.insert(0, os.path.join(HERE, "frontend"))
|
37 |
+
sys.path.insert(0, HERE)
|
38 |
+
|
39 |
+
# 3) Import and run your real app
|
40 |
+
from frontend.app import main as app_main
|
41 |
+
app_main()
|
42 |
+
|
43 |
+
except Exception as e:
|
44 |
+
st.error(f"🚨 fredapi call failed: {e}")
|
45 |
+
st.stop()
|
46 |
+
else:
|
47 |
+
st.error("❌ No FRED API key found in environment or secrets")
|
48 |
+
st.info("Please configure FRED_API_KEY in Streamlit Cloud secrets")
|
49 |
+
st.stop()
|