Commit Random Forest
Browse files- app.py +52 -0
- model_rf.pkl +3 -0
- my-standard-scaler.pkl +3 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import pickle
|
4 |
+
|
5 |
+
# Cargar el modelo
|
6 |
+
with open('model_rf.pkl', 'rb') as file:
|
7 |
+
rf = pickle.load(file)
|
8 |
+
|
9 |
+
# Cargar el scaler
|
10 |
+
with open('my-standard-scaler.pkl', 'rb') as file:
|
11 |
+
s_c = pickle.load(file)
|
12 |
+
|
13 |
+
# Definir la funci贸n de predicci贸n
|
14 |
+
def predict(pH: float, EC: float, CCE: float, SOC: float, Sa: float, Si: float,
|
15 |
+
Cy: float, CEC: float, eCa: float, eMg: float, eK: float, eNa: float, eAlH: float):
|
16 |
+
ECEC = eCa + eMg + eK + eNa + eAlH
|
17 |
+
xCa = eCa/ECEC
|
18 |
+
xMg = eMg/ECEC
|
19 |
+
xK = eK/ECEC
|
20 |
+
xNa = eNa/ECEC
|
21 |
+
xAlH = eAlH/ECEC
|
22 |
+
BS1 = (eCa + eMg + eK + eNa)/CEC
|
23 |
+
BS2 = (eCa + eMg + eK + eNa)/ECEC
|
24 |
+
input_features = np.array([[pH, EC, CCE, SOC, Sa, Si, Cy, CEC, ECEC, xCa, xMg, xK, xNa, xAlH, BS1, BS2]])
|
25 |
+
input_features_scale = s_c.transform(input_features)
|
26 |
+
prediction = rf.predict(input_features_scale)[0].round(2)
|
27 |
+
return prediction
|
28 |
+
|
29 |
+
# Crear la interfaz Gradio
|
30 |
+
with gr.Blocks() as demo:
|
31 |
+
gr.Markdown("# Estima tu % de grasa corporal")
|
32 |
+
|
33 |
+
pH = gr.Number(label="pH (--)", value=7.09, interactive=True)
|
34 |
+
EC = gr.Number(label="Ec (--)", value=0.31, interactive=True)
|
35 |
+
CCE = gr.Number(label="CCE (--)", value=0.20, interactive=True)
|
36 |
+
SOC = gr.Number(label="SOC (--)", value=2.9408, interactive=True)
|
37 |
+
Sa = gr.Number(label="Sa (--)", value=45.0, interactive=True)
|
38 |
+
Si = gr.Number(label="Si (--)", value=24.0, interactive=True)
|
39 |
+
Cy = gr.Number(label="Cy (--)", value=31.0, interactive=True)
|
40 |
+
CEC = gr.Number(label="CEC (--)", value=23.52, interactive=True)
|
41 |
+
eCa = gr.Number(label="eCa (--)", value=19.44, interactive=True)
|
42 |
+
eMg = gr.Number(label="eMg (--)", value=3.47, interactive=True)
|
43 |
+
eK = gr.Number(label="eK (--)", value=0.47, interactive=True)
|
44 |
+
eNa = gr.Number(label="eNa (--)", value=0.15, interactive=True)
|
45 |
+
eAlH = gr.Number(label="eAlH (--)", value=0.0, interactive=True)
|
46 |
+
|
47 |
+
submit = gr.Button(value='Predecir')
|
48 |
+
output = gr.Textbox(label=": soil bulk density", interactive=False)
|
49 |
+
|
50 |
+
submit.click(predict, inputs=[pH , EC, CCE, SOC, Sa, Si, Cy, CEC, eCa, eMg, eK, eNa, eAlH], outputs=[output])
|
51 |
+
|
52 |
+
demo.launch(share=False, debug=False)
|
model_rf.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6447c0b8d6e28cb88c221fe7b836c9347e5300b12b9bee415d4f3859e04c8744
|
3 |
+
size 1015100
|
my-standard-scaler.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b51a9a34ac7cbc89634d5adfe4d525af82829399542167d08a88b66d21692e01
|
3 |
+
size 1012
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.38.1
|
2 |
+
numpy==1.24.3
|
3 |
+
scikit-learn==1.2.2
|