File size: 5,366 Bytes
c5c9dba
 
 
 
 
 
 
 
 
 
 
 
 
a3d8df2
2907ba4
a3d8df2
 
 
93b3457
2907ba4
70716fb
a3d8df2
 
35c2cfe
2907ba4
93b3457
 
70716fb
a3d8df2
 
 
c5c9dba
2907ba4
c5c9dba
 
 
 
 
 
 
 
93b3457
c5c9dba
 
 
5cd3a17
c5c9dba
 
756e690
 
 
 
 
 
 
d082948
a43a787
b77b085
2125012
ecb332d
4ec5db2
b4e4180
7fc12c8
8af57c7
7fc12c8
8af57c7
03d8e3d
8af57c7
03d8e3d
8af57c7
2907ba4
b4e4180
03d8e3d
8af57c7
7fc12c8
8af57c7
7fc12c8
8af57c7
7fc12c8
2907ba4
b4e4180
03d8e3d
8af57c7
03d8e3d
8af57c7
7fc12c8
882a783
2907ba4
b4e4180
882a783
 
 
 
 
 
2664126
 
a3d8df2
b4e4180
a3d8df2
b4e4180
a3d8df2
b4e4180
a3d8df2
b4e4180
a3d8df2
b109a9c
2664126
b109a9c
a3d8df2
 
 
3054620
a3d8df2
c5c9dba
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import gradio as gr
import numpy as np
import pickle

# Cargar el modelo
with open('model_rf.pkl', 'rb') as file:
    rf = pickle.load(file)

# Cargar el scaler
with open('my-standard-scaler.pkl', 'rb') as file:
    s_c = pickle.load(file)

# Definir la funci贸n de predicci贸n
def predict_1(SOC: float):
    SOC = SOC/1.724 # SOC <- MO/1.724
    prediction = 1.58 + np.exp(-0.07*SOC)
    return prediction.round(2)

def predict_2(SOC: float, Cy: float):
    SOC = SOC/1.724 # SOC <- MO/1.724
    prediction = np.array(2.03 - 0.008*Cy - 0.008*SOC)
    return prediction.round(2)

def predict_3(SOC: float, Cy: float, eCa: float, eMg: float, eK: float, eNa: float, eAlH: float):
    SOC = SOC/1.724 # SOC <- MO/1.724
    ECEC = eCa + eMg + eK + eNa + eAlH
    xK = eK/ECEC
    prediction = np.array(1.53 - 0.076*SOC + 0.004*Cy - 2.04*xK)
    return prediction.round(2)
    
def predict_4(pH: float, EC: float, CCE: float, SOC: float, Sa: float, Si: float,
            Cy: float, CEC: float, eCa: float, eMg: float, eK: float, eNa: float, eAlH: float):
    SOC = SOC/1.724 # SOC <- MO/1.724
    ECEC = eCa + eMg + eK + eNa + eAlH
    xCa = eCa/ECEC
    xMg = eMg/ECEC
    xK = eK/ECEC
    xNa = eNa/ECEC
    xAlH = eAlH/ECEC
    BS1 = (eCa + eMg + eK + eNa)/CEC
    BS2 = (eCa + eMg + eK + eNa)/ECEC
    input_features = np.array([[pH,	EC,	CCE, SOC, Sa, Si, Cy, CEC, ECEC, xCa, xMg, xK, xNa, xAlH, BS1, BS2]])
    input_features_scale = s_c.transform(input_features)
    prediction = rf.predict(input_features_scale)[0].round(2)
    return prediction
