youngtsai commited on
Commit
26894bc
1 Parent(s): 1a94c44

question_buttons = gr.Container()

Browse files
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -21,6 +21,16 @@ def process_file(file):
21
  # 返回 DataFrame 字符串,以用作聊天机器人的系统提示
22
  return df_string
23
 
 
 
 
 
 
 
 
 
 
 
24
  def respond(user_message, df_string_output, chat_history):
25
  print("=== 變數:user_message ===")
26
  print(user_message)
@@ -70,6 +80,7 @@ with gr.Blocks() as demo:
70
 
71
  with gr.Column():
72
  df_string_output = gr.Textbox(label="raw data")
 
73
 
74
  send_button.click(
75
  respond,
@@ -77,6 +88,16 @@ with gr.Blocks() as demo:
77
  outputs=[msg, chatbot]
78
  )
79
 
80
- file_upload.change(process_file, inputs=file_upload, outputs=df_string_output)
 
 
 
 
 
 
 
 
 
 
81
 
82
  demo.launch()
 
21
  # 返回 DataFrame 字符串,以用作聊天机器人的系统提示
22
  return df_string
23
 
24
+ def generate_questions(df_string):
25
+ # 使用 OpenAI 生成基于上传数据的问题
26
+ # 这里需要编写代码来实现此功能
27
+ questions = ["问题 1", "问题 2", "问题 3"] # 示例问题列表
28
+ return questions
29
+
30
+ def send_question(question, df_string_output, chat_history):
31
+ # 当问题按钮被点击时调用此函数
32
+ return respond(question, df_string_output, chat_history)
33
+
34
  def respond(user_message, df_string_output, chat_history):
35
  print("=== 變數:user_message ===")
36
  print(user_message)
 
80
 
81
  with gr.Column():
82
  df_string_output = gr.Textbox(label="raw data")
83
+ question_buttons = gr.Container()
84
 
85
  send_button.click(
86
  respond,
 
88
  outputs=[msg, chatbot]
89
  )
90
 
91
+ # file_upload.change(process_file, inputs=file_upload, outputs=df_string_output)
92
+
93
+ file_upload.change(process_file, inputs=file_upload, outputs=[df_string_output, question_buttons])
94
+
95
+ # 根据生成的问题创建按钮
96
+ for question in generate_questions(""): # 初始时为空
97
+ question_buttons.append(gr.Button(question, elem_id=question).click(
98
+ send_question,
99
+ inputs=[question, df_string_output, chatbot],
100
+ outputs=[msg, chatbot]
101
+ ))
102
 
103
  demo.launch()