Spaces:
Running
Running
def update_buttons(df_string):
Browse files
app.py
CHANGED
@@ -18,8 +18,13 @@ def process_file(file):
|
|
18 |
# 将 DataFrame 转换为字符串
|
19 |
df_string = df.to_string()
|
20 |
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def generate_questions(df_string):
|
25 |
# 使用 OpenAI 生成基于上传数据的问题
|
@@ -70,6 +75,10 @@ def respond(user_message, df_string_output, chat_history):
|
|
70 |
return "", chat_history
|
71 |
|
72 |
|
|
|
|
|
|
|
|
|
73 |
with gr.Blocks() as demo:
|
74 |
with gr.Row():
|
75 |
with gr.Column():
|
@@ -80,8 +89,14 @@ with gr.Blocks() as demo:
|
|
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,
|
87 |
inputs=[msg, df_string_output, chatbot],
|
@@ -89,15 +104,14 @@ with gr.Blocks() as demo:
|
|
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()
|
|
|
18 |
# 将 DataFrame 转换为字符串
|
19 |
df_string = df.to_string()
|
20 |
|
21 |
+
return update_buttons(df_string), df_string
|
22 |
+
|
23 |
+
def update_buttons(df_string):
|
24 |
+
# 根据上传的文件内容生成问题
|
25 |
+
questions = generate_questions(df_string)
|
26 |
+
return questions[:3] # 确保返回三个问题
|
27 |
+
|
28 |
|
29 |
def generate_questions(df_string):
|
30 |
# 使用 OpenAI 生成基于上传数据的问题
|
|
|
75 |
return "", chat_history
|
76 |
|
77 |
|
78 |
+
def on_button_click(button, df_string_output, chat_history):
|
79 |
+
# 当按钮被点击时发送对应的问题
|
80 |
+
return respond(button.text, df_string_output, chat_history)
|
81 |
+
|
82 |
with gr.Blocks() as demo:
|
83 |
with gr.Row():
|
84 |
with gr.Column():
|
|
|
89 |
|
90 |
with gr.Column():
|
91 |
df_string_output = gr.Textbox(label="raw data")
|
|
|
92 |
|
93 |
+
with gr.Group():
|
94 |
+
gr.Markdown("## 常用问题")
|
95 |
+
btn_1 = gr.Button()
|
96 |
+
btn_2 = gr.Button()
|
97 |
+
btn_3 = gr.Button()
|
98 |
+
|
99 |
+
|
100 |
send_button.click(
|
101 |
respond,
|
102 |
inputs=[msg, df_string_output, chatbot],
|
|
|
104 |
)
|
105 |
|
106 |
# file_upload.change(process_file, inputs=file_upload, outputs=df_string_output)
|
107 |
+
file_upload.change(process_file, inputs=file_upload, outputs=[(btn_1, "text"), (btn_2, "text"), (btn_3, "text"), df_string_output])
|
108 |
+
|
109 |
+
|
110 |
+
# 连接按钮点击事件
|
111 |
+
btn_1.click(on_button_click, inputs=[btn_1, df_string_output, chatbot], outputs=[msg, chatbot])
|
112 |
+
btn_2.click(on_button_click, inputs=[btn_2, df_string_output, chatbot], outputs=[msg, chatbot])
|
113 |
+
btn_3.click(on_button_click, inputs=[btn_3, df_string_output, chatbot], outputs=[msg, chatbot])
|
114 |
|
|
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
demo.launch()
|