Edwin Salguero
commited on
Commit
Β·
378ea47
1
Parent(s):
2cebf25
Add FRED API key validation at app startup and improve environment variable loading
Browse files- frontend/app.py +10 -0
- streamlit_app.py +14 -2
frontend/app.py
CHANGED
@@ -425,6 +425,16 @@ def create_forecast_plot(historical_data, forecast_data, title="Forecast"):
|
|
425 |
def main():
|
426 |
"""Main Streamlit application"""
|
427 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
# Show loading indicator
|
429 |
with st.spinner("π Initializing FRED ML Platform..."):
|
430 |
# Load configuration
|
|
|
425 |
def main():
|
426 |
"""Main Streamlit application"""
|
427 |
|
428 |
+
# Check for FRED API key first
|
429 |
+
fred_key = os.getenv("FRED_API_KEY") or st.secrets.get("FRED_API_KEY")
|
430 |
+
if not fred_key:
|
431 |
+
st.error("β FRED API not available. Please configure your FRED API key.")
|
432 |
+
st.info("Get a free FRED API key at: https://fred.stlouisfed.org/docs/api/api_key.html")
|
433 |
+
st.stop()
|
434 |
+
|
435 |
+
# Add debug print
|
436 |
+
st.write(f"π FRED API Key loaded: {fred_key[:8]}...")
|
437 |
+
|
438 |
# Show loading indicator
|
439 |
with st.spinner("π Initializing FRED ML Platform..."):
|
440 |
# Load configuration
|
streamlit_app.py
CHANGED
@@ -6,6 +6,20 @@ Streamlit Cloud Deployment Entry Point
|
|
6 |
|
7 |
import sys
|
8 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Add the frontend directory to the path
|
11 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
@@ -32,7 +46,6 @@ except ImportError as e:
|
|
32 |
except ImportError as e2:
|
33 |
print(f"Error importing from app: {e2}")
|
34 |
# Last resort: define a simple main function
|
35 |
-
import streamlit as st
|
36 |
def main():
|
37 |
st.error("Failed to import main application. Please check the deployment.")
|
38 |
st.info("Contact support if this issue persists.")
|
@@ -43,6 +56,5 @@ if __name__ == "__main__":
|
|
43 |
if main is not None:
|
44 |
main()
|
45 |
else:
|
46 |
-
import streamlit as st
|
47 |
st.error("Failed to import main application. Please check the deployment.")
|
48 |
st.info("Contact support if this issue persists.")
|
|
|
6 |
|
7 |
import sys
|
8 |
import os
|
9 |
+
import streamlit as st
|
10 |
+
from dotenv import load_dotenv
|
11 |
+
|
12 |
+
# Load environment variables from .env file
|
13 |
+
load_dotenv()
|
14 |
+
|
15 |
+
# Check for FRED API key
|
16 |
+
fred_key = os.getenv("FRED_API_KEY") or st.secrets.get("FRED_API_KEY")
|
17 |
+
if not fred_key:
|
18 |
+
st.error("β FRED API not available. Please configure your FRED API key.")
|
19 |
+
st.stop()
|
20 |
+
|
21 |
+
# Add debug print
|
22 |
+
st.write(f"π FRED API Key loaded: {fred_key[:8]}...")
|
23 |
|
24 |
# Add the frontend directory to the path
|
25 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
46 |
except ImportError as e2:
|
47 |
print(f"Error importing from app: {e2}")
|
48 |
# Last resort: define a simple main function
|
|
|
49 |
def main():
|
50 |
st.error("Failed to import main application. Please check the deployment.")
|
51 |
st.info("Contact support if this issue persists.")
|
|
|
56 |
if main is not None:
|
57 |
main()
|
58 |
else:
|
|
|
59 |
st.error("Failed to import main application. Please check the deployment.")
|
60 |
st.info("Contact support if this issue persists.")
|