macadeliccc commited on
Commit
3bc8972
1 Parent(s): 76789b2
Files changed (1) hide show
  1. app.py +16 -10
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 interact with the chat server
30
-
31
  def chat_with_ochat(message):
32
-
33
- # Here you would add the code to interact with the ochat server
34
- # For simplicity, this is just a placeholder response
35
- return "Response from ochat server"
 
 
36
 
37
-
38
- # Start the ochat server
39
- start_ochat_server()
 
 
 
 
 
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(