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 filesFiles changed (2)
- frontend/app.py+5-15
- streamlit_app.py+14-6
84 unmodified lines85868788888990909293949596979899100101919210310410593949596979884 unmodified lines """Load configuration only when needed""" global CONFIG_AVAILABLE, FRED_API_KEY, REAL_DATA_MODE, FRED_API_AVAILABLE # Try multiple sources for FRED API key # pull from env or secrets fred_key = os.getenv('FRED_API_KEY') print(f"DEBUG: load_config() - FRED_API_KEY from os.getenv = {fred_key}") if not fred_key: try: fred_key = st.secrets["FRED_API_KEY"] print(f"DEBUG: load_config() - FRED_API_KEY from st.secrets = {fred_key}") except Exception as e: print(f"DEBUG: load_config() - Error getting from st.secrets: {e}") pass print("DEBUG: Final FRED_API_KEY =", fred_key) # Update global variables fred_key = st.secrets.get("FRED_API_KEY", "") FRED_API_KEY = fred_key or '' REAL_DATA_MODE = FRED_API_KEY and FRED_API_KEY != 'your-fred-api-key-here' # Now that we know the key exists, mark the API client as available FRED_API_AVAILABLE = bool(REAL_DATA_MODE) REAL_DATA_MODE = bool(FRED_API_KEY and FRED_API_KEY != 'your-fred-api-key-here') # Now mark the client available whenever we have a valid key FRED_API_AVAILABLE = REAL_DATA_MODE print(f"DEBUG: load_config() - Updated FRED_API_KEY = {FRED_API_KEY}") print(f"DEBUG: load_config() - Updated REAL_DATA_MODE = {REAL_DATA_MODE}") print(f"DEBUG: load_config() - Updated FRED_API_AVAILABLE = {FRED_API_AVAILABLE}")12323456785678910111213141516#!/usr/bin/env python3"""Diagnostic wrapper to verify Streamlit secrets."""import os, streamlit as st"""Streamlit-native entry point for Streamlit Cloud deployment."""import streamlit as st, os
st.write("๐ os.environ:", {k: v for k, v in os.environ.items() if "FRED" in k})st.write("๐ st.secrets:", list(st.secrets.keys()))st.write("๐ st.secrets FRED_API_KEY:", st.secrets.get("FRED_API_KEY", "NOT_FOUND"))st.stop() # **no** load_dotenv() herefred_key = st.secrets["FRED_API_KEY"]if not fred_key: st.error("โ FRED API key not found in Streamlit secrets.") st.stop()
# make it available to downstream codeos.environ["FRED_API_KEY"] = fred_key
# now import and run your real appfrom frontend.app import main as app_mainapp_main() frontend/app.py+5-15
streamlit_app.py+14-6