Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,10 +8,10 @@ def process_file(file):
|
|
8 |
columns = df.columns.tolist()
|
9 |
print("文件已上传,表头为:", columns) # 调试信息
|
10 |
# 返回前5行数据,更新下拉列表选项,并使其他控件可见
|
11 |
-
return (df.head(),
|
12 |
-
gr.update(visible=True),
|
13 |
gr.update(choices=columns, visible=True),
|
14 |
gr.update(choices=columns, visible=True),
|
|
|
15 |
gr.update(visible=True))
|
16 |
|
17 |
def update_slider(choice):
|
@@ -36,17 +36,20 @@ def generate_output(file, col1, col2, choice, number):
|
|
36 |
return filtered_data.head(), image_path
|
37 |
|
38 |
with gr.Blocks() as demo:
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
47 |
|
48 |
# 文件上传后调用 process_file 函数
|
49 |
-
file_input.upload(process_file, inputs=file_input, outputs=[
|
50 |
|
51 |
# 选择框值改变时调用 update_slider 函数
|
52 |
choice_radio.change(update_slider, inputs=choice_radio, outputs=slider)
|
@@ -54,6 +57,4 @@ with gr.Blocks() as demo:
|
|
54 |
# 点击提交按钮时调用 generate_output 函数
|
55 |
submit_button.click(generate_output, inputs=[file_input, col1_dropdown, col2_dropdown, choice_radio, slider], outputs=[df_display, output_image])
|
56 |
|
57 |
-
demo.launch()
|
58 |
-
|
59 |
-
|
|
|
8 |
columns = df.columns.tolist()
|
9 |
print("文件已上传,表头为:", columns) # 调试信息
|
10 |
# 返回前5行数据,更新下拉列表选项,并使其他控件可见
|
11 |
+
return (df.head(),
|
|
|
12 |
gr.update(choices=columns, visible=True),
|
13 |
gr.update(choices=columns, visible=True),
|
14 |
+
gr.update(visible=True),
|
15 |
gr.update(visible=True))
|
16 |
|
17 |
def update_slider(choice):
|
|
|
36 |
return filtered_data.head(), image_path
|
37 |
|
38 |
with gr.Blocks() as demo:
|
39 |
+
with gr.Row():
|
40 |
+
with gr.Column():
|
41 |
+
file_input = gr.File(label="上传CSV文件", file_types=["csv"])
|
42 |
+
col1_dropdown = gr.Dropdown(label="选择列1", visible=False)
|
43 |
+
col2_dropdown = gr.Dropdown(label="选择列2", visible=False)
|
44 |
+
choice_radio = gr.Radio(["是", "否"], label="是否选择", visible=False)
|
45 |
+
slider = gr.Slider(minimum=2, maximum=7, step=1, label="选择数字", visible=False)
|
46 |
+
submit_button = gr.Button("提交")
|
47 |
+
with gr.Column():
|
48 |
+
df_display = gr.Dataframe(visible=False)
|
49 |
+
output_image = gr.Image(visible=False)
|
50 |
|
51 |
# 文件上传后调用 process_file 函数
|
52 |
+
file_input.upload(process_file, inputs=file_input, outputs=[col1_dropdown, col2_dropdown, choice_radio, df_display])
|
53 |
|
54 |
# 选择框值改变时调用 update_slider 函数
|
55 |
choice_radio.change(update_slider, inputs=choice_radio, outputs=slider)
|
|
|
57 |
# 点击提交按钮时调用 generate_output 函数
|
58 |
submit_button.click(generate_output, inputs=[file_input, col1_dropdown, col2_dropdown, choice_radio, slider], outputs=[df_display, output_image])
|
59 |
|
60 |
+
demo.launch()
|
|
|
|