aied-lab commited on
Commit
0943ef4
·
verified ·
1 Parent(s): ca2773d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -113,10 +113,10 @@ with gr.Blocks() as demo:
113
  with gr.Column(scale=0.15, min_width=0):
114
  submit_btn = gr.Button("提問")
115
 
116
- # 用戶輸入後立即顯示提問文字,不添加回應部分
117
  def user_input(user_message, history):
118
  history.append((user_message, "")) # 顯示提問文字,回應部分為空字符串
119
- return history, history # 立即更新 chatbot 顯示
120
 
121
  # 處理 AI 回應,更新回應部分
122
  def bot_response(history):
@@ -124,15 +124,15 @@ with gr.Blocks() as demo:
124
  history = handle_query(user_message, 0.7, history) # 調用處理函數
125
  return history, history # 返回更新後的聊天記錄
126
 
127
- # 先顯示提問文字,然後處理 AI 回應
128
- submit_btn.click(user_input, [txt, state], [chatbot, state], queue=False).then(
129
  bot_response, state, [chatbot, state]
130
  )
131
 
132
- # 支援按 "Enter" 提交問題,立即顯示提問文字
133
- txt.submit(user_input, [txt, state], [chatbot, state], queue=False).then(
134
  bot_response, state, [chatbot, state]
135
  )
136
 
137
  # 啟動 Gradio 應用
138
- demo.launch()
 
113
  with gr.Column(scale=0.15, min_width=0):
114
  submit_btn = gr.Button("提問")
115
 
116
+ # 用戶輸入後立即顯示提問文字,不添加回應部分,並清空輸入框
117
  def user_input(user_message, history):
118
  history.append((user_message, "")) # 顯示提問文字,回應部分為空字符串
119
+ return history, "", history # 返回清空的輸入框以及更新的聊天歷史
120
 
121
  # 處理 AI 回應,更新回應部分
122
  def bot_response(history):
 
124
  history = handle_query(user_message, 0.7, history) # 調用處理函數
125
  return history, history # 返回更新後的聊天記錄
126
 
127
+ # 先顯示提問文字,然後處理 AI 回應,並清空輸入框
128
+ submit_btn.click(user_input, [txt, state], [chatbot, txt, state], queue=False).then(
129
  bot_response, state, [chatbot, state]
130
  )
131
 
132
+ # 支援按 "Enter" 提交問題,立即顯示提問文字並清空輸入框
133
+ txt.submit(user_input, [txt, state], [chatbot, txt, state], queue=False).then(
134
  bot_response, state, [chatbot, state]
135
  )
136
 
137
  # 啟動 Gradio 應用
138
+ demo.launch()