DeepLearning101 commited on
Commit
c9c08b8
·
verified ·
1 Parent(s): 79f3857

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -67,6 +67,19 @@ def run_sync(user_input):
67
  print(f"Running sync with input: {user_input}")
68
  return asyncio.run(handle_input(user_input))
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  # 定義 Gradio 界面
71
  user_input = gr.Textbox(label='歡迎問我加密貨幣交易所的各種疑難雜症', placeholder='在此輸入問題...')
72
  examples = [
@@ -91,6 +104,10 @@ with gr.Blocks() as iface:
91
  user_input = gr.Textbox(label='輸入您的問題', placeholder="在此輸入問題...")
92
  submit_button = gr.Button("送出")
93
  gr.Examples(examples=examples, inputs=user_input)
 
 
 
 
94
  with gr.Row():
95
  feedback_output = gr.Textbox(label='反饋結果', interactive=False)
96
 
@@ -99,6 +116,23 @@ with gr.Blocks() as iface:
99
  history.append((user_input, response))
100
  return history, history
101
 
 
 
 
 
 
102
  submit_button.click(fn=chat, inputs=[user_input, chatbot], outputs=[chatbot, chatbot])
103
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  iface.launch()
 
67
  print(f"Running sync with input: {user_input}")
68
  return asyncio.run(handle_input(user_input))
69
 
70
+ # 定義反饋處理函數
71
+ def save_feedback(user_input, response, feedback_type, improvement):
72
+ feedback = {
73
+ "user_input": user_input,
74
+ "response": response,
75
+ "feedback_type": feedback_type,
76
+ "improvement": improvement
77
+ }
78
+ print(f"Saving feedback: {feedback}")
79
+ # 假設你有一個保存反饋的機制,可以是保存到文件或發送到服務器
80
+ # 這裡簡單打印出來,實際應用中應該保存反饋
81
+ return "感謝您的反饋!"
82
+
83
  # 定義 Gradio 界面
84
  user_input = gr.Textbox(label='歡迎問我加密貨幣交易所的各種疑難雜症', placeholder='在此輸入問題...')
85
  examples = [
 
104
  user_input = gr.Textbox(label='輸入您的問題', placeholder="在此輸入問題...")
105
  submit_button = gr.Button("送出")
106
  gr.Examples(examples=examples, inputs=user_input)
107
+ with gr.Row():
108
+ like_button = gr.Button("👍")
109
+ dislike_button = gr.Button("👎")
110
+ improvement_input = gr.Textbox(label='請輸入改進建議', placeholder='請輸入如何改進模型回應的建議')
111
  with gr.Row():
112
  feedback_output = gr.Textbox(label='反饋結果', interactive=False)
113
 
 
116
  history.append((user_input, response))
117
  return history, history
118
 
119
+ def handle_feedback(response, feedback_type, improvement):
120
+ global last_user_input
121
+ feedback_message = save_feedback(last_user_input, response, feedback_type, improvement)
122
+ return feedback_message
123
+
124
  submit_button.click(fn=chat, inputs=[user_input, chatbot], outputs=[chatbot, chatbot])
125
 
126
+ like_button.click(
127
+ fn=lambda response, improvement: handle_feedback(response, "like", improvement),
128
+ inputs=[chatbot, improvement_input],
129
+ outputs=feedback_output
130
+ )
131
+
132
+ dislike_button.click(
133
+ fn=lambda response, improvement: handle_feedback(response, "dislike", improvement),
134
+ inputs=[chatbot, improvement_input],
135
+ outputs=feedback_output
136
+ )
137
+
138
  iface.launch()