MasoudSamaei commited on
Commit
2fcef21
1 Parent(s): f1da487

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +177 -0
app.py CHANGED
@@ -51,6 +51,183 @@ Authors: Masoud Samaei1, Roohollah Shirani Faradonbeh1,*, Morteza Alinejad Omran
51
  2. Department of Civil Engineering, Shahrood University of Technology, Shahrood, Iran
52
  3. Faculty of Engineering, University of Tabriz, Tabriz, Iran
53
  * Corresponding Author—Email: roohollah.shiranifaradonbeh@curtin.edu.au
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  """,
55
  live=False)
56
  app.launch()
 
51
  2. Department of Civil Engineering, Shahrood University of Technology, Shahrood, Iran
52
  3. Faculty of Engineering, University of Tabriz, Tabriz, Iran
53
  * Corresponding Author—Email: roohollah.shiranifaradonbeh@curtin.edu.au
54
+ """,
55
+ live=False)
56
+ app.launch()
57
+
58
+
59
+
60
+ import numpy as np
61
+ import matplotlib.pyplot as plt
62
+
63
+
64
+ def make_prediction2(parameter, Type, dr, sn, percent, tmax):
65
+ with open("Decision_Tree.pkl", "rb") as f1:
66
+ clf1 = pickle.load(f1)
67
+ with open("random_forest.pkl", "rb") as f2:
68
+ clf2 = pickle.load(f2)
69
+ with open("XGBoost.pkl", "rb") as f3:
70
+ clf3 = pickle.load(f3)
71
+ with open("AdaBoost.pkl", "rb") as f4:
72
+ clf4 = pickle.load(f4)
73
+
74
+ predses1=np.array([])
75
+ predses2=np.array([])
76
+ predses3=np.array([])
77
+ predses4=np.array([])
78
+
79
+ # fig = plt.figure()
80
+
81
+ if parameter=="PET Type":
82
+ Types = np.array([])
83
+ for Type in range(1,4):
84
+ Types = np.append(Types, Type)
85
+
86
+ preds1 = clf1.predict([[Type, dr, sn, percent]])
87
+ preds1 = (round((preds1.squeeze() * tmax),2))
88
+ predses1 = np.append(predses1, preds1)
89
+
90
+ preds2 = clf2.predict([[Type, dr, sn, percent]])
91
+ preds2 =(round((preds2.squeeze() * tmax),2))
92
+ predses2= np.append(predses2, preds2)
93
+
94
+ preds3 = clf3.predict([[Type, dr, sn, percent]])
95
+ preds3 =(round((preds3.squeeze() * tmax),2))
96
+ predses3= np.append(predses3, preds3)
97
+
98
+ preds4 = clf4.predict([[Type, dr, sn, percent]])
99
+ preds4 =(round((preds4.squeeze() * tmax),2))
100
+ predses4= np.append(predses4, preds4)
101
+
102
+ plt.xlim(0, 4) # set the xlim to left, right
103
+ plt.ylim(tmax*0.8, 1.5*tmax)
104
+ plt.scatter(Types, predses1, color='k', label='Decision Tree')
105
+ plt.scatter(Types, predses2, color='b', label='Random Forest')
106
+ plt.scatter(Types, predses3, color='r', label='XGBoost')
107
+ plt.scatter(Types, predses4, color='y', label='AdaBoost')
108
+ plt.ylabel("Shear Strength", fontweight='bold')
109
+ plt.axhline(y=tmax, color='r', linestyle='-')
110
+ plt.xlabel("PET Type", fontweight='bold')
111
+ plt.legend(loc='lower right')
112
+ plt.show()
113
+
114
+
115
+ elif parameter=="Dr":
116
+ drs = np.array([])
117
+ for dr in np.arange(0.55,1,0.2):
118
+ drs = np.append(drs, dr)
119
+
120
+ preds1 = clf1.predict([[Type, dr, sn, percent]])
121
+ preds1 = (round((preds1.squeeze() * tmax),2))
122
+ predses1 = np.append(predses1, preds1)
123
+
124
+ preds2 = clf2.predict([[Type, dr, sn, percent]])
125
+ preds2 =(round((preds2.squeeze() * tmax),2))
126
+ predses2= np.append(predses2, preds2)
127
+
128
+ preds3 = clf3.predict([[Type, dr, sn, percent]])
129
+ preds3 =(round((preds3.squeeze() * tmax),2))
130
+ predses3= np.append(predses3, preds3)
131
+
132
+ preds4 = clf4.predict([[Type, dr, sn, percent]])
133
+ preds4 =(round((preds4.squeeze() * tmax),2))
134
+ predses4= np.append(predses4, preds4)
135
+
136
+ plt.xlim(0, 1.5) # set the xlim to left, right
137
+ plt.ylim(tmax*0.9, 1.1*tmax)
138
+ plt.scatter(drs, predses1, color='k', label='Decision Tree')
139
+ plt.scatter(drs, predses2, color='b', label='Random Forest')
140
+ plt.scatter(drs, predses3, color='r', label='XGBoost')
141
+ plt.scatter(drs, predses4, color='y', label='AdaBoost')
142
+ plt.ylabel("Shear Strength", fontweight='bold')
143
+ plt.xlabel("Dr", fontweight='bold')
144
+ plt.axhline(y=tmax, color='r', linestyle='-')
145
+ plt.legend(loc='lower right')
146
+ plt.show()
147
+
148
+
149
+ elif parameter=="Sn":
150
+ snss = np.array([])
151
+ for sn in np.arange(50,155,50):
152
+ snss = np.append(snss, sn)
153
+ preds1 = clf1.predict([[Type, dr, sn, percent]])
154
+ preds1 = (round((preds1.squeeze() * tmax),2))
155
+ predses1 = np.append(predses1, preds1)
156
+
157
+ preds2 = clf2.predict([[Type, dr, sn, percent]])
158
+ preds2 =(round((preds2.squeeze() * tmax),2))
159
+ predses2= np.append(predses2, preds2)
160
+
161
+ preds3 = clf3.predict([[Type, dr, sn, percent]])
162
+ preds3 =(round((preds3.squeeze() * tmax),2))
163
+ predses3= np.append(predses3, preds3)
164
+
165
+ preds4 = clf4.predict([[Type, dr, sn, percent]])
166
+ preds4 =(round((preds4.squeeze() * tmax),2))
167
+ predses4= np.append(predses4, preds4)
168
+
169
+ plt.xlim(40, 160) # set the xlim to left, right
170
+ plt.ylim(tmax*0.8, 1.5*tmax)
171
+ plt.scatter(snss, predses1, color='k', label='Decision Tree')
172
+ plt.scatter(snss, predses2, color='b', label='Random Forest')
173
+ plt.scatter(snss, predses3, color='r', label='XGBoost')
174
+ plt.scatter(snss, predses4, color='y', label='AdaBoost')
175
+ plt.ylabel("Shear Strength", fontweight='bold')
176
+ plt.xlabel("Normal Stress (Sn)", fontweight='bold')
177
+ plt.axhline(y=tmax, color='r', linestyle='-')
178
+ plt.legend(loc='lower right')
179
+ plt.show()
180
+
181
+ elif parameter=="PET percantage":
182
+ percents= np.array([])
183
+ for percent in np.arange(0.1,2.05,0.1):
184
+ percents = np.append(percents, percent)
185
+ preds1 = clf1.predict([[Type, dr, sn, percent]])
186
+ preds1 = (round((preds1.squeeze() * tmax),2))
187
+ predses1 = np.append(predses1, preds1)
188
+
189
+ preds2 = clf2.predict([[Type, dr, sn, percent]])
190
+ preds2 =(round((preds2.squeeze() * tmax),2))
191
+ predses2= np.append(predses2, preds2)
192
+
193
+ preds3 = clf3.predict([[Type, dr, sn, percent]])
194
+ preds3 =(round((preds3.squeeze() * tmax),2))
195
+ predses3= np.append(predses3, preds3)
196
+
197
+ preds4 = clf4.predict([[Type, dr, sn, percent]])
198
+ preds4 =(round((preds4.squeeze() * tmax),2))
199
+ predses4= np.append(predses4, preds4)
200
+
201
+ plt.xlim(0, 2.5) # set the xlim to left, right
202
+ plt.ylim(tmax*0.6, 1.5*tmax)
203
+ plt.scatter(percents, predses1, color='k', label='Decision Tree')
204
+ plt.scatter(percents, predses2, color='b', label='Random Forest')
205
+ plt.scatter(percents, predses3, color='r', label='XGBoost')
206
+ plt.scatter(percents, predses4, color='y', label='AdaBoost')
207
+ plt.ylabel("Shear Strength", fontweight='bold')
208
+ plt.xlabel("PET percentage", fontweight='bold')
209
+ plt.axhline(y=tmax, color='r', linestyle='-')
210
+ plt.legend(loc='lower right')
211
+ plt.show()
212
+
213
+ return plt
214
+
215
+
216
+
217
+ #
218
+
219
+ parameter = gr.Radio(["PET Type", "Dr", "Sn", "PET percantage"], value="PET Type", label="Select the parameter")
220
+ 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")
221
+ dr = gr.Slider(0.55, 0.95, step=0.2, label="Relative Density (Dr)", info="Range between 0.55 to 0.95")
222
+ sn = gr.Slider(50, 150, step=50, label="Normal Stresses (Sn)", info="Range between 50 to 150")
223
+ percent= gr.Slider(0, 2, step=0.1, label="PET Percent", info="Range between 0 to 2")
224
+ tmax= gr.Slider(36.5, 144, step=0.1, label="Shear Strength (plain soil without PET)", info="Range between 36 to 144")
225
+
226
+ # We create the output
227
+
228
+ app = gr.Interface(fn = make_prediction2, inputs=[parameter, Type, dr, sn, percent, tmax], outputs=['plot'],
229
+ title= "Parametric Analysis",
230
+ description = """ abc
231
  """,
232
  live=False)
233
  app.launch()