Commit
•
a3f5fdb
1
Parent(s):
897960e
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
|
3 |
+
def make_prediction(al, type, dr, sn, percent, tmax):
|
4 |
+
if percent == 0:
|
5 |
+
return "There is not any improvement in shear strength"
|
6 |
+
else:
|
7 |
+
if al == "Decision Tree" :
|
8 |
+
with open("Decision_Tree.pkl", "rb") as f:
|
9 |
+
clf = pickle.load(f)
|
10 |
+
preds = clf.predict([[type, dr, sn, percent]])
|
11 |
+
return f"Improvement percentage by Decision Tree is predicted around {round((preds.squeeze()-1)*100,2)}% and shear strength after improvement is {round((preds.squeeze() * tmax),2)}"
|
12 |
+
elif al == "Random Forest" :
|
13 |
+
with open("random_forest.pkl", "rb") as f:
|
14 |
+
clf = pickle.load(f)
|
15 |
+
preds = clf.predict([[type, dr, sn, percent]])
|
16 |
+
return f"Improvement percentage would be around {(preds.squeeze()-1)*100}% and shear strength improvement predicted by Random Forest is {(preds * tmax).squeeze()}"
|
17 |
+
elif al == "XGBoost" :
|
18 |
+
with open("XGBoost.pkl", "rb") as f:
|
19 |
+
clf = pickle.load(f)
|
20 |
+
preds = clf.predict([[type, dr, sn, percent]])
|
21 |
+
return f"Improvement percentage would be around {(preds.squeeze()-1)*100}% and shear strength improvement predicted by XGBoost is {(preds * tmax).squeeze()}"
|
22 |
+
elif al == "AdaBoost" :
|
23 |
+
with open("AdaBoost.pkl", "rb") as f:
|
24 |
+
clf = pickle.load(f)
|
25 |
+
preds = clf.predict([[type, dr, sn, percent]])
|
26 |
+
return f"Improvement percentage would be around {(preds.squeeze()-1)*100}% and shear strength improvement predicted by AdaBoost is {(preds * tmax).squeeze()}"
|
27 |
+
|
28 |
+
|
29 |
+
import gradio as gr
|
30 |
+
|
31 |
+
#Create the input component for Gradio since we are expecting 5 inputs
|
32 |
+
|
33 |
+
Algorithm = gr.Radio(["Decision Tree", "Random Forest", "XGBoost", "AdaBoost"], value="Decision Tree", label="Algorithm")
|
34 |
+
pet_type = gr.Slider(1, 3, value=1, step=1, label="PET type", info="Choose 1 for 1*1 PET, 2 for 1*5 PET, and 3 for fiber PET")
|
35 |
+
DR = gr.Slider(0.55, 0.95, step=0.2, label="Relative Density (Dr)")
|
36 |
+
SN = gr.Slider(50, 150, step=50, label="Normal Stresses (Sn)")
|
37 |
+
PPERCENT= gr.Slider(0, 2, step=0.1, label="PET Percent")
|
38 |
+
ShearStrength= gr.Slider(36.5, 144, step=0.1, label="Shear Strength")
|
39 |
+
|
40 |
+
# We create the output
|
41 |
+
output = gr.Textbox()
|
42 |
+
|
43 |
+
|
44 |
+
app = gr.Interface(fn = make_prediction, inputs=[Algorithm, pet_type, DR, SN, PPERCENT, ShearStrength], outputs=output, live=True)
|
45 |
+
app.launch()
|