macadeliccc commited on
Commit
9a9a69d
·
1 Parent(s): 1d9cd75
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -25,6 +25,13 @@ def start_ochat_server():
25
 
26
  start_ochat_server()
27
 
 
 
 
 
 
 
 
28
  # Function to send a message to the ochat server and get a response
29
  def chat_with_ochat(message):
30
  url = "http://0.0.0.0:18888/v1/chat/completions"
@@ -50,20 +57,14 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
50
  registry.hf.space/macadeliccc-openchat-3-5-chatbot:latest python app.py```")
51
 
52
  with gr.Row():
53
- input_text = gr.Textbox(label="Your Message", placeholder="Type your message here")
54
- submit_button = gr.Button("Send")
55
- output_chat = gr.Chatbot()
56
 
57
  chat_history = State([]) # Session state for chat history
58
 
59
- def update_output(input_message, chat_history):
60
- server_response = chat_with_ochat(input_message) # Server's response
61
- chat_history.append((input_message, server_response))
62
- return chat_history
63
-
64
- submit_button.click(
65
- fn=update_output,
66
- inputs=[input_text, chat_history], # Ensure both inputs are passed
67
- outputs=[output_chat]
68
  )
 
69
  app.launch()
 
25
 
26
  start_ochat_server()
27
 
28
+ def user(message, history):
29
+ return "", history + [[message, None]]
30
+
31
+
32
+ def bot(history):
33
+ return chat_with_ochat(history[-1][0]), history + [[None, chat_with_ochat(history[-1][0])]]
34
+
35
  # Function to send a message to the ochat server and get a response
36
  def chat_with_ochat(message):
37
  url = "http://0.0.0.0:18888/v1/chat/completions"
 
57
  registry.hf.space/macadeliccc-openchat-3-5-chatbot:latest python app.py```")
58
 
59
  with gr.Row():
60
+ message = gr.Textbox(label="Your Message", placeholder="Type your message here")
61
+ chatbot = gr.Chatbot()
62
+ clear = gr.Button("Clear")
63
 
64
  chat_history = State([]) # Session state for chat history
65
 
66
+ message.submit(user, [message, chatbot], [message, chatbot], queue=False).then(
67
+ chat_with_ochat, chatbot, chatbot
 
 
 
 
 
 
 
68
  )
69
+ clear.click(lambda: None, None, chatbot, queue=False)
70
  app.launch()