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 lines85868788899091929394959697989910010110210310410510610710884 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 keyfred_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}")passprint("DEBUG: Final FRED_API_KEY =", fred_key)# Update global variablesFRED_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 availableFRED_API_AVAILABLE = bool(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}")84 unmodified lines858687888990919293949596979884 unmodified lines"""Load configuration only when needed"""global CONFIG_AVAILABLE, FRED_API_KEY, REAL_DATA_MODE, FRED_API_AVAILABLE# pull from env or secretsfred_key = os.getenv('FRED_API_KEY')if not fred_key:fred_key = st.secrets.get("FRED_API_KEY", "")FRED_API_KEY = fred_key or ''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 keyFRED_API_AVAILABLE = REAL_DATA_MODEprint(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}")
12345678#!/usr/bin/env python3"""Diagnostic wrapper to verify Streamlit secrets."""import os, streamlit as stst.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()12345678910111213141516#!/usr/bin/env python3"""Streamlit-native entry point for Streamlit Cloud deployment."""import streamlit as st, os# **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