ShabanEjupi commited on
Commit
3c42841
·
verified ·
1 Parent(s): ce63348

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -22
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
- # Periodically update status
67
- demo.load(
68
- lambda: None,
69
- inputs=None,
70
- outputs=None,
71
- _js="""
72
- function() {
73
- setInterval(() => {
74
- document.getElementById('status').dispatchEvent(new Event('change'));
75
- }, 3000);
76
- return [];
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)