# <img src="https://www.wycia.com/wp-content/uploads/2016/09/LOGO-PUCP.jpg" width=200px>
# Crear la interfaz Gradio
with gr.Blocks() as demo:
    #with gr.Row():
    #    with gr.Column():
    #        gr.Markdown("""<img src="https://www.wycia.com/wp-content/uploads/2016/09/LOGO-PUCP.jpg" width=250px>""")
    #    with gr.Column():
    #        gr.Markdown("""<img src="https://prociencia.gob.pe/wp-content/uploads/2022/05/PROCIENCIA-LOGO-300x169.png" width=200px>""")
    #    with gr.Column():
    #        gr.Markdown("""<img src="https://i.ibb.co/k8LxVMT/images.jpg" width=150px>""")
    #gr.Markdown("""<img src="https://www.wycia.com/wp-content/uploads/2016/09/LOGO-PUCP.jpg" width=1000px height=250px >""")
    gr.Markdown("""<img src="https://i.ibb.co/dJB3MTX/banner-v1.png" width=1000px >""")
    #gr.Markdown("""<img src="https://drive.google.com/uc?export=view&id=1kmnKJcF0QIqxVDsqGcENmVe1qZJqV96m" width=1000px >""")
    gr.Markdown("# Estimaci贸n de la densidad aparente del suelo")
    
    with gr.Row():
        with gr.Column(scale=0, min_width=250):
            gr.Markdown("**M.O. (%)**")
            SOC = gr.Number(label="", value=2.9408, interactive=True, elem_classes="bold-label")
            gr.Markdown("**K<sup>+</sup> (meq/100g)**")
            eK = gr.Number(label="", value=0.47, interactive=True)
            gr.Markdown("**pH (1:1) en H<sub>2</sub>O**")
            pH = gr.Number(label="", value=7.09, interactive=True)
            gr.Markdown("**C.E. (1:1 dS/m)**")
            EC = gr.Number(label="", value=0.31, interactive=True)
            
        with gr.Column(scale=0, min_width=250):
            gr.Markdown("**Arcilla (%)**")
            Cy = gr.Number(label="", value=31.0, interactive=True)
            gr.Markdown("**Na<sup>+</sup> (meq/100g)**")
            eNa = gr.Number(label="", value=0.15, interactive=True)
            gr.Markdown("**CaCO<sub>2</sub> (%)**")
            CCE = gr.Number(label="", value=0.20, interactive=True) 
            
            
        with gr.Column(scale=0, min_width=250):
            gr.Markdown("**Ca<sup>2+</sup> (meq/100g)**")
            eCa = gr.Number(label="", value=19.44, interactive=True)
            gr.Markdown("**Al<sup>3+</sup> + H<sup>+</sup> (meq/100g)**")
            eAlH = gr.Number(label="", value=0.0, interactive=True)
            gr.Markdown("**Limo (%)**")
            Si = gr.Number(label="", value=24.0, interactive=True)  
            
        with gr.Column(scale=0, min_width=250):  
            gr.Markdown("**Mg<sup>2+</sup> (meq/100g)**")
            eMg = gr.Number(label="", value=3.47, interactive=True)
            gr.Markdown("**Arena (%)**")
            Sa = gr.Number(label="", value=45.0, interactive=True)
            gr.Markdown("**CIC (meq/100g)**")
            CEC = gr.Number(label="", value=23.52, interactive=True)   

    gr.Markdown("Seleccione un modelo:")
    with gr.Row():
        with gr.Column(scale=0, min_width=250):
            submit_1 = gr.Button(value='Abdelbaki')
        with gr.Column(scale=0, min_width=250):
            submit_2 = gr.Button(value='Benites')
        with gr.Column(scale=0, min_width=250):
            submit_3 = gr.Button(value='MLRegression')
        with gr.Column(scale=0, min_width=250):
            submit_4 = gr.Button(value='Random Forest')

    gr.Markdown("Densidad aparente del suelo (g/cm<sup>3</sup>):")
    output = gr.Textbox(label="", interactive=False)

    submit_1.click(predict_1, inputs=[SOC], outputs=[output])
    submit_2.click(predict_2, inputs=[SOC, Cy], outputs=[output])
    submit_3.click(predict_3, inputs=[SOC, Cy, eCa, eMg, eK, eNa, eAlH], outputs=[output])
    submit_4.click(predict_4, inputs=[pH , EC, CCE, SOC, Sa, Si, Cy, CEC, eCa, eMg, eK, eNa, eAlH], outputs=[output])

demo.launch(share=False, debug=False)