Spaces:
Running
on
Zero
Running
on
Zero
macadeliccc
commited on
Commit
•
a1908d6
1
Parent(s):
9568922
server monitor
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from gradio import State
|
|
7 |
import asyncio
|
8 |
import json
|
9 |
import asyncio
|
|
|
10 |
|
11 |
# Function to start the ochat server
|
12 |
@spaces.GPU
|
@@ -26,9 +27,28 @@ def start_ochat_server():
|
|
26 |
except Exception as e:
|
27 |
return f"Failed to start ochat server: {e}"
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
start_ochat_server()
|
31 |
|
|
|
|
|
|
|
|
|
32 |
# Function to send a message to the ochat server and get a response
|
33 |
async def chat_with_ochat(message):
|
34 |
base_url = "http://localhost:18888"
|
|
|
7 |
import asyncio
|
8 |
import json
|
9 |
import asyncio
|
10 |
+
import threading
|
11 |
|
12 |
# Function to start the ochat server
|
13 |
@spaces.GPU
|
|
|
27 |
except Exception as e:
|
28 |
return f"Failed to start ochat server: {e}"
|
29 |
|
30 |
+
async def monitor_server():
|
31 |
+
while True:
|
32 |
+
async with aiohttp.ClientSession() as session:
|
33 |
+
try:
|
34 |
+
async with session.get("http://localhost:18888/docs") as response:
|
35 |
+
if response.status == 200:
|
36 |
+
print("Server is running.")
|
37 |
+
else:
|
38 |
+
print("Server is not running. Attempting to restart...")
|
39 |
+
start_ochat_server()
|
40 |
+
except aiohttp.ClientError:
|
41 |
+
print("Server is not running. Attempting to restart...")
|
42 |
+
start_ochat_server()
|
43 |
+
|
44 |
+
await asyncio.sleep(60) # Check every 60 seconds
|
45 |
|
46 |
start_ochat_server()
|
47 |
|
48 |
+
# Start the monitoring in a separate thread
|
49 |
+
thread = threading.Thread(target=monitor_server)
|
50 |
+
thread.start()
|
51 |
+
|
52 |
# Function to send a message to the ochat server and get a response
|
53 |
async def chat_with_ochat(message):
|
54 |
base_url = "http://localhost:18888"
|