Edwin Salguero commited on
Commit
44508a2
·
1 Parent(s): 9c8effd

Rewrite streamlit_app.py as a clean, robust Streamlit Cloud entry point

Browse files
Files changed (1) hide show
  1. streamlit_app.py +16 -50
streamlit_app.py CHANGED
@@ -1,60 +1,26 @@
1
  #!/usr/bin/env python3
2
- """
3
- FRED ML - Economic Analytics Platform
4
- Streamlit Cloud Deployment Entry Point
5
- """
6
-
7
- import sys
8
- import os
9
- import streamlit as st
10
  from dotenv import load_dotenv
11
 
12
- # Load environment variables from .env file
13
  load_dotenv()
 
 
 
 
 
 
14
 
15
- # Check for FRED API key
16
- fred_key = os.getenv("FRED_API_KEY") or st.secrets.get("FRED_API_KEY")
17
  if not fred_key:
18
- st.error("❌ FRED API not available. Please configure your FRED API key.")
 
19
  st.stop()
20
 
21
- # Add debug print
22
- st.write(f"🔑 FRED API Key loaded: {fred_key[:8]}...")
23
-
24
- # Add the frontend directory to the path
25
- current_dir = os.path.dirname(os.path.abspath(__file__))
26
- frontend_dir = os.path.join(current_dir, 'frontend')
27
- if frontend_dir not in sys.path:
28
- sys.path.insert(0, frontend_dir)
29
-
30
- # Add the current directory to the path as well
31
- if current_dir not in sys.path:
32
- sys.path.insert(0, current_dir)
33
-
34
- main = None # Initialize main as None
35
-
36
- try:
37
- # Import only the main function to avoid loading unnecessary modules
38
- from frontend.app import main
39
- print("Successfully imported main function from frontend.app")
40
- except ImportError as e:
41
- print(f"Error importing from frontend.app: {e}")
42
- try:
43
- # Fallback: try importing directly
44
- from app import main
45
- print("Successfully imported main function from app")
46
- except ImportError as e2:
47
- print(f"Error importing from app: {e2}")
48
- # Last resort: define a simple main function
49
- def main():
50
- st.error("Failed to import main application. Please check the deployment.")
51
- st.info("Contact support if this issue persists.")
52
- print("Using fallback main function")
53
 
54
- # Run the main function directly
55
  if __name__ == "__main__":
56
- if main is not None:
57
- main()
58
- else:
59
- st.error("Failed to import main application. Please check the deployment.")
60
- st.info("Contact support if this issue persists.")
 
1
  #!/usr/bin/env python3
2
+ """Entry‐point for Streamlit Cloud deployment."""
3
+ import os, sys
 
 
 
 
 
 
4
  from dotenv import load_dotenv
5
 
6
+ # 1) Load .env (locally) and merge in Streamlit secrets
7
  load_dotenv()
8
+ from streamlit import secrets # for Cloud
9
+
10
+ # 2) Ensure our code is importable
11
+ HERE = os.path.dirname(os.path.abspath(__file__))
12
+ sys.path.insert(0, os.path.join(HERE, "frontend"))
13
+ sys.path.insert(0, HERE)
14
 
15
+ # 3) Get the FRED key from env or Streamlit secrets
16
+ fred_key = os.getenv("FRED_API_KEY") or secrets.get("FRED_API_KEY")
17
  if not fred_key:
18
+ import streamlit as st
19
+ st.error("❌ FRED API not available. Please configure your FRED_API_KEY.")
20
  st.stop()
21
 
22
+ # 4) Import and run your real app
23
+ from frontend.app import main as app_main
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
 
25
  if __name__ == "__main__":
26
+ app_main()