Spaces:
Sleeping
Sleeping
Commit ·
6973f9d
1
Parent(s): 5a61933
explicitly delete uploaded files after prediction
Browse files- codes/gradio_utils.py +19 -3
codes/gradio_utils.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import warnings
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import xgboost as xgb
|
| 4 |
import sys
|
|
@@ -9,9 +10,20 @@ import pickle
|
|
| 9 |
import pandas as pd
|
| 10 |
import xgboost as xgb
|
| 11 |
|
| 12 |
-
global image # path to explanation plot, defined as global for the purposes of update
|
| 13 |
global features
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
markdown_text = """
|
| 16 |
**Feature Category Explanations**
|
| 17 |
|
|
@@ -169,7 +181,9 @@ def get_preds(patients_file, samples_file, mutations_file, cna_file, tumor_id):
|
|
| 169 |
cancer_types_to_consider,
|
| 170 |
save_plot=True)
|
| 171 |
|
| 172 |
-
|
|
|
|
|
|
|
| 173 |
|
| 174 |
def parse_inputs(age, gender, CNA_events, mutations):
|
| 175 |
# Normalization of age input
|
|
@@ -304,7 +318,9 @@ def get_preds_min_info(age, gender, CNA_events, mutations, output='Top Predictio
|
|
| 304 |
save_plot=True)
|
| 305 |
|
| 306 |
# Return the top 3 predictions and the path to the explanation plot
|
| 307 |
-
|
|
|
|
|
|
|
| 308 |
|
| 309 |
def get_top3(predictions, tumor_sample_id):
|
| 310 |
"""
|
|
|
|
| 1 |
import warnings
|
| 2 |
+
import os
|
| 3 |
import pandas as pd
|
| 4 |
import xgboost as xgb
|
| 5 |
import sys
|
|
|
|
| 10 |
import pandas as pd
|
| 11 |
import xgboost as xgb
|
| 12 |
|
| 13 |
+
global image # path to explanation plot, defined as global for the purposes of update
|
| 14 |
global features
|
| 15 |
|
| 16 |
+
def cleanup(uploaded_files=None):
|
| 17 |
+
"""Clear global state and temp files after each request."""
|
| 18 |
+
global features, predictions, sample_id
|
| 19 |
+
features = None
|
| 20 |
+
predictions = None
|
| 21 |
+
sample_id = None
|
| 22 |
+
if uploaded_files:
|
| 23 |
+
for f in uploaded_files:
|
| 24 |
+
if f is not None and hasattr(f, 'name') and os.path.exists(f.name):
|
| 25 |
+
os.remove(f.name)
|
| 26 |
+
|
| 27 |
markdown_text = """
|
| 28 |
**Feature Category Explanations**
|
| 29 |
|
|
|
|
| 181 |
cancer_types_to_consider,
|
| 182 |
save_plot=True)
|
| 183 |
|
| 184 |
+
result = get_top3(predictions, tumor_id), gr.Markdown(markdown_text), results[tumor_id]['explanation_plot']
|
| 185 |
+
cleanup([patients_file, samples_file, mutations_file, cna_file])
|
| 186 |
+
return result
|
| 187 |
|
| 188 |
def parse_inputs(age, gender, CNA_events, mutations):
|
| 189 |
# Normalization of age input
|
|
|
|
| 318 |
save_plot=True)
|
| 319 |
|
| 320 |
# Return the top 3 predictions and the path to the explanation plot
|
| 321 |
+
result = get_top3(predictions, 0), gr.Markdown(markdown_text, elem_classes="markdown-box"), results[0]['explanation_plot']
|
| 322 |
+
cleanup()
|
| 323 |
+
return result
|
| 324 |
|
| 325 |
def get_top3(predictions, tumor_sample_id):
|
| 326 |
"""
|