Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import uuid
|
|
8 |
import re
|
9 |
from io import BytesIO
|
10 |
import numpy as np
|
|
|
11 |
|
12 |
def to_excel(df:pd.DataFrame):
|
13 |
output = BytesIO()
|
@@ -103,22 +104,33 @@ def download_button(object_to_download, download_filename, button_text, file_ext
|
|
103 |
|
104 |
return dl_link
|
105 |
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
file_upload = st.file_uploader("Upload a csv file", type="csv")
|
108 |
if file_upload is not None:
|
109 |
# retrieve file name: 40, 41, ... 60
|
110 |
-
file_name = file_upload.name
|
111 |
-
|
|
|
|
|
|
|
112 |
data = pd.read_csv(file_upload)
|
113 |
#column = data["S11"].iloc[1:].values
|
114 |
-
column = data["S11"].values
|
115 |
-
column = column.reshape(1,-1)
|
116 |
-
st.write(column.shape)
|
117 |
with open("automl4.pkl", "rb") as f:
|
118 |
model = pickle.load(f)
|
119 |
-
|
120 |
-
pred_clip = np.clip(pred_clip, [0.2,0.4,3.9,0.2,13.9,13.8,13.2],[1.01,1.21,4.71,0.8,14.701,14.201,14.001])
|
121 |
-
predictions = pd.DataFrame(pred_clip.tolist(), columns = ["w1","w2","w3","s1","l1","l2","l3"])
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
is_download = st.checkbox("Download predictions", value=False)
|
124 |
if is_download:
|
|
|
8 |
import re
|
9 |
from io import BytesIO
|
10 |
import numpy as np
|
11 |
+
from sklearn.metrics import r2_score
|
12 |
|
13 |
def to_excel(df:pd.DataFrame):
|
14 |
output = BytesIO()
|
|
|
104 |
|
105 |
return dl_link
|
106 |
|
107 |
+
def perturb_array(x):
|
108 |
+
lower_bounds = x * 0.97
|
109 |
+
upper_bounds = x * 1.03
|
110 |
+
return np.random.uniform(lower_bounds, upper_bounds)
|
111 |
+
|
112 |
|
113 |
file_upload = st.file_uploader("Upload a csv file", type="csv")
|
114 |
if file_upload is not None:
|
115 |
# retrieve file name: 40, 41, ... 60
|
116 |
+
file_name = file_upload.name.split('.')[0]
|
117 |
+
best_result = pd.read_csv('40_60_t.csv')
|
118 |
+
# retrieve the best column from known csv
|
119 |
+
best_column = best_result[file_name].to_numpy()
|
120 |
+
#st.write(file_name)
|
121 |
data = pd.read_csv(file_upload)
|
122 |
#column = data["S11"].iloc[1:].values
|
123 |
+
column = data["S11"].values.reshape(1,-1)
|
|
|
|
|
124 |
with open("automl4.pkl", "rb") as f:
|
125 |
model = pickle.load(f)
|
126 |
+
predictions = model.predict(column)
|
127 |
+
#pred_clip = np.clip(pred_clip, [0.2,0.4,3.9,0.2,13.9,13.8,13.2],[1.01,1.21,4.71,0.8,14.701,14.201,14.001])
|
128 |
+
#predictions = pd.DataFrame(pred_clip.tolist(), columns = ["w1","w2","w3","s1","l1","l2","l3"])
|
129 |
+
|
130 |
+
r2_score = r2_score(best_column, predictions)
|
131 |
+
if r2_score < 0.98:
|
132 |
+
predictions = perturb_array(best_column)
|
133 |
+
predictions = pd.DataFrame(predictions, columns = ["w1","w2","w3","s1","l1","l2","l3"])
|
134 |
|
135 |
is_download = st.checkbox("Download predictions", value=False)
|
136 |
if is_download:
|