Spaces:
Sleeping
Sleeping
Gilmullin Almaz
commited on
Commit
·
5a86d30
1
Parent(s):
863a53f
resetting error logs
Browse files
app.py
CHANGED
|
@@ -26,6 +26,7 @@ from cluster.clustering import *
|
|
| 26 |
from StructureFingerprint import MorganFingerprint
|
| 27 |
|
| 28 |
import psutil
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
disable_progress_bars("huggingface_hub")
|
|
@@ -266,32 +267,67 @@ if submit_planning:
|
|
| 266 |
# results = cluster_molecules(reduced_super_cgrs_dict, mfp, max_clusters=num_clusters)
|
| 267 |
cluster_box, z = st.columns(2, gap="medium")
|
| 268 |
with cluster_box:
|
| 269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
st.write(f"Number of winning nodes: {len(tree.winning_nodes)}")
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
submit_clustering = st.button('Start clustering')
|
| 274 |
|
| 275 |
if submit_clustering:
|
| 276 |
try:
|
| 277 |
-
st.
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
except Exception as e:
|
| 293 |
st.error(f"Clustering failed with error: {str(e)}")
|
| 294 |
-
st.write(f"
|
| 295 |
raise e
|
| 296 |
# Access results
|
| 297 |
clusters = results['clusters_dict']
|
|
|
|
| 26 |
from StructureFingerprint import MorganFingerprint
|
| 27 |
|
| 28 |
import psutil
|
| 29 |
+
import gc
|
| 30 |
|
| 31 |
|
| 32 |
disable_progress_bars("huggingface_hub")
|
|
|
|
| 267 |
# results = cluster_molecules(reduced_super_cgrs_dict, mfp, max_clusters=num_clusters)
|
| 268 |
cluster_box, z = st.columns(2, gap="medium")
|
| 269 |
with cluster_box:
|
| 270 |
+
# Initialize session state if not exists
|
| 271 |
+
if 'memory_warning_shown' not in st.session_state:
|
| 272 |
+
st.session_state.memory_warning_shown = False
|
| 273 |
+
|
| 274 |
+
current_memory = psutil.Process().memory_info().rss / 1024 / 1024
|
| 275 |
+
st.write(f"Current memory usage: {current_memory:.2f} MB")
|
| 276 |
st.write(f"Number of winning nodes: {len(tree.winning_nodes)}")
|
| 277 |
+
|
| 278 |
+
# Memory warning
|
| 279 |
+
if current_memory > 1000 and not st.session_state.memory_warning_shown:
|
| 280 |
+
st.warning("Memory usage is high. Consider reducing the number of routes or clearing cache.")
|
| 281 |
+
st.session_state.memory_warning_shown = True
|
| 282 |
+
|
| 283 |
+
# Store the previous value in session state
|
| 284 |
+
if 'prev_num_clusters' not in st.session_state:
|
| 285 |
+
st.session_state.prev_num_clusters = 2
|
| 286 |
+
|
| 287 |
+
num_clusters = st.slider(
|
| 288 |
+
'Number of clusters to display',
|
| 289 |
+
min_value=2,
|
| 290 |
+
max_value=min(10, len(tree.winning_nodes)),
|
| 291 |
+
value=st.session_state.prev_num_clusters
|
| 292 |
+
)
|
| 293 |
+
|
| 294 |
+
# Update the stored value only if it changed
|
| 295 |
+
if num_clusters != st.session_state.prev_num_clusters:
|
| 296 |
+
st.session_state.prev_num_clusters = num_clusters
|
| 297 |
|
| 298 |
submit_clustering = st.button('Start clustering')
|
| 299 |
|
| 300 |
if submit_clustering:
|
| 301 |
try:
|
| 302 |
+
with st.spinner("Processing clusters..."):
|
| 303 |
+
# Clear memory before starting
|
| 304 |
+
gc.collect()
|
| 305 |
+
|
| 306 |
+
st.write("Starting clustering process...")
|
| 307 |
+
memory_before = psutil.Process().memory_info().rss / 1024 / 1024
|
| 308 |
+
st.write(f"Memory before clustering: {memory_before:.2f} MB")
|
| 309 |
+
|
| 310 |
+
super_cgrs_dict = reassign_nums(tree)
|
| 311 |
+
del tree # Free up memory from the tree object since we don't need it anymore
|
| 312 |
+
gc.collect()
|
| 313 |
+
|
| 314 |
+
reduced_super_cgrs_dict = process_all_rs_cgrs(super_cgrs_dict)
|
| 315 |
+
del super_cgrs_dict # Free up memory
|
| 316 |
+
gc.collect()
|
| 317 |
+
|
| 318 |
+
memory_after = psutil.Process().memory_info().rss / 1024 / 1024
|
| 319 |
+
st.write(f"Memory after CGR processing: {memory_after:.2f} MB")
|
| 320 |
+
|
| 321 |
+
mfp = MorganFingerprint()
|
| 322 |
+
results = cluster_molecules(reduced_super_cgrs_dict, mfp, max_clusters=num_clusters)
|
| 323 |
+
del reduced_super_cgrs_dict # Free up memory
|
| 324 |
+
gc.collect()
|
| 325 |
+
|
| 326 |
+
st.write("Clustering completed")
|
| 327 |
+
|
| 328 |
except Exception as e:
|
| 329 |
st.error(f"Clustering failed with error: {str(e)}")
|
| 330 |
+
st.write(f"Memory at error: {psutil.Process().memory_info().rss / 1024 / 1024:.2f} MB")
|
| 331 |
raise e
|
| 332 |
# Access results
|
| 333 |
clusters = results['clusters_dict']
|