Spaces:
Sleeping
Sleeping
Commit
•
a6fc871
1
Parent(s):
865009c
Add Google Analytics
Browse files
app.py
CHANGED
@@ -5,12 +5,18 @@ from io import StringIO
|
|
5 |
import joblib
|
6 |
import numpy as np
|
7 |
import pandas as pd
|
|
|
8 |
# page set up
|
9 |
import streamlit as st
|
10 |
from b3clf.descriptor_padel import compute_descriptors
|
11 |
from b3clf.geometry_opt import geometry_optimize
|
12 |
-
from b3clf.utils import (
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
14 |
from streamlit_ketcher import st_ketcher
|
15 |
|
16 |
st.set_page_config(
|
@@ -211,7 +217,6 @@ with upload_column:
|
|
211 |
# st.write(file)
|
212 |
|
213 |
|
214 |
-
|
215 |
feature_column, prediction_column = st.columns(2)
|
216 |
with feature_column:
|
217 |
st.subheader("Features")
|
@@ -230,49 +235,58 @@ with prediction_column:
|
|
230 |
|
231 |
|
232 |
# Generate predictions when the user uploads a file
|
233 |
-
if
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
# feture table
|
250 |
-
with feature_column:
|
251 |
-
st.dataframe(X_features)
|
252 |
-
# placeholder_features.dataframe(X_features, hide_index=False)
|
253 |
-
feature_file_name = file.name.split(".")[0] + "_b3clf_features.csv"
|
254 |
-
features_csv = X_features.to_csv(index=True)
|
255 |
-
st.download_button(
|
256 |
-
"Download features as CSV",
|
257 |
-
data=features_csv,
|
258 |
-
file_name=feature_file_name,
|
259 |
)
|
260 |
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
# Add a button to download the predictions as a CSV file
|
268 |
-
predictions_csv = results.to_csv(index=True)
|
269 |
-
results_file_name = file.name.split(".")[0] + "_b3clf_predictions.csv"
|
270 |
st.download_button(
|
271 |
-
"Download
|
272 |
-
data=
|
273 |
-
file_name=
|
274 |
)
|
275 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
276 |
# hide footer
|
277 |
# https://github.com/streamlit/streamlit/issues/892
|
278 |
hide_streamlit_style = """
|
@@ -282,3 +296,19 @@ hide_streamlit_style = """
|
|
282 |
</style>
|
283 |
"""
|
284 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import joblib
|
6 |
import numpy as np
|
7 |
import pandas as pd
|
8 |
+
|
9 |
# page set up
|
10 |
import streamlit as st
|
11 |
from b3clf.descriptor_padel import compute_descriptors
|
12 |
from b3clf.geometry_opt import geometry_optimize
|
13 |
+
from b3clf.utils import (
|
14 |
+
get_descriptors,
|
15 |
+
predict_permeability,
|
16 |
+
scale_descriptors,
|
17 |
+
select_descriptors,
|
18 |
+
)
|
19 |
+
from streamlit_extras.let_it_rain import rain
|
20 |
from streamlit_ketcher import st_ketcher
|
21 |
|
22 |
st.set_page_config(
|
|
|
217 |
# st.write(file)
|
218 |
|
219 |
|
|
|
220 |
feature_column, prediction_column = st.columns(2)
|
221 |
with feature_column:
|
222 |
st.subheader("Features")
|
|
|
235 |
|
236 |
|
237 |
# Generate predictions when the user uploads a file
|
238 |
+
if st.button(label="Submit job", key="submit_job_button", type="secondary"):
|
239 |
+
if file:
|
240 |
+
temp_dir = tempfile.mkdtemp()
|
241 |
+
# Create a temporary file path for the uploaded file
|
242 |
+
temp_file_path = os.path.join(temp_dir, file.name)
|
243 |
+
# Save the uploaded file to the temporary file path
|
244 |
+
with open(temp_file_path, "wb") as temp_file:
|
245 |
+
temp_file.write(file.read())
|
246 |
+
# X_features, results = generate_predictions(temp_file_path)
|
247 |
+
X_features, results = generate_predictions(
|
248 |
+
input_fname=temp_file_path,
|
249 |
+
sep="\s+|\t+",
|
250 |
+
clf=classifiers_dict[classifier],
|
251 |
+
sampling=resample_methods_dict[resampler],
|
252 |
+
time_per_mol=120,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
)
|
254 |
|
255 |
+
# feture table
|
256 |
+
with feature_column:
|
257 |
+
st.dataframe(X_features)
|
258 |
+
# placeholder_features.dataframe(X_features, hide_index=False)
|
259 |
+
feature_file_name = file.name.split(".")[0] + "_b3clf_features.csv"
|
260 |
+
features_csv = X_features.to_csv(index=True)
|
|
|
|
|
|
|
261 |
st.download_button(
|
262 |
+
"Download features as CSV",
|
263 |
+
data=features_csv,
|
264 |
+
file_name=feature_file_name,
|
265 |
)
|
266 |
|
267 |
+
# prediction table
|
268 |
+
with prediction_column:
|
269 |
+
# st.subheader("Predictions")
|
270 |
+
if results is not None:
|
271 |
+
# Display the predictions in a table
|
272 |
+
st.dataframe(results, hide_index=True)
|
273 |
+
# Add a button to download the predictions as a CSV file
|
274 |
+
predictions_csv = results.to_csv(index=True)
|
275 |
+
results_file_name = file.name.split(".")[0] + "_b3clf_predictions.csv"
|
276 |
+
st.download_button(
|
277 |
+
"Download predictions as CSV",
|
278 |
+
data=predictions_csv,
|
279 |
+
file_name=results_file_name,
|
280 |
+
)
|
281 |
+
# indicate the success of the job
|
282 |
+
# rain(
|
283 |
+
# emoji="🎈",
|
284 |
+
# font_size=54,
|
285 |
+
# falling_speed=5,
|
286 |
+
# animation_length=10,
|
287 |
+
# )
|
288 |
+
st.balloons()
|
289 |
+
|
290 |
# hide footer
|
291 |
# https://github.com/streamlit/streamlit/issues/892
|
292 |
hide_streamlit_style = """
|
|
|
296 |
</style>
|
297 |
"""
|
298 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
299 |
+
|
300 |
+
# add google analytics
|
301 |
+
st.markdown(
|
302 |
+
"""
|
303 |
+
<!-- Google tag (gtag.js) -->
|
304 |
+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-WG8QYRELP9"></script>
|
305 |
+
<script>
|
306 |
+
window.dataLayer = window.dataLayer || [];
|
307 |
+
function gtag(){dataLayer.push(arguments);}
|
308 |
+
gtag('js', new Date());
|
309 |
+
|
310 |
+
gtag('config', 'G-WG8QYRELP9');
|
311 |
+
</script>
|
312 |
+
""",
|
313 |
+
unsafe_allow_html=True,
|
314 |
+
)
|