Neetika Saxena
commited on
Commit
Β·
afaa9de
1
Parent(s):
573e464
Add server availability retry logic with graceful startup handling
Browse files
app.py
CHANGED
|
@@ -671,14 +671,24 @@ if "session_id" not in st.session_state:
|
|
| 671 |
</div>
|
| 672 |
""", unsafe_allow_html=True)
|
| 673 |
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 682 |
|
| 683 |
# Create two-column layout with proper sizing
|
| 684 |
col_left, col_right = st.columns([1, 1.2], gap="large")
|
|
|
|
| 671 |
</div>
|
| 672 |
""", unsafe_allow_html=True)
|
| 673 |
|
| 674 |
+
# Check server availability with retries
|
| 675 |
+
max_retries = 5
|
| 676 |
+
retry_delay = 2 # seconds
|
| 677 |
+
server_ready = False
|
| 678 |
+
|
| 679 |
+
for attempt in range(max_retries):
|
| 680 |
+
try:
|
| 681 |
+
if requests.get(f"{st.secrets.server.ip_address}/", timeout=5).status_code == 200:
|
| 682 |
+
server_ready = True
|
| 683 |
+
break
|
| 684 |
+
except:
|
| 685 |
+
if attempt < max_retries - 1:
|
| 686 |
+
st.info(f"π Initializing services... ({attempt + 1}/{max_retries})")
|
| 687 |
+
import time
|
| 688 |
+
time.sleep(retry_delay)
|
| 689 |
+
else:
|
| 690 |
+
st.error("π« Server is not reachable. Please check your connection or server status.", icon="π")
|
| 691 |
+
st.stop()
|
| 692 |
|
| 693 |
# Create two-column layout with proper sizing
|
| 694 |
col_left, col_right = st.columns([1, 1.2], gap="large")
|