Edwin Salguero commited on
Commit ·
21e47a6
1
Parent(s): 15d6ce7
Rewrite streamlit_app.py as a clean, robust Streamlit Cloud entry point
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960#!/usr/bin/env python3"""FRED ML - Economic Analytics PlatformStreamlit Cloud Deployment Entry Point"""import sysimport osimport streamlit as stfrom dotenv import load_dotenv# Load environment variables from .env fileload_dotenv()# Check for FRED API keyfred_key = os.getenv("FRED_API_KEY") or st.secrets.get("FRED_API_KEY")if not fred_key:st.error("❌ FRED API not available. Please configure your FRED API key.")st.stop()# Add debug printst.write(f"🔑 FRED API Key loaded: {fred_key[:8]}...")# Add the frontend directory to the pathcurrent_dir = os.path.dirname(os.path.abspath(__file__))frontend_dir = os.path.join(current_dir, 'frontend')if frontend_dir not in sys.path:sys.path.insert(0, frontend_dir)# Add the current directory to the path as wellif current_dir not in sys.path:sys.path.insert(0, current_dir)main = None # Initialize main as Nonetry:# Import only the main function to avoid loading unnecessary modulesfrom frontend.app import mainprint("Successfully imported main function from frontend.app")except ImportError as e:print(f"Error importing from frontend.app: {e}")try:# Fallback: try importing directlyfrom app import mainprint("Successfully imported main function from app")except ImportError as e2:print(f"Error importing from app: {e2}")# Last resort: define a simple main functiondef main():st.error("Failed to import main application. Please check the deployment.")st.info("Contact support if this issue persists.")print("Using fallback main function")# Run the main function directlyif __name__ == "__main__":if main is not None:main()else:st.error("Failed to import main application. Please check the deployment.")st.info("Contact support if this issue persists.")1234567891011121314151617181920212223242526#!/usr/bin/env python3"""Entry‐point for Streamlit Cloud deployment."""import os, sysfrom dotenv import load_dotenv# 1) Load .env (locally) and merge in Streamlit secretsload_dotenv()from streamlit import secrets # for Cloud# 2) Ensure our code is importableHERE = os.path.dirname(os.path.abspath(__file__))sys.path.insert(0, os.path.join(HERE, "frontend"))sys.path.insert(0, HERE)# 3) Get the FRED key from env or Streamlit secretsfred_key = os.getenv("FRED_API_KEY") or secrets.get("FRED_API_KEY")if not fred_key:import streamlit as stst.error("❌ FRED API not available. Please configure your FRED_API_KEY.")st.stop()# 4) Import and run your real appfrom frontend.app import main as app_mainif __name__ == "__main__":app_main()
streamlit_app.py+16-50