HenryY2023 commited on
Commit
fda3f46
·
verified ·
1 Parent(s): 8dbfa9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -12,7 +12,8 @@ def install_packages():
12
 
13
  # Install compatible versions in a specific order
14
  subprocess.check_call([sys.executable, "-m", "pip", "install", "websockets==10.4"])
15
- subprocess.check_call([sys.executable, "-m", "pip", "install", "gradio==3.35.0"])
 
16
  subprocess.check_call([sys.executable, "-m", "pip", "install", "gradio-client==0.5.0"])
17
 
18
  # Install the rest of the requirements
@@ -248,20 +249,20 @@ with gr.Blocks() as demo:
248
  with gr.Tabs():
249
  # Chat tab
250
  with gr.TabItem("Chat"):
 
251
  chatbot = gr.Chatbot(height=500)
252
  msg = gr.Textbox(label="Your Question", placeholder="Type your question here...")
253
  clear = gr.Button("Clear Conversation")
254
 
255
- def user(user_message, history):
256
- return "", history + [[user_message, None]]
 
 
 
 
 
257
 
258
- def bot(history):
259
- user_message = history[-1][0]
260
- response = chat(user_message, history[:-1])
261
- history[-1][1] = response
262
- return history
263
-
264
- msg.submit(user, [msg, chatbot], [msg, chatbot]).then(bot, chatbot, chatbot)
265
  clear.click(lambda: None, None, chatbot, queue=False)
266
 
267
  # History tab
 
12
 
13
  # Install compatible versions in a specific order
14
  subprocess.check_call([sys.executable, "-m", "pip", "install", "websockets==10.4"])
15
+ # Updated Gradio to a more recent version
16
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "gradio==4.8.0"])
17
  subprocess.check_call([sys.executable, "-m", "pip", "install", "gradio-client==0.5.0"])
18
 
19
  # Install the rest of the requirements
 
249
  with gr.Tabs():
250
  # Chat tab
251
  with gr.TabItem("Chat"):
252
+ # Using a simpler chat interface
253
  chatbot = gr.Chatbot(height=500)
254
  msg = gr.Textbox(label="Your Question", placeholder="Type your question here...")
255
  clear = gr.Button("Clear Conversation")
256
 
257
+ def respond(message, chat_history):
258
+ if not message:
259
+ return "", chat_history
260
+
261
+ bot_message = chat(message, chat_history)
262
+ chat_history.append((message, bot_message))
263
+ return "", chat_history
264
 
265
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
 
 
 
 
 
 
266
  clear.click(lambda: None, None, chatbot, queue=False)
267
 
268
  # History tab