Edwin Salguero commited on
Commit ·
864919d
1
Parent(s): 3878dad
Implement Streamlit-native solution: remove dotenv dependency and use st.secrets directly
Browse filesFiles changed (2)
- frontend/app.py+1-3
- streamlit_app.py+10-33
9 unmodified lines101112131415161774 unmodified lines929394959697989 unmodified linesimport sysimport iofrom typing import Dict, List, Optionalfrom dotenv import load_dotenvload_dotenv()import osprint("DEBUG: FRED_API_KEY from os.getenv =", os.getenv('FRED_API_KEY'))74 unmodified linesprint(f"DEBUG: load_config() - FRED_API_KEY from os.getenv = {fred_key}")if not fred_key:try:fred_key = st.secrets.get("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}")9 unmodified lines10111213141574 unmodified lines909192939495969 unmodified linesimport sysimport iofrom typing import Dict, List, Optionalimport osprint("DEBUG: FRED_API_KEY from os.getenv =", os.getenv('FRED_API_KEY'))74 unmodified linesprint(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}")
1234567891011121314151617181920212223242526272829303132333435363738394041424344#!/usr/bin/env python3"""Diagnostic entry‐point for Streamlit Cloud deployment."""import os, sys# CRITICAL: Set environment variable BEFORE importing streamlit# This ensures the key is available when the frontend app imports# 1. Try to get the key from environment firstfred_key = os.getenv("FRED_API_KEY")# 2. If not in environment, we'll get it from Streamlit secrets laterif not fred_key:# Import streamlit only when neededimport streamlit as stfred_key = st.secrets.get("FRED_API_KEY")print(f"DEBUG: FRED_API_KEY from os.getenv = {os.getenv('FRED_API_KEY')}")print(f"DEBUG: Final fred_key = {fred_key}")# 3. Set the environment variable IMMEDIATELYif fred_key:os.environ["FRED_API_KEY"] = fred_keyprint(f"DEBUG: Set FRED_API_KEY in environment = {os.environ.get('FRED_API_KEY')}")else:print("DEBUG: No FRED API key found!")# 4. Now import streamlit and frontend codeimport streamlit as stfrom dotenv import load_dotenv# Load .env locally (no‐op in Cloud)…load_dotenv()# 5. Double-check the key is availableif not os.getenv("FRED_API_KEY"):st.error("❌ FRED API not available. Please configure your FRED_API_KEY.")st.info("Available environment variables: " + str(list(os.environ.keys())))st.info("Available secrets keys: " + str(list(st.secrets.keys())))st.stop()# 6. Now hook up your frontend codeHERE = os.path.dirname(os.path.abspath(__file__))sys.path.insert(0, os.path.join(HERE, "frontend"))from app import main as app_main123456789101112131415161718192021#!/usr/bin/env python3"""Streamlit-native entry point for Streamlit Cloud deployment."""import os, sysimport streamlit as st# Streamlit-native solution: Use st.secrets directlyfred_key = os.getenv("FRED_API_KEY") or st.secrets["FRED_API_KEY"]if not fred_key:st.error("❌ FRED API key not found. Configure it in Streamlit Cloud Secrets.")st.info("Available environment variables: " + str(list(os.environ.keys())))st.info("Available secrets keys: " + str(list(st.secrets.keys())))st.stop()# Set the environment variable for the frontend appos.environ["FRED_API_KEY"] = fred_keyprint(f"DEBUG: Set FRED_API_KEY in environment = {os.environ.get('FRED_API_KEY')}")# Now hook up your frontend codeHERE = os.path.dirname(os.path.abspath(__file__))sys.path.insert(0, os.path.join(HERE, "frontend"))from app import main as app_main
frontend/app.py+1-3
streamlit_app.py+10-33