macadeliccc commited on
Commit
16cd0e3
·
1 Parent(s): de6f23c
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -28,6 +28,7 @@ def start_ochat_server():
28
  except Exception as e:
29
  return f"Failed to start ochat server: {e}"
30
 
 
31
 
32
  async def is_server_running():
33
  async with aiohttp.ClientSession() as session:
@@ -38,19 +39,15 @@ async def is_server_running():
38
  return False
39
 
40
  async def monitor_server():
41
- server_started = False
42
- while True:
43
- if not server_started:
44
- start_ochat_server()
45
- server_started = True
46
 
47
- if await is_server_running():
48
- print("Server is running.")
49
- else:
50
  print("Server is not running. Attempting to restart...")
51
- server_started = False
52
 
53
- await asyncio.sleep(60) # Check every 60 seconds
54
 
55
  def run_async_monitor():
56
  loop = asyncio.new_event_loop()
@@ -83,6 +80,7 @@ async def chat_with_ochat(message):
83
  except aiohttp.ClientError as e:
84
  return f"Error: {e}"
85
 
 
86
  thread = threading.Thread(target=run_async_monitor)
87
  thread.start()
88
  # Create a Gradio Blocks interface with session state
 
28
  except Exception as e:
29
  return f"Failed to start ochat server: {e}"
30
 
31
+ start_ochat_server()
32
 
33
  async def is_server_running():
34
  async with aiohttp.ClientSession() as session:
 
39
  return False
40
 
41
  async def monitor_server():
42
+ # Wait for 5 minutes before starting to monitor
43
+ await asyncio.sleep(300)
 
 
 
44
 
45
+ while True:
46
+ if not await is_server_running():
 
47
  print("Server is not running. Attempting to restart...")
48
+ start_ochat_server()
49
 
50
+ await asyncio.sleep(60)
51
 
52
  def run_async_monitor():
53
  loop = asyncio.new_event_loop()
 
80
  except aiohttp.ClientError as e:
81
  return f"Error: {e}"
82
 
83
+
84
  thread = threading.Thread(target=run_async_monitor)
85
  thread.start()
86
  # Create a Gradio Blocks interface with session state