lordofgaming commited on
Commit
f4c683f
·
1 Parent(s): 027fce5

App reliability: Backend health check, Force Dark Theme, Fix Dependencies

Browse files
.streamlit/config.toml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ [theme]
2
+ base="dark"
3
+ primaryColor="#ff0033"
4
+ backgroundColor="#000000"
5
+ secondaryBackgroundColor="#0a0a0a"
6
+ textColor="#ffffff"
7
+ font="sans serif"
frontend/streamlit_app.py CHANGED
@@ -4,6 +4,8 @@ Premium Speech-to-Text & Text-to-Speech Interface
4
  """
5
 
6
  import streamlit as st
 
 
7
  from pathlib import Path
8
  from services.api_client import get_api_client
9
 
@@ -611,12 +613,50 @@ def render_sidebar():
611
  st.session_state.theme = new_theme
612
  st.rerun()
613
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
614
  # Main app
615
  def main():
616
  """Main application entry point"""
617
  load_css()
618
  init_session_state()
619
  render_sidebar()
 
 
 
 
 
620
  render_home()
621
 
622
 
 
4
  """
5
 
6
  import streamlit as st
7
+ import time
8
+ import requests
9
  from pathlib import Path
10
  from services.api_client import get_api_client
11
 
 
613
  st.session_state.theme = new_theme
614
  st.rerun()
615
 
616
+ # Check backend health
617
+ def check_backend_health():
618
+ """Check if backend is reachable"""
619
+ api_url = st.session_state.get("api_base_url", "http://localhost:8001")
620
+ health_url = f"{api_url}/health"
621
+
622
+ # Try 3 times with short delay
623
+ for i in range(3):
624
+ try:
625
+ response = requests.get(health_url, timeout=2)
626
+ if response.status_code == 200:
627
+ return True
628
+ except requests.exceptions.ConnectionError:
629
+ pass
630
+ except Exception as e:
631
+ # Other errors (timeout, etc)
632
+ pass
633
+ time.sleep(1)
634
+
635
+ # If we get here, backend is likely starting or down
636
+ st.warning("⏳ Backend is starting up... (Connection Refused)")
637
+ st.info("The server is on free tier and may take 1-2 minutes to cold start. Please wait and refresh.")
638
+
639
+ # Try one more time with longer timeout and spinner
640
+ with st.spinner("Waiting for connection..."):
641
+ try:
642
+ time.sleep(5)
643
+ requests.get(health_url, timeout=5)
644
+ st.rerun() # Success! Rerun app
645
+ return True
646
+ except:
647
+ return False
648
+
649
  # Main app
650
  def main():
651
  """Main application entry point"""
652
  load_css()
653
  init_session_state()
654
  render_sidebar()
655
+
656
+ # Check backend health
657
+ if not check_backend_health():
658
+ st.stop()
659
+
660
  render_home()
661
 
662