Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import matplotlib.pyplot as plt
|
4 |
-
import tempfile
|
5 |
import warnings
|
6 |
|
7 |
warnings.filterwarnings(action='ignore', category=UserWarning)
|
@@ -23,14 +22,18 @@ def process_file(file):
|
|
23 |
feature_columns = columns[:-1]
|
24 |
last_column = [columns[-1]]
|
25 |
# 返回前5行数据,更新下拉列表选项,并使其他控件可见
|
26 |
-
return (gr.update(choices=feature_columns,
|
27 |
gr.update(choices=last_column, value=last_column[-1], visible=True),
|
28 |
gr.update(visible=True),
|
29 |
-
gr.update(visible=True),
|
30 |
df.head(),
|
31 |
gr.update(visible=True)
|
32 |
)
|
33 |
|
|
|
|
|
|
|
|
|
34 |
def update_slider(choice):
|
35 |
# 更新数轴控件的可见性
|
36 |
return gr.update(visible=choice == "是")
|
@@ -50,12 +53,12 @@ def generate_output(file, column1, column2, choice, bins):
|
|
50 |
|
51 |
# 统计每个身高分段中不同心血管疾病类别的数量
|
52 |
counts = pd.crosstab(data_x, data_y)
|
53 |
-
# 绘制分段柱形图
|
54 |
-
counts.plot(kind='bar')
|
55 |
# 设置画布大小
|
56 |
plt.figure(figsize=(bins*2, 6))
|
|
|
|
|
57 |
# 设置 x 轴刻度标签横向显示
|
58 |
-
plt.xticks(rotation=
|
59 |
plt.xlabel(column1, fontsize=12)
|
60 |
plt.ylabel(column2, fontsize=12)
|
61 |
# plt.legend(['不患病', '患病'])
|
@@ -81,10 +84,15 @@ with gr.Blocks() as demo:
|
|
81 |
df_display = gr.Dataframe(visible=False)
|
82 |
output_image = gr.Image(visible=False)
|
83 |
|
|
|
|
|
84 |
# 文件上传后调用 process_file 函数
|
85 |
-
file_input.upload(process_file, inputs=file_input, outputs=[col1_dropdown, col2_dropdown,
|
86 |
|
87 |
-
# 选择框值改变时调用
|
|
|
|
|
|
|
88 |
choice_radio.change(update_slider, inputs=choice_radio, outputs=slider)
|
89 |
|
90 |
# 点击提交按钮时调用 generate_output 函数
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import matplotlib.pyplot as plt
|
|
|
4 |
import warnings
|
5 |
|
6 |
warnings.filterwarnings(action='ignore', category=UserWarning)
|
|
|
22 |
feature_columns = columns[:-1]
|
23 |
last_column = [columns[-1]]
|
24 |
# 返回前5行数据,更新下拉列表选项,并使其他控件可见
|
25 |
+
return (gr.update(choices=feature_columns, visible=True),
|
26 |
gr.update(choices=last_column, value=last_column[-1], visible=True),
|
27 |
gr.update(visible=True),
|
28 |
+
# gr.update(visible=True),
|
29 |
df.head(),
|
30 |
gr.update(visible=True)
|
31 |
)
|
32 |
|
33 |
+
def update_choice_radio(choice_feature_column):
|
34 |
+
# 更新数轴控件的可见性
|
35 |
+
return gr.update(label="“" + choice_feature_column + "”是否为连续值", visible=True)
|
36 |
+
|
37 |
def update_slider(choice):
|
38 |
# 更新数轴控件的可见性
|
39 |
return gr.update(visible=choice == "是")
|
|
|
53 |
|
54 |
# 统计每个身高分段中不同心血管疾病类别的数量
|
55 |
counts = pd.crosstab(data_x, data_y)
|
|
|
|
|
56 |
# 设置画布大小
|
57 |
plt.figure(figsize=(bins*2, 6))
|
58 |
+
# 绘制分段柱形图
|
59 |
+
counts.plot(kind='bar')
|
60 |
# 设置 x 轴刻度标签横向显示
|
61 |
+
plt.xticks(rotation=30)
|
62 |
plt.xlabel(column1, fontsize=12)
|
63 |
plt.ylabel(column2, fontsize=12)
|
64 |
# plt.legend(['不患病', '患病'])
|
|
|
84 |
df_display = gr.Dataframe(visible=False)
|
85 |
output_image = gr.Image(visible=False)
|
86 |
|
87 |
+
# # 文件上传后调用 process_file 函数
|
88 |
+
# file_input.upload(process_file, inputs=file_input, outputs=[col1_dropdown, col2_dropdown, choice_radio, df_display, df_display, submit_button])
|
89 |
# 文件上传后调用 process_file 函数
|
90 |
+
file_input.upload(process_file, inputs=file_input, outputs=[col1_dropdown, col2_dropdown, df_display, df_display, submit_button])
|
91 |
|
92 |
+
# 选择框值改变时调用 update_col2_dropdown 函数
|
93 |
+
col1_dropdown.change(update_choice_radio, inputs=col1_dropdown, outputs=choice_radio)
|
94 |
+
|
95 |
+
# 选择框值改变时调用 update_slide函数
|
96 |
choice_radio.change(update_slider, inputs=choice_radio, outputs=slider)
|
97 |
|
98 |
# 点击提交按钮时调用 generate_output 函数
|