Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,10 +20,7 @@ class ConnectionManager:
|
|
| 20 |
def _monitor(self):
|
| 21 |
while not self.stop_event.is_set():
|
| 22 |
try:
|
| 23 |
-
response = requests.get(
|
| 24 |
-
f"{COLAB_URL}/health",
|
| 25 |
-
timeout=5
|
| 26 |
-
)
|
| 27 |
self.active = response.status_code == 200
|
| 28 |
except:
|
| 29 |
self.active = False
|
|
@@ -63,24 +60,19 @@ with gr.Blocks(title="Phi-3 Chatbot") as demo:
|
|
| 63 |
def update_status():
|
| 64 |
return "🟢 Connected" if conn.active else "🔴 Backend offline"
|
| 65 |
|
| 66 |
-
#
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
)
|
| 80 |
-
status.change(
|
| 81 |
-
update_status,
|
| 82 |
-
inputs=None,
|
| 83 |
-
outputs=status
|
| 84 |
)
|
| 85 |
|
| 86 |
chatbot = gr.Chatbot(height=350)
|
|
|
|
| 20 |
def _monitor(self):
|
| 21 |
while not self.stop_event.is_set():
|
| 22 |
try:
|
| 23 |
+
response = requests.get(f"{COLAB_URL}/health", timeout=5)
|
|
|
|
|
|
|
|
|
|
| 24 |
self.active = response.status_code == 200
|
| 25 |
except:
|
| 26 |
self.active = False
|
|
|
|
| 60 |
def update_status():
|
| 61 |
return "🟢 Connected" if conn.active else "🔴 Backend offline"
|
| 62 |
|
| 63 |
+
# Add dummy hidden component for polling
|
| 64 |
+
dummy = gr.Textbox(visible=False)
|
| 65 |
+
|
| 66 |
+
# Set up polling
|
| 67 |
+
def poll_status():
|
| 68 |
+
while True:
|
| 69 |
+
time.sleep(POLL_INTERVAL)
|
| 70 |
+
yield update_status()
|
| 71 |
+
|
| 72 |
+
dummy.change(
|
| 73 |
+
fn=poll_status,
|
| 74 |
+
outputs=status,
|
| 75 |
+
show_progress=False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
)
|
| 77 |
|
| 78 |
chatbot = gr.Chatbot(height=350)
|