Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Cargamos librerías
|
2 |
+
import pickle
|
3 |
+
import gradio as gr
|
4 |
+
import sklearn
|
5 |
+
import pandas as pd
|
6 |
+
from sklearn.model_selection import train_test_split
|
7 |
+
from sklearn.ensemble import ExtraTreesRegressor
|
8 |
+
|
9 |
+
# You can use this block to train and save a model.
|
10 |
+
|
11 |
+
|
12 |
+
# Load the data
|
13 |
+
filename = 'Dataset_RCS_3.csv'
|
14 |
+
names0 = ['JET', "Suelo",'SPT', 'WtoC', 'Presion', 'Velocidad','RCS']
|
15 |
+
dataset=pd.read_csv(filename, names=names0)
|
16 |
+
# Categorical data
|
17 |
+
categorical_cols = ['JET', "Suelo"]
|
18 |
+
df = pd.get_dummies(X, columns = categorical_cols)
|
19 |
+
|
20 |
+
# Split the data into training and testing sets
|
21 |
+
validation_size = 0.20
|
22 |
+
seed = 10
|
23 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=validation_size, random_state=seed)
|
24 |
+
|
25 |
+
# Train the model
|
26 |
+
modelodef=ExtraTreesRegressor(
|
27 |
+
n_estimators=1000,
|
28 |
+
max_depth=9,
|
29 |
+
min_samples_leaf=1,
|
30 |
+
random_state=seed)
|
31 |
+
modelodef.fit(X_train, y_train)
|
32 |
+
# Save the model
|
33 |
+
pickle.dump(model, open("model.pkl", "wb"))
|
34 |
+
|
35 |
+
#create a function for gradio
|
36 |
+
def RCS(JET, Suelo,SPT, WtoC, Presion, Velocidad):
|
37 |
+
x = np.array([JET, Suelo,SPT, WtoC, Presion, Velocidad])
|
38 |
+
prediction = modelodef.predict(x.reshape(1, -1))
|
39 |
+
return prediction
|
40 |
+
|
41 |
+
outputs = gr.outputs.Textbox()
|
42 |
+
app = gr.Interface(fn=RCS, inputs=['number','number','number','number','number','number'], outputs=outputs,description="UCS jet grouting")
|
43 |
+
app.launch(share=True)
|