Spaces:
Sleeping
Sleeping
Anton Bushuiev
commited on
Commit
·
f32e93f
1
Parent(s):
33fc999
Add error handling, force light mode
Browse files
app.py
CHANGED
|
@@ -138,7 +138,8 @@ def setup():
|
|
| 138 |
print("Setup complete")
|
| 139 |
|
| 140 |
|
| 141 |
-
def
|
|
|
|
| 142 |
in_pth = Path(in_pth)
|
| 143 |
# # in_pth = Path('DreaMS/data/MSV000086206/peak/mzml/S_N1.mzML') # Example dataset
|
| 144 |
|
|
@@ -239,15 +240,36 @@ def predict(lib_pth, in_pth, progress=gr.Progress(track_tqdm=True)):
|
|
| 239 |
df = df.drop(columns=['Top k'])
|
| 240 |
df = df[df["DreaMS similarity"] >= 0.75]
|
| 241 |
# Add row numbers as first column
|
| 242 |
-
df.insert(0, 'Row', range(len(df)))
|
| 243 |
|
| 244 |
progress(1.0, desc=f"Predictions complete! Found {len(df)} high-confidence matches.")
|
| 245 |
|
| 246 |
return df, str(df_path)
|
| 247 |
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
setup()
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
with app:
|
| 252 |
|
| 253 |
# Input GUI
|
|
|
|
| 138 |
print("Setup complete")
|
| 139 |
|
| 140 |
|
| 141 |
+
def _predict_core(lib_pth, in_pth, progress):
|
| 142 |
+
"""Core prediction function without error handling"""
|
| 143 |
in_pth = Path(in_pth)
|
| 144 |
# # in_pth = Path('DreaMS/data/MSV000086206/peak/mzml/S_N1.mzML') # Example dataset
|
| 145 |
|
|
|
|
| 240 |
df = df.drop(columns=['Top k'])
|
| 241 |
df = df[df["DreaMS similarity"] >= 0.75]
|
| 242 |
# Add row numbers as first column
|
| 243 |
+
df.insert(0, 'Row', range(1, len(df) + 1))
|
| 244 |
|
| 245 |
progress(1.0, desc=f"Predictions complete! Found {len(df)} high-confidence matches.")
|
| 246 |
|
| 247 |
return df, str(df_path)
|
| 248 |
|
| 249 |
|
| 250 |
+
def predict(lib_pth, in_pth, progress=gr.Progress(track_tqdm=True)):
|
| 251 |
+
"""Wrapper function with error handling"""
|
| 252 |
+
try:
|
| 253 |
+
return _predict_core(lib_pth, in_pth, progress)
|
| 254 |
+
except Exception as e:
|
| 255 |
+
raise gr.Error(e)
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
# Set up
|
| 259 |
setup()
|
| 260 |
+
|
| 261 |
+
# Start the Gradio app
|
| 262 |
+
js_func = """
|
| 263 |
+
function refresh() {
|
| 264 |
+
const url = new URL(window.location);
|
| 265 |
+
|
| 266 |
+
if (url.searchParams.get('__theme') !== 'light') {
|
| 267 |
+
url.searchParams.set('__theme', 'light');
|
| 268 |
+
window.location.href = url.href;
|
| 269 |
+
}
|
| 270 |
+
}
|
| 271 |
+
"""
|
| 272 |
+
app = gr.Blocks(theme=gr.themes.Default(primary_hue="yellow", secondary_hue="pink"), js=js_func)
|
| 273 |
with app:
|
| 274 |
|
| 275 |
# Input GUI
|