UCS_JG / app.py
EstebanDC's picture
Update app.py
40d86da
raw
history blame
2.73 kB
# Cargamos librerías
import pickle
import numpy as np
import gradio as gr
import sklearn
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import ExtraTreesRegressor
# You can use this block to train and save a model.
# Load the data
filename = 'Dataset_RCS_3.csv'
names0 = ['JET', "Suelo",'SPT', 'WtoC', 'Presion', 'Velocidad','RCS']
dataset=pd.read_csv(filename, names=names0)
# Dividimos el dataset en entrenamiento y test
y = dataset['RCS']
X = dataset.drop('RCS', axis=1)
# Categorical data
categorical_cols = ['JET', "Suelo"]
df = pd.get_dummies(X, columns = categorical_cols)
# Split the data into training and testing sets
validation_size = 0.20
seed = 10
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=validation_size, random_state=seed)
# Train the model
modelodef=ExtraTreesRegressor(
n_estimators=1000,
max_depth=9,
min_samples_leaf=1,
random_state=seed)
modelodef.fit(X_train, y_train)
# Save the model
pickle.dump(modelodef, open("modelodef.pkl", "wb"))
#create a function for gradio
def RCS(JET, Suelo,SPT, WtoC, Presion, Velocidad):
modelodef = pickle.load(open("modelodef.pkl", "rb"))
prediction0 = modelodef.predict([[JET, Suelo,SPT, WtoC, Presion, Velocidad]])
prediction = np.round(prediction0,2)
return prediction
title = "ASSESSMENT OF UNIAXIAL COMPRESSIVE STRENGTH OF JET GROUTING"
description = "This app corresponds to the research paper Machine learning as a solution to discover complex patterns: assessment of compressive strength of jet grouting"
article = """
Notes:
- Click submit/enviar button to obtain the UCS prediction
- Click clear/limpiar button to refresh text
- Please note the application ranges of the variables in the above referenced paper
- As decimal separator you can use either a point or a comma
"""
app = gr.Interface(
RCS,
inputs=[
gr.Radio(['1', '2', '3'], label="Jet system. 1:Single. 2:Double. 3:Triple",value="1"),
gr.Radio(['1', '2', '3', '4'], label="Soil type. 1:Coarse without fines. 2:Coarse with fines. 3:Fine. 4:Organic",value="1"),
gr.Number(value=1, label="Nspt"),
gr.Number(value=1, label="W/C"),
gr.Number(value=1, label="Grout pressure (MPa)"),
gr.Number(value=1, label="Rotation speed (rpm)"),
],
outputs=[gr.Text(label="UCS (MPa)")],
title=title,
description=description,
article = article,
theme="dark-seafoam"
)
app.launch()