Spaces:
Running
on
Zero
Running
on
Zero
macadeliccc
commited on
Commit
•
3bc8972
1
Parent(s):
76789b2
test
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
|
|
3 |
import torch
|
4 |
import subprocess
|
5 |
import numpy as np
|
6 |
-
|
7 |
|
8 |
|
9 |
|
@@ -26,17 +26,23 @@ def start_ochat_server():
|
|
26 |
return f"Failed to start ochat server: {e}"
|
27 |
|
28 |
|
29 |
-
# Function to
|
30 |
-
|
31 |
def chat_with_ochat(message):
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
# Create a Gradio Interface
|
42 |
iface = gr.Interface(
|
|
|
3 |
import torch
|
4 |
import subprocess
|
5 |
import numpy as np
|
6 |
+
import requests
|
7 |
|
8 |
|
9 |
|
|
|
26 |
return f"Failed to start ochat server: {e}"
|
27 |
|
28 |
|
29 |
+
# Function to send a message to the ochat server and get a response
|
|
|
30 |
def chat_with_ochat(message):
|
31 |
+
url = "http://localhost:18888/v1/chat/completions"
|
32 |
+
headers = {"Content-Type": "application/json"}
|
33 |
+
data = {
|
34 |
+
"model": "openchat_3.5",
|
35 |
+
"messages": [{"role": "user", "content": message}]
|
36 |
+
}
|
37 |
|
38 |
+
try:
|
39 |
+
response = requests.post(url, json=data, headers=headers)
|
40 |
+
if response.status_code == 200:
|
41 |
+
return response.json()['choices'][0]['message']['content']
|
42 |
+
else:
|
43 |
+
return f"Error: Server responded with status code {response.status_code}"
|
44 |
+
except requests.RequestException as e:
|
45 |
+
return f"Error: {e}"
|
46 |
|
47 |
# Create a Gradio Interface
|
48 |
iface = gr.Interface(
|