Edwin Salguero commited on
Commit ·
21e47a6
1
Parent(s): 15d6ce7
Rewrite streamlit_app.py as a clean, robust Streamlit Cloud entry point
Browse files123456789234512678910111213141516151617181819202121222324252627282930313233343536373839404142434445464748495051522223245425565726585960#!/usr/bin/env python3"""FRED ML - Economic Analytics PlatformStreamlit Cloud Deployment Entry Point"""
import sysimport osimport streamlit as st"""Entry‐point for Streamlit Cloud deployment."""import os, sysfrom dotenv import load_dotenv
# Load environment variables from .env file# 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)
# Check for FRED API keyfred_key = os.getenv("FRED_API_KEY") or st.secrets.get("FRED_API_KEY")# 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 st st.error("❌ FRED API not available. Please configure your FRED API 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 None
try: # Import only the main function to avoid loading unnecessary modules from frontend.app import main print("Successfully imported main function from frontend.app")except ImportError as e: print(f"Error importing from frontend.app: {e}") try: # Fallback: try importing directly from app import main print("Successfully imported main function from app") except ImportError as e2: print(f"Error importing from app: {e2}") # Last resort: define a simple main function def 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")# 4) Import and run your real appfrom frontend.app import main as app_main
# Run the main function directlyif __name__ == "__main__": if main is not None: main() app_main() else: st.error("Failed to import main application. Please check the deployment.") st.info("Contact support if this issue persists.") streamlit_app.py+16-50