Edwin Salguero commited on
Commit
50a66f8
·
1 Parent(s): b204d55

Fix Streamlit Cloud deployment import issue - Added robust import handling with fallbacks - Added current directory to Python path - Added error handling for import failures - Improved debugging output for deployment troubleshooting

Browse files
Files changed (1) hide show
  1. streamlit_app.py +22 -2
streamlit_app.py CHANGED
@@ -13,8 +13,28 @@ frontend_dir = os.path.join(current_dir, 'frontend')
13
  if frontend_dir not in sys.path:
14
  sys.path.insert(0, frontend_dir)
15
 
16
- # Import only the main function to avoid loading unnecessary modules
17
- from app import main
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  # Run the main function directly
20
  if __name__ == "__main__":
 
13
  if frontend_dir not in sys.path:
14
  sys.path.insert(0, frontend_dir)
15
 
16
+ # Add the current directory to the path as well
17
+ if current_dir not in sys.path:
18
+ sys.path.insert(0, current_dir)
19
+
20
+ try:
21
+ # Import only the main function to avoid loading unnecessary modules
22
+ from frontend.app import main
23
+ print("Successfully imported main function from frontend.app")
24
+ except ImportError as e:
25
+ print(f"Error importing from frontend.app: {e}")
26
+ try:
27
+ # Fallback: try importing directly
28
+ from app import main
29
+ print("Successfully imported main function from app")
30
+ except ImportError as e2:
31
+ print(f"Error importing from app: {e2}")
32
+ # Last resort: define a simple main function
33
+ import streamlit as st
34
+ def main():
35
+ st.error("Failed to import main application. Please check the deployment.")
36
+ st.info("Contact support if this issue persists.")
37
+ print("Using fallback main function")
38
 
39
  # Run the main function directly
40
  if __name__ == "__main__":