Spaces:
Running
on
Zero
Running
on
Zero
macadeliccc
commited on
Commit
β’
89bcd26
1
Parent(s):
f4c5213
test
Browse files
README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: π
|
4 |
-
colorFrom:
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.1.2
|
@@ -11,3 +11,10 @@ license: apache-2.0
|
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: Fast OpenChat-3.5
|
3 |
emoji: π
|
4 |
+
colorFrom: indigo
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.1.2
|
|
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
14 |
+
|
15 |
+
|
16 |
+
Run this on your own with this command:
|
17 |
+
|
18 |
+
```
|
19 |
+
docker run -it -p 7860:7860 --platform=linux/amd64 --gpus all \\\n\tregistry.hf.space/macadeliccc-openchat-3-5-chatbot:latest python app.py
|
20 |
+
```
|
app.py
CHANGED
@@ -29,49 +29,31 @@ def start_ochat_server():
|
|
29 |
start_ochat_server()
|
30 |
|
31 |
# Function to send a message to the ochat server and get a response
|
32 |
-
def chat_with_ochat(message
|
33 |
url = "http://0.0.0.0:18888/v1/chat/completions"
|
34 |
headers = {"Content-Type": "application/json"}
|
35 |
-
|
36 |
-
# Convert history to the expected format
|
37 |
-
messages = [{"role": "user" if i % 2 == 0 else "system", "content": msg}
|
38 |
-
for i, (user_msg, bot_msg) in enumerate(history) for msg in [user_msg, bot_msg] if msg]
|
39 |
-
|
40 |
-
# Append the latest user message
|
41 |
-
messages.append({"role": "user", "content": message})
|
42 |
-
|
43 |
data = {
|
44 |
"model": "openchat_3.5",
|
45 |
-
"messages":
|
46 |
}
|
47 |
|
48 |
try:
|
49 |
response = requests.post(url, json=data, headers=headers)
|
50 |
if response.status_code == 200:
|
51 |
-
# Extract the latest bot response
|
52 |
return response.json()['choices'][0]['message']['content']
|
53 |
else:
|
54 |
return f"Error: Server responded with status code {response.status_code}"
|
55 |
except requests.RequestException as e:
|
56 |
return f"Error: {e}"
|
57 |
|
58 |
-
|
59 |
with gr.Blocks() as demo:
|
60 |
chatbot = gr.Chatbot()
|
61 |
msg = gr.Textbox()
|
62 |
clear = gr.Button("Clear")
|
|
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
def bot(history):
|
68 |
-
response = chat_with_ochat(history[-1][0], history)
|
69 |
-
history[-1][1] = response
|
70 |
-
return history
|
71 |
|
72 |
-
|
73 |
-
bot, chatbot, chatbot
|
74 |
-
)
|
75 |
-
clear.click(lambda: None, None, chatbot, queue=False)
|
76 |
|
77 |
-
demo.launch()
|
|
|
29 |
start_ochat_server()
|
30 |
|
31 |
# Function to send a message to the ochat server and get a response
|
32 |
+
def chat_with_ochat(message):
|
33 |
url = "http://0.0.0.0:18888/v1/chat/completions"
|
34 |
headers = {"Content-Type": "application/json"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
data = {
|
36 |
"model": "openchat_3.5",
|
37 |
+
"messages": [{"role": "user", "content": message}]
|
38 |
}
|
39 |
|
40 |
try:
|
41 |
response = requests.post(url, json=data, headers=headers)
|
42 |
if response.status_code == 200:
|
|
|
43 |
return response.json()['choices'][0]['message']['content']
|
44 |
else:
|
45 |
return f"Error: Server responded with status code {response.status_code}"
|
46 |
except requests.RequestException as e:
|
47 |
return f"Error: {e}"
|
48 |
|
|
|
49 |
with gr.Blocks() as demo:
|
50 |
chatbot = gr.Chatbot()
|
51 |
msg = gr.Textbox()
|
52 |
clear = gr.Button("Clear")
|
53 |
+
history = gr.State([]) # Initialize an empty state for history
|
54 |
|
55 |
+
msg.submit(chat_with_ochat, inputs=[msg, history], outputs=[chatbot, history])
|
56 |
+
clear.click(lambda: ("", []), inputs=None, outputs=[chatbot, history])
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
+
demo.launch()
|
|
|
|
|
|
|
59 |
|
|