Spaces:
Running
on
Zero
Running
on
Zero
macadeliccc
commited on
Commit
•
4ea1c4e
1
Parent(s):
e70c8de
concurrent users test
Browse files
app.py
CHANGED
@@ -4,10 +4,11 @@ import torch
|
|
4 |
import subprocess
|
5 |
import requests
|
6 |
from gradio import State
|
|
|
7 |
|
8 |
# Function to start the ochat server
|
9 |
@spaces.GPU
|
10 |
-
def start_ochat_server():
|
11 |
print(f"Is CUDA available: {torch.cuda.is_available()}")
|
12 |
print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
13 |
|
@@ -25,19 +26,10 @@ def start_ochat_server():
|
|
25 |
|
26 |
start_ochat_server()
|
27 |
|
28 |
-
def user(message, history):
|
29 |
-
return "", history + [[message, None]]
|
30 |
|
31 |
|
32 |
-
def bot(history):
|
33 |
-
if history and history[-1] and history[-1][0]:
|
34 |
-
user_message = history[-1][0]
|
35 |
-
bot_response = chat_with_ochat(user_message)
|
36 |
-
history[-1][1] = bot_response # Update the last entry with the bot's response
|
37 |
-
return history
|
38 |
-
|
39 |
# Function to send a message to the ochat server and get a response
|
40 |
-
def chat_with_ochat(message):
|
41 |
url = "http://localhost:18888/v1/chat/completions"
|
42 |
headers = {"Content-Type": "application/json"}
|
43 |
data = {
|
@@ -68,6 +60,17 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
68 |
|
69 |
history = State([]) # Session state for chat history
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
message.submit(user, [message, chatbot], [message, chatbot], queue=False).then(
|
72 |
bot, chatbot, chatbot
|
73 |
)
|
|
|
4 |
import subprocess
|
5 |
import requests
|
6 |
from gradio import State
|
7 |
+
import asyncio
|
8 |
|
9 |
# Function to start the ochat server
|
10 |
@spaces.GPU
|
11 |
+
async def start_ochat_server():
|
12 |
print(f"Is CUDA available: {torch.cuda.is_available()}")
|
13 |
print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
14 |
|
|
|
26 |
|
27 |
start_ochat_server()
|
28 |
|
|
|
|
|
29 |
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
# Function to send a message to the ochat server and get a response
|
32 |
+
async def chat_with_ochat(message):
|
33 |
url = "http://localhost:18888/v1/chat/completions"
|
34 |
headers = {"Content-Type": "application/json"}
|
35 |
data = {
|
|
|
60 |
|
61 |
history = State([]) # Session state for chat history
|
62 |
|
63 |
+
async def user(message, history):
|
64 |
+
return "", history + [[message, None]]
|
65 |
+
|
66 |
+
|
67 |
+
async def bot(history):
|
68 |
+
if history and history[-1] and history[-1][0]:
|
69 |
+
user_message = history[-1][0]
|
70 |
+
bot_response = chat_with_ochat(user_message)
|
71 |
+
history[-1][1] = bot_response # Update the last entry with the bot's response
|
72 |
+
return history
|
73 |
+
|
74 |
message.submit(user, [message, chatbot], [message, chatbot], queue=False).then(
|
75 |
bot, chatbot, chatbot
|
76 |
)
|