SivaRohith69 commited on
Commit
7856594
Β·
1 Parent(s): d8180cd

fix: make Streamlit startup resilient - handle import failures gracefully

Browse files
Files changed (3) hide show
  1. Dockerfile +21 -1
  2. app.py +6 -1
  3. backend/firebase_auth.py +1 -1
Dockerfile CHANGED
@@ -43,6 +43,7 @@ ENV USE_SUPABASE=true
43
  RUN echo '#!/bin/bash\n\
44
  set -e\n\
45
  \n\
 
46
  echo "=== FocusFlow Startup ===" \n\
47
  \n\
48
  # Wait for DNS/networking to be ready (HF Spaces can be slow)\n\
@@ -72,9 +73,28 @@ RUN echo '#!/bin/bash\n\
72
  sleep 1\n\
73
  done\n\
74
  \n\
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  # Start Streamlit frontend\n\
76
  echo "Starting frontend on port 8501..." \n\
77
- exec streamlit run app.py --server.port 8501 --server.address 0.0.0.0 --server.headless true\n\
78
  ' > /app/start.sh && chmod +x /app/start.sh
79
 
80
  # Run startup script
 
43
  RUN echo '#!/bin/bash\n\
44
  set -e\n\
45
  \n\
46
+ echo "===== Application Startup at $(date) =====" \n\
47
  echo "=== FocusFlow Startup ===" \n\
48
  \n\
49
  # Wait for DNS/networking to be ready (HF Spaces can be slow)\n\
 
73
  sleep 1\n\
74
  done\n\
75
  \n\
76
+ # Test critical imports before launching Streamlit\n\
77
+ echo "Testing Python imports..." \n\
78
+ python3 -c "\n\
79
+ import sys\n\
80
+ try:\n\
81
+ import streamlit; print(\" βœ… streamlit\")\n\
82
+ except Exception as e: print(f\" ❌ streamlit: {e}\"); sys.exit(1)\n\
83
+ try:\n\
84
+ import requests; print(\" βœ… requests\")\n\
85
+ except Exception as e: print(f\" ❌ requests: {e}\")\n\
86
+ try:\n\
87
+ from streamlit_calendar import calendar; print(\" βœ… streamlit_calendar\")\n\
88
+ except Exception as e: print(f\" ❌ streamlit_calendar: {e}\")\n\
89
+ try:\n\
90
+ import firebase_admin; print(\" βœ… firebase_admin\")\n\
91
+ except Exception as e: print(f\" ❌ firebase_admin: {e}\")\n\
92
+ print(\"Import check complete.\")\n\
93
+ "\n\
94
+ \n\
95
  # Start Streamlit frontend\n\
96
  echo "Starting frontend on port 8501..." \n\
97
+ exec streamlit run app.py --server.port 8501 --server.address 0.0.0.0 --server.headless true 2>&1\n\
98
  ' > /app/start.sh && chmod +x /app/start.sh
99
 
100
  # Run startup script
app.py CHANGED
@@ -4,7 +4,12 @@ import pandas as pd
4
  import plotly.express as px
5
  import time
6
  import streamlit.components.v1 as components
7
- from streamlit_calendar import calendar
 
 
 
 
 
8
  from datetime import date
9
  import os
10
 
 
4
  import plotly.express as px
5
  import time
6
  import streamlit.components.v1 as components
7
+ try:
8
+ from streamlit_calendar import calendar as st_calendar
9
+ _HAS_CALENDAR = True
10
+ except ImportError:
11
+ _HAS_CALENDAR = False
12
+ st_calendar = None
13
  from datetime import date
14
  import os
15
 
backend/firebase_auth.py CHANGED
@@ -35,7 +35,7 @@ def _init_firebase():
35
  logger.info("βœ… Firebase Admin SDK initialized successfully.")
36
  except Exception as e:
37
  logger.error(f"❌ Failed to initialize Firebase Admin SDK: {e}")
38
- raise
39
 
40
  # Run initialization at module load time
41
  _init_firebase()
 
35
  logger.info("βœ… Firebase Admin SDK initialized successfully.")
36
  except Exception as e:
37
  logger.error(f"❌ Failed to initialize Firebase Admin SDK: {e}")
38
+ # Don't raise β€” allow app to start without Firebase auth
39
 
40
  # Run initialization at module load time
41
  _init_firebase()