Concrete123 commited on
Commit
5fba68f
·
verified ·
1 Parent(s): 1f0e69c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -33
app.py CHANGED
@@ -3,7 +3,6 @@ import pandas as pd
3
  import xgboost as xgb
4
  from sklearn.model_selection import train_test_split
5
  import gradio as gr
6
- import shap
7
 
8
  # 加载数据
9
  df_strength = pd.read_excel("Dataset1.xlsx")
@@ -34,38 +33,40 @@ clf.fit(x_train, y_train)
34
  def CirConStr(Temperature, CO2_Pressure, Time, CO2_Concentration, Particle_Size, CaO, MgO, SiO2, Al2O3, Fe2O3, MnO, L_S):
35
  x = np.array([Temperature, CO2_Pressure, Time, CO2_Concentration, Particle_Size, CaO, MgO, SiO2, Al2O3, Fe2O3, MnO, L_S])
36
  prediction = clf.predict(x.reshape(1, -1))
37
- return prediction[0]
38
 
39
- # 绘制 SHAP waterfall plot 的函数
40
- def plot_waterfall(Temperature, CO2_Pressure, Time, CO2_Concentration, Particle_Size, CaO, MgO, SiO2, Al2O3, Fe2O3, MnO, L_S):
41
- x = np.array([Temperature, CO2_Pressure, Time, CO2_Concentration, Particle_Size, CaO, MgO, SiO2, Al2O3, Fe2O3, MnO, L_S])
42
- explainer = shap.Explainer(clf, x_train)
43
- shap_values = explainer(x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
- # 绘制 SHAP waterfall plot 并返回 HTML
46
- shap.initjs()
47
- waterfall_plot_html = shap.waterfall_plot(explainer.expected_value, shap_values[0], feature_names=df_strength.columns[:-1], show=False)
48
- return waterfall_plot_html.html
 
 
 
 
 
 
49
 
50
- # 创建界面
51
- with gr.Interface(fn=CirConStr, inputs=[
52
- gr.inputs.Number(label="Temperature (unit: ℃)"),
53
- gr.inputs.Number(label="CO2_Pressure (unit: Bar)"),
54
- gr.inputs.Number(label="Time (unit: h)"),
55
- gr.inputs.Number(label="CO2_Concentration(unit: %)"),
56
- gr.inputs.Number(label="Particle_Size (unit: μm)"),
57
- gr.inputs.Number(label="CaO (fc, unit: %)"),
58
- gr.inputs.Number(label="MgO (fc, unit: %)"),
59
- gr.inputs.Number(label="SiO2 (fc, unit: %)"),
60
- gr.inputs.Number(label="Al2O3 (fc, unit: %)"),
61
- gr.inputs.Number(label="Fe2O3 (fc, unit: %)"),
62
- gr.inputs.Number(label="MnO (unit: %)"),
63
- gr.inputs.Number(label="L_S(L/S, unit: &)"),
64
- ],
65
- outputs=[
66
- gr.outputs.Textbox(label="Estimated CO2 sequestration capacity of SS (fcc, unit: %)"),
67
- gr.outputs.HTML(label="SHAP Waterfall Plot")
68
- ],
69
- title="Rapid estimation of CO2 sequestration capacity of SS"
70
- ) as app:
71
- app.launch()
 
3
  import xgboost as xgb
4
  from sklearn.model_selection import train_test_split
5
  import gradio as gr
 
6
 
7
  # 加载数据
8
  df_strength = pd.read_excel("Dataset1.xlsx")
 
33
  def CirConStr(Temperature, CO2_Pressure, Time, CO2_Concentration, Particle_Size, CaO, MgO, SiO2, Al2O3, Fe2O3, MnO, L_S):
34
  x = np.array([Temperature, CO2_Pressure, Time, CO2_Concentration, Particle_Size, CaO, MgO, SiO2, Al2O3, Fe2O3, MnO, L_S])
35
  prediction = clf.predict(x.reshape(1, -1))
36
+ return prediction
37
 
38
+ # 创建界面
39
+ with gr.Blocks() as app:
40
+ gr.Markdown("### Rapid estimation of CO2 sequestration capacity of SS")
41
+
42
+ with gr.Row():
43
+ with gr.Column():
44
+ Temperature = gr.Number(label="Temperature (unit: ℃)")
45
+ CO2_Pressure = gr.Number(label="CO2_Pressure (unit: Bar)")
46
+ Time = gr.Number(label="Time (unit: h)")
47
+ CO2_Concentration = gr.Number(label="CO2_Concentration(unit: %)")
48
+
49
+ with gr.Column():
50
+ Particle_Size = gr.Number(label="Particle_Size (unit: μm)")
51
+ CaO = gr.Number(label="CaO (fc, unit: %)")
52
+ MgO = gr.Number(label="MgO (fc, unit: %)")
53
+ SiO2 = gr.Number(label="SiO2 (fc, unit: %)")
54
+
55
+ with gr.Column():
56
+ Al2O3 = gr.Number(label="Al2O3 (fc, unit: %)")
57
+ Fe2O3 = gr.Number(label="Fe2O3 (fc, unit: %)")
58
+ MnO = gr.Number(label="MnO (unit: %)")
59
+ L_S = gr.Number(label="L_S(L/S, unit: &)")
60
 
61
+ # 输出组件
62
+ output = gr.Textbox(label="Estimated CO2 sequestration capacity of SS (fcc, unit: %)")
63
+
64
+ # 添加按钮和功能
65
+ calculate_btn = gr.Button("Calculate")
66
+ calculate_btn.click(
67
+ CirConStr,
68
+ inputs=[Temperature, CO2_Pressure, Time, CO2_Concentration, Particle_Size, CaO, MgO, SiO2, Al2O3, Fe2O3, MnO, L_S],
69
+ outputs=output
70
+ )
71
 
72
+ app.launch()