Spaces:
Running
Running
feat: set config page at the start
Browse files- src/streamlit_app.py +42 -10
src/streamlit_app.py
CHANGED
|
@@ -6,6 +6,14 @@ import pandas as pd
|
|
| 6 |
import streamlit as st
|
| 7 |
import plotly.express as px
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# ---------------------------------------------------------------------
|
| 10 |
# Configuration
|
| 11 |
# ---------------------------------------------------------------------
|
|
@@ -62,6 +70,17 @@ def load_raw_data():
|
|
| 62 |
|
| 63 |
pearson_df.columns = [c.strip() for c in pearson_df.columns]
|
| 64 |
mcc_df.columns = [c.strip() for c in mcc_df.columns]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
return pearson_df, mcc_df
|
| 66 |
|
| 67 |
|
|
@@ -216,17 +235,29 @@ def build_bar_df(
|
|
| 216 |
)
|
| 217 |
|
| 218 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
# ---------------------------------------------------------------------
|
| 220 |
# Streamlit UI
|
| 221 |
# ---------------------------------------------------------------------
|
| 222 |
|
| 223 |
|
| 224 |
def main():
|
| 225 |
-
st.set_page_config(
|
| 226 |
-
page_title="Custom Model Benchmarks",
|
| 227 |
-
layout="wide",
|
| 228 |
-
)
|
| 229 |
-
|
| 230 |
st.title("🧬 Custom Model Benchmarks")
|
| 231 |
st.markdown(_INTRO)
|
| 232 |
st.markdown(f"_Last updated: **{_LAST_UPDATED}**_")
|
|
@@ -249,7 +280,7 @@ def main():
|
|
| 249 |
available_species = sorted(df_bench["species"].unique())
|
| 250 |
selected_species: List[str] = []
|
| 251 |
for sp in available_species:
|
| 252 |
-
if
|
| 253 |
selected_species.append(sp)
|
| 254 |
|
| 255 |
# Assay toggles (Pearson only), based on filtered species
|
|
@@ -266,7 +297,7 @@ def main():
|
|
| 266 |
)
|
| 267 |
selected_assays: List[str] = []
|
| 268 |
for assay in available_assays:
|
| 269 |
-
if
|
| 270 |
selected_assays.append(assay)
|
| 271 |
else:
|
| 272 |
selected_assays = []
|
|
@@ -281,7 +312,7 @@ def main():
|
|
| 281 |
df_for_tracks = df_bench
|
| 282 |
available_datasets = sorted(df_for_tracks["datasets"].unique())
|
| 283 |
for ds in available_datasets:
|
| 284 |
-
if
|
| 285 |
selected_datasets.append(ds)
|
| 286 |
else:
|
| 287 |
selected_datasets = []
|
|
@@ -290,7 +321,7 @@ def main():
|
|
| 290 |
st.sidebar.subheader("Models")
|
| 291 |
selected_models: List[str] = []
|
| 292 |
for model in _ALL_MODELS:
|
| 293 |
-
if
|
| 294 |
selected_models.append(model)
|
| 295 |
|
| 296 |
# --- Main content ---
|
|
@@ -333,4 +364,5 @@ def main():
|
|
| 333 |
st.plotly_chart(fig, use_container_width=True)
|
| 334 |
|
| 335 |
|
| 336 |
-
|
|
|
|
|
|
| 6 |
import streamlit as st
|
| 7 |
import plotly.express as px
|
| 8 |
|
| 9 |
+
# ---------------------------------------------------------------------
|
| 10 |
+
# Page config (must be the first Streamlit command)
|
| 11 |
+
# ---------------------------------------------------------------------
|
| 12 |
+
st.set_page_config(
|
| 13 |
+
page_title="Custom Model Benchmarks",
|
| 14 |
+
layout="wide",
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
# ---------------------------------------------------------------------
|
| 18 |
# Configuration
|
| 19 |
# ---------------------------------------------------------------------
|
|
|
|
| 70 |
|
| 71 |
pearson_df.columns = [c.strip() for c in pearson_df.columns]
|
| 72 |
mcc_df.columns = [c.strip() for c in mcc_df.columns]
|
| 73 |
+
|
| 74 |
+
# Optional: basic sanity check on required columns
|
| 75 |
+
# required_p = {"species", "datasets", "pearson correlation"}
|
| 76 |
+
# required_m = {"species", "datasets", "MCC"}
|
| 77 |
+
# missing_p = required_p - set(pearson_df.columns)
|
| 78 |
+
# missing_m = required_m - set(mcc_df.columns)
|
| 79 |
+
# if missing_p:
|
| 80 |
+
# st.error(f"Pearson CSV missing columns: {missing_p}")
|
| 81 |
+
# if missing_m:
|
| 82 |
+
# st.error(f"MCC CSV missing columns: {missing_m}")
|
| 83 |
+
|
| 84 |
return pearson_df, mcc_df
|
| 85 |
|
| 86 |
|
|
|
|
| 235 |
)
|
| 236 |
|
| 237 |
|
| 238 |
+
# ---------------------------------------------------------------------
|
| 239 |
+
# UI helpers
|
| 240 |
+
# ---------------------------------------------------------------------
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
def sidebar_toggle(label: str, value: bool = False, key: str | None = None) -> bool:
|
| 244 |
+
"""
|
| 245 |
+
Wrapper to use st.sidebar.toggle when available, otherwise fall back to checkbox.
|
| 246 |
+
This makes the app compatible with older Streamlit versions on Hugging Face.
|
| 247 |
+
"""
|
| 248 |
+
toggle_fn = getattr(st.sidebar, "toggle", None)
|
| 249 |
+
if toggle_fn is not None:
|
| 250 |
+
return toggle_fn(label, value=value, key=key)
|
| 251 |
+
# Fallback for older Streamlit versions
|
| 252 |
+
return st.sidebar.checkbox(label, value=value, key=key)
|
| 253 |
+
|
| 254 |
+
|
| 255 |
# ---------------------------------------------------------------------
|
| 256 |
# Streamlit UI
|
| 257 |
# ---------------------------------------------------------------------
|
| 258 |
|
| 259 |
|
| 260 |
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
st.title("🧬 Custom Model Benchmarks")
|
| 262 |
st.markdown(_INTRO)
|
| 263 |
st.markdown(f"_Last updated: **{_LAST_UPDATED}**_")
|
|
|
|
| 280 |
available_species = sorted(df_bench["species"].unique())
|
| 281 |
selected_species: List[str] = []
|
| 282 |
for sp in available_species:
|
| 283 |
+
if sidebar_toggle(sp, value=True, key=f"species_{benchmark_name}_{sp}"):
|
| 284 |
selected_species.append(sp)
|
| 285 |
|
| 286 |
# Assay toggles (Pearson only), based on filtered species
|
|
|
|
| 297 |
)
|
| 298 |
selected_assays: List[str] = []
|
| 299 |
for assay in available_assays:
|
| 300 |
+
if sidebar_toggle(assay, value=True, key=f"assay_{benchmark_name}_{assay}"):
|
| 301 |
selected_assays.append(assay)
|
| 302 |
else:
|
| 303 |
selected_assays = []
|
|
|
|
| 312 |
df_for_tracks = df_bench
|
| 313 |
available_datasets = sorted(df_for_tracks["datasets"].unique())
|
| 314 |
for ds in available_datasets:
|
| 315 |
+
if sidebar_toggle(ds, value=True, key=f"dataset_{benchmark_name}_{ds}"):
|
| 316 |
selected_datasets.append(ds)
|
| 317 |
else:
|
| 318 |
selected_datasets = []
|
|
|
|
| 321 |
st.sidebar.subheader("Models")
|
| 322 |
selected_models: List[str] = []
|
| 323 |
for model in _ALL_MODELS:
|
| 324 |
+
if sidebar_toggle(model, value=True, key=f"model_{model}"):
|
| 325 |
selected_models.append(model)
|
| 326 |
|
| 327 |
# --- Main content ---
|
|
|
|
| 364 |
st.plotly_chart(fig, use_container_width=True)
|
| 365 |
|
| 366 |
|
| 367 |
+
if __name__ == "__main__":
|
| 368 |
+
main()
|