DeepLearning101 commited on
Commit
471c532
·
verified ·
1 Parent(s): 4d653a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -17
app.py CHANGED
@@ -81,7 +81,7 @@ async def send_chat_message(user_input):
81
  if full_response:
82
  return ''.join(full_response).strip()
83
  else:
84
- return "Error: No thought found in the response"
85
  except Exception as e:
86
  print(f"Exception: {e}")
87
  return f"Exception: {e}"
@@ -135,11 +135,7 @@ def show_feedback():
135
  except Exception as e:
136
  return f"Error: {e}"
137
 
138
- TITLE = """<h1 align="center">Large Language Model (LLM) Playground 💬 <a href='https://support.maicoin.com/zh-TW/support/home' target='_blank'>Cryptocurrency Exchange FAQ</a></h1>"""
139
- SUBTITLE = """<h2 align="center"><a href='https://www.twman.org' target='_blank'>TonTon Huang Ph.D. @ 2024/06 </a><br></h2>"""
140
- LINKS = """<a href='https://blog.twman.org/2021/04/ASR.html' target='_blank'>那些語音處理 (Speech Processing) 踩的坑</a> | <a href='https://blog.twman.org/2021/04/NLP.html' target='_blank'>那些自然語言處理 (Natural Language Processing, NLP) 踩的坑</a> | <a href='https://blog.twman.org/2024/02/asr-tts.html' target='_blank'>那些ASR和TTS可能會踩的坑</a> | <a href='https://blog.twman.org/2024/02/LLM.html' target='_blank'>那些大模型開發會踩的坑</a> | <a href='https://blog.twman.org/2023/04/GPT.html' target='_blank'>什麼是大語言模型,它是什麼?想要嗎?</a><br>
141
- <a href='https://blog.twman.org/2023/07/wsl.html' target='_blank'>用PaddleOCR的PPOCRLabel來微調醫療診斷書和收據</a> | <a href='https://blog.twman.org/2023/07/HugIE.html' target='_blank'>基於機器閱讀理解和指令微調的統一信息抽取框架之診斷書醫囑資訊擷取分析</a><br>
142
- <a href='https://huggingface.co/spaces/DeepLearning101/High-Entropy-Alloys-FAQ/blob/main/reference.txt' target='_blank'>「高熵合金」(High-entropy alloys) 參考論文</a><br>"""
143
 
144
  # 添加示例
145
  examples = [
@@ -149,40 +145,45 @@ examples = [
149
 
150
  with gr.Blocks() as iface:
151
  gr.HTML(TITLE)
152
- gr.HTML(SUBTITLE)
153
- gr.HTML(LINKS)
154
  with gr.Row():
155
- user_input = gr.Textbox(label='歡迎問我關於「高熵合金」(High-entropy alloys) 的各種疑難雜症', lines=2, placeholder="在此輸入問題,然後按下右邊的送出...")
 
 
 
156
  submit_button = gr.Button("送出")
157
-
158
  gr.Examples(examples=examples, inputs=user_input)
159
 
160
- with gr.Row():
161
- response_output = gr.Textbox(label='底下是大型語言模型的回應', interactive=False)
162
  with gr.Row():
163
  like_button = gr.Button("👍")
164
  dislike_button = gr.Button("👎")
165
- improvement_input = gr.Textbox(label='請先輸入改進建議再按下左手邊的贊或倒贊', placeholder='請輸入如何改進模型回應的建議,如果不輸入可以直接忽略')
 
166
  with gr.Row():
167
  feedback_output = gr.Textbox(label='反饋結果', interactive=False)
168
  with gr.Row():
169
  show_feedback_button = gr.Button("查看所有反饋")
170
  feedback_display = gr.JSON(label='所有反饋')
171
 
172
- submit_button.click(fn=handle_user_input, inputs=user_input, outputs=response_output)
 
 
 
 
 
173
 
174
  like_button.click(
175
  fn=lambda response, improvement: handle_feedback(response, "like", improvement),
176
- inputs=[response_output, improvement_input],
177
  outputs=feedback_output
178
  )
179
 
180
  dislike_button.click(
181
  fn=lambda response, improvement: handle_feedback(response, "dislike", improvement),
182
- inputs=[response_output, improvement_input],
183
  outputs=feedback_output
184
  )
185
 
186
  show_feedback_button.click(fn=show_feedback, outputs=feedback_display)
187
 
188
- iface.launch()
 
81
  if full_response:
82
  return ''.join(full_response).strip()
83
  else:
84
+ return "Error: No response found in the response"
85
  except Exception as e:
86
  print(f"Exception: {e}")
87
  return f"Exception: {e}"
 
135
  except Exception as e:
136
  return f"Error: {e}"
137
 
138
+ TITLE = """<h1 align="center">大型語言模型 (LLM) 聊天界面 💬</h1>"""
 
 
 
 
139
 
140
  # 添加示例
141
  examples = [
 
145
 
146
  with gr.Blocks() as iface:
147
  gr.HTML(TITLE)
 
 
148
  with gr.Row():
149
+ chatbot = gr.Chatbot()
150
+
151
+ with gr.Row():
152
+ user_input = gr.Textbox(label='輸入您的問題', placeholder="在此輸入問題...")
153
  submit_button = gr.Button("送出")
154
+
155
  gr.Examples(examples=examples, inputs=user_input)
156
 
 
 
157
  with gr.Row():
158
  like_button = gr.Button("👍")
159
  dislike_button = gr.Button("👎")
160
+ improvement_input = gr.Textbox(label='請輸入改進建議', placeholder='請輸入如何改進模型回應的建議')
161
+
162
  with gr.Row():
163
  feedback_output = gr.Textbox(label='反饋結果', interactive=False)
164
  with gr.Row():
165
  show_feedback_button = gr.Button("查看所有反饋")
166
  feedback_display = gr.JSON(label='所有反饋')
167
 
168
+ def chat(user_input, history):
169
+ response = handle_user_input(user_input)
170
+ history.append((user_input, response))
171
+ return history, history
172
+
173
+ submit_button.click(fn=chat, inputs=[user_input, chatbot], outputs=[chatbot, chatbot])
174
 
175
  like_button.click(
176
  fn=lambda response, improvement: handle_feedback(response, "like", improvement),
177
+ inputs=[chatbot, improvement_input],
178
  outputs=feedback_output
179
  )
180
 
181
  dislike_button.click(
182
  fn=lambda response, improvement: handle_feedback(response, "dislike", improvement),
183
+ inputs=[chatbot, improvement_input],
184
  outputs=feedback_output
185
  )
186
 
187
  show_feedback_button.click(fn=show_feedback, outputs=feedback_display)
188
 
189
+ iface.launch()