Spaces:
Sleeping
Sleeping
Commit
•
659e403
1
Parent(s):
d6532a9
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ from sklearn.preprocessing import OrdinalEncoder
|
|
2 |
import xgboost as xgb
|
3 |
import numpy as np
|
4 |
import matplotlib.pyplot as plt
|
5 |
-
import argparse, h5py, os, re
|
6 |
import streamlit as st
|
7 |
|
8 |
def get_POMFinder():
|
@@ -96,6 +96,36 @@ def download_button(file_name, button_text):
|
|
96 |
file_name=file_name,
|
97 |
mime="text/xyz",)
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
st.title('POMFinder')
|
101 |
st.write('Welcome to POMFinder which is a tree-based supervised learning algorithm that can predict the polyoxometalate cluster from a Pair Distribution Function.')
|
@@ -136,7 +166,8 @@ else:
|
|
136 |
|
137 |
# Download the structural database
|
138 |
#download_button("COD_ICSD_XYZs_POMs_unique99.zip", "Download structural database")
|
139 |
-
|
|
|
140 |
|
141 |
st.subheader('Cite')
|
142 |
|
|
|
2 |
import xgboost as xgb
|
3 |
import numpy as np
|
4 |
import matplotlib.pyplot as plt
|
5 |
+
import argparse, h5py, os, re, zipfile
|
6 |
import streamlit as st
|
7 |
|
8 |
def get_POMFinder():
|
|
|
96 |
file_name=file_name,
|
97 |
mime="text/xyz",)
|
98 |
|
99 |
+
def create_zip_with_txt(y_onehotenc_cat, res, y_pred_proba):
|
100 |
+
"""
|
101 |
+
Create a zip file containing specific .xyz files and a txt file with model guesses.
|
102 |
+
|
103 |
+
Parameters:
|
104 |
+
y_onehotenc_cat: The one-hot encoder categories object.
|
105 |
+
res: The result index for selecting the appropriate file.
|
106 |
+
y_pred_proba: The probability associated with each prediction.
|
107 |
+
|
108 |
+
Returns:
|
109 |
+
None. A zip file is created in the current directory.
|
110 |
+
"""
|
111 |
+
|
112 |
+
zip_file_name = "POMFinder_results.zip"
|
113 |
+
|
114 |
+
# Create a zip file
|
115 |
+
with zipfile.ZipFile(zip_file_name, 'w') as zipf:
|
116 |
+
# Add the .xyz files
|
117 |
+
for i in range(5):
|
118 |
+
file_path = "Backend/COD_ICSD_XYZs_POMs_unique99/" + str(y_onehotenc_cat.categories_[i][res[0]])[2:-2] + "cale.xyz"
|
119 |
+
zipf.write(file_path, arcname=str(y_onehotenc_cat.categories_[i][res[0]])[2:-2] + "cale.xyz")
|
120 |
+
|
121 |
+
# Create and add the txt file with model guesses
|
122 |
+
with zipf.open("model_guesses.txt", "w") as f:
|
123 |
+
for i in range(5):
|
124 |
+
guess_text = f'The {i+1}st guess from the model is: {str(y_onehotenc_cat.categories_[i][res[0]])[2:-2]+"cale.xyz"} with a probability of {y_pred_proba[res[0]]:.2f} %\n'
|
125 |
+
f.write(guess_text.encode('utf-8'))
|
126 |
+
|
127 |
+
|
128 |
+
|
129 |
|
130 |
st.title('POMFinder')
|
131 |
st.write('Welcome to POMFinder which is a tree-based supervised learning algorithm that can predict the polyoxometalate cluster from a Pair Distribution Function.')
|
|
|
166 |
|
167 |
# Download the structural database
|
168 |
#download_button("COD_ICSD_XYZs_POMs_unique99.zip", "Download structural database")
|
169 |
+
create_zip_with_txt(y_onehotenc_cat, res, y_pred_proba)
|
170 |
+
download_button("POMFinder_results.zip", "Download top-5 predictions")
|
171 |
|
172 |
st.subheader('Cite')
|
173 |
|