macadeliccc commited on
Commit
c3afba8
·
1 Parent(s): 16cd0e3
Files changed (1) hide show
  1. app.py +29 -31
app.py CHANGED
@@ -30,34 +30,35 @@ def start_ochat_server():
30
 
31
  start_ochat_server()
32
 
33
- async def is_server_running():
34
- async with aiohttp.ClientSession() as session:
35
- try:
36
- async with session.get("http://localhost:18888/v1/chat/completions") as response:
37
- return response.status == 200 or response.status == 400 or response.status == 422
38
- except aiohttp.ClientError:
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()
54
- asyncio.set_event_loop(loop)
55
- loop.run_until_complete(monitor_server())
56
- loop.close()
57
-
58
- # Start the monitoring in a separate thread
59
- thread = threading.Thread(target=run_async_monitor)
60
- thread.start()
 
61
 
62
  # Function to send a message to the ochat server and get a response
63
  async def chat_with_ochat(message):
@@ -80,9 +81,6 @@ async def chat_with_ochat(message):
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
87
  with gr.Blocks(theme=gr.themes.Soft()) as app:
88
  gr.Markdown("## vLLM OpenChat-3.5 Interface")
 
30
 
31
  start_ochat_server()
32
 
33
+ # async def is_server_running():
34
+ # async with aiohttp.ClientSession() as session:
35
+ # try:
36
+ # async with session.get("http://localhost:18888/v1/chat/completions") as response:
37
+ # return response.status == 200 or response.status == 400 or response.status == 422
38
+ # except aiohttp.ClientError:
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
+ # time.sleep(120)
54
+ # loop = asyncio.new_event_loop()
55
+ # asyncio.set_event_loop(loop)
56
+ # loop.run_until_complete(monitor_server())
57
+ # loop.close()
58
+
59
+ # # Start the monitoring in a separate thread
60
+ # thread = threading.Thread(target=run_async_monitor)
61
+ # thread.start()
62
 
63
  # Function to send a message to the ochat server and get a response
64
  async def chat_with_ochat(message):
 
81
  except aiohttp.ClientError as e:
82
  return f"Error: {e}"
83
 
 
 
 
84
  # Create a Gradio Blocks interface with session state
85
  with gr.Blocks(theme=gr.themes.Soft()) as app:
86
  gr.Markdown("## vLLM OpenChat-3.5 Interface")