|
import gradio as gr |
|
import numpy as np |
|
import pickle |
|
|
|
|
|
with open('model_rf.pkl', 'rb') as file: |
|
rf = pickle.load(file) |
|
|
|
|
|
with open('my-standard-scaler.pkl', 'rb') as file: |
|
s_c = pickle.load(file) |
|
|
|
|
|
def predict(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): |
|
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 |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Estima tu % de grasa corporal") |
|
|
|
pH = gr.Number(label="pH (--)", value=7.09, interactive=True) |
|
EC = gr.Number(label="Ec (--)", value=0.31, interactive=True) |
|
CCE = gr.Number(label="CCE (--)", value=0.20, interactive=True) |
|
SOC = gr.Number(label="SOC (--)", value=2.9408, interactive=True) |
|
Sa = gr.Number(label="Sa (--)", value=45.0, interactive=True) |
|
Si = gr.Number(label="Si (--)", value=24.0, interactive=True) |
|
Cy = gr.Number(label="Cy (--)", value=31.0, interactive=True) |
|
CEC = gr.Number(label="CEC (--)", value=23.52, interactive=True) |
|
eCa = gr.Number(label="eCa (--)", value=19.44, interactive=True) |
|
eMg = gr.Number(label="eMg (--)", value=3.47, interactive=True) |
|
eK = gr.Number(label="eK (--)", value=0.47, interactive=True) |
|
eNa = gr.Number(label="eNa (--)", value=0.15, interactive=True) |
|
eAlH = gr.Number(label="eAlH (--)", value=0.0, interactive=True) |
|
|
|
submit = gr.Button(value='Predecir') |
|
output = gr.Textbox(label=": soil bulk density", interactive=False) |
|
|
|
submit.click(predict, inputs=[pH , EC, CCE, SOC, Sa, Si, Cy, CEC, eCa, eMg, eK, eNa, eAlH], outputs=[output]) |
|
|
|
demo.launch(share=False, debug=False) |