macadeliccc commited on
Commit
9568922
1 Parent(s): 40457c5
Files changed (1) hide show
  1. app.py +11 -23
app.py CHANGED
@@ -9,8 +9,8 @@ import json
9
  import asyncio
10
 
11
  # Function to start the ochat server
12
- @asyncio.spaces.GPU
13
- async def start_ochat_server():
14
  print(f"Is CUDA available: {torch.cuda.is_available()}")
15
  print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
16
 
@@ -19,27 +19,15 @@ async def start_ochat_server():
19
  "--model", "openchat/openchat_3.5"
20
  ]
21
 
22
- async def is_server_running():
23
- async with aiohttp.ClientSession() as session:
24
- try:
25
- async with session.get("http://localhost:18888/docs") as response:
26
- return response.status == 200
27
- except aiohttp.ClientError:
28
- return False
29
-
30
- while True:
31
- if not await is_server_running():
32
- try:
33
- # Start the server in a separate process
34
- subprocess.Popen(command)
35
- print("ochat server started successfully.")
36
- except Exception as e:
37
- print(f"Failed to start ochat server: {e}")
38
-
39
- await asyncio.sleep(60) # Wait for 60 seconds before checking again
40
-
41
- # Start the server
42
- asyncio.run(start_ochat_server())
43
 
44
  # Function to send a message to the ochat server and get a response
45
  async def chat_with_ochat(message):
 
9
  import asyncio
10
 
11
  # Function to start the ochat server
12
+ @spaces.GPU
13
+ def start_ochat_server():
14
  print(f"Is CUDA available: {torch.cuda.is_available()}")
15
  print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
16
 
 
19
  "--model", "openchat/openchat_3.5"
20
  ]
21
 
22
+ # Start the server in a separate process
23
+ try:
24
+ subprocess.Popen(command)
25
+ return "ochat server started successfully"
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):