Commit ·
216b843
1
Parent(s): 2e9ffc1
Fix detail view: keep title+doi in CATALOG; direct select→detail; handle all df shapes
Browse files
app.py
CHANGED
|
@@ -109,10 +109,11 @@ def _load_catalog() -> pd.DataFrame:
|
|
| 109 |
df["on_hf"] = df["dataset"].apply(lambda s: "✓" if s in on_hub else "")
|
| 110 |
for col in ("n_subjects", "n_records", "n_tasks"):
|
| 111 |
df[col] = pd.to_numeric(df[col], errors="coerce").fillna(0).astype(int)
|
| 112 |
-
|
|
|
|
| 113 |
if col not in df.columns:
|
| 114 |
df[col] = ""
|
| 115 |
-
df = df[TABLE_COLUMNS].fillna("")
|
| 116 |
return df
|
| 117 |
|
| 118 |
|
|
@@ -155,7 +156,7 @@ def _filter(
|
|
| 155 |
|
| 156 |
|
| 157 |
def _render_table(df: pd.DataFrame) -> pd.DataFrame:
|
| 158 |
-
return df.rename(columns=DISPLAY_HEADERS)
|
| 159 |
|
| 160 |
|
| 161 |
def _snippets(slug: str, on_hf: bool) -> str:
|
|
@@ -244,11 +245,34 @@ CSS = """
|
|
| 244 |
"""
|
| 245 |
|
| 246 |
|
| 247 |
-
def _on_select(evt: gr.SelectData, df
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
|
| 254 |
def _on_filter(
|
|
@@ -332,10 +356,8 @@ Library on [PyPI](https://pypi.org/project/eegdash/).
|
|
| 332 |
for w in filter_inputs:
|
| 333 |
w.change(_on_filter, filter_inputs, [table, count])
|
| 334 |
|
| 335 |
-
|
| 336 |
-
table.select(_on_select, [table], [selected_slug])
|
| 337 |
-
selected_slug.change(lambda s: _detail(CATALOG, s), [selected_slug], [detail])
|
| 338 |
|
| 339 |
|
| 340 |
if __name__ == "__main__":
|
| 341 |
-
demo.launch()
|
|
|
|
| 109 |
df["on_hf"] = df["dataset"].apply(lambda s: "✓" if s in on_hub else "")
|
| 110 |
for col in ("n_subjects", "n_records", "n_tasks"):
|
| 111 |
df[col] = pd.to_numeric(df[col], errors="coerce").fillna(0).astype(int)
|
| 112 |
+
extra = ["dataset_title", "doi"]
|
| 113 |
+
for col in TABLE_COLUMNS + extra:
|
| 114 |
if col not in df.columns:
|
| 115 |
df[col] = ""
|
| 116 |
+
df = df[TABLE_COLUMNS + extra].fillna("")
|
| 117 |
return df
|
| 118 |
|
| 119 |
|
|
|
|
| 156 |
|
| 157 |
|
| 158 |
def _render_table(df: pd.DataFrame) -> pd.DataFrame:
|
| 159 |
+
return df[TABLE_COLUMNS].rename(columns=DISPLAY_HEADERS)
|
| 160 |
|
| 161 |
|
| 162 |
def _snippets(slug: str, on_hf: bool) -> str:
|
|
|
|
| 245 |
"""
|
| 246 |
|
| 247 |
|
| 248 |
+
def _on_select(evt: gr.SelectData, df) -> str:
|
| 249 |
+
"""Return the detail markdown for the clicked row.
|
| 250 |
+
|
| 251 |
+
Bypasses ``gr.State`` so the lookup is a single hop: click → detail.
|
| 252 |
+
Handles deselection and header clicks (``evt.index`` may be ``None``)
|
| 253 |
+
and the three shapes gradio 5.x can pass the table value as (DataFrame,
|
| 254 |
+
list-of-lists, or a dict with ``headers``/``data``).
|
| 255 |
+
"""
|
| 256 |
+
if evt is None or evt.index is None:
|
| 257 |
+
return "Pick a dataset row above to see details and load snippets."
|
| 258 |
+
row_idx = evt.index[0] if isinstance(evt.index, (list, tuple)) else evt.index
|
| 259 |
+
if df is None:
|
| 260 |
+
return "Pick a dataset row above to see details and load snippets."
|
| 261 |
+
if isinstance(df, pd.DataFrame):
|
| 262 |
+
if df.empty or row_idx >= len(df):
|
| 263 |
+
return "Pick a dataset row above to see details and load snippets."
|
| 264 |
+
slug = str(df.iloc[row_idx, 0])
|
| 265 |
+
elif isinstance(df, dict) and "data" in df:
|
| 266 |
+
rows = df["data"]
|
| 267 |
+
if not rows or row_idx >= len(rows):
|
| 268 |
+
return "Pick a dataset row above to see details and load snippets."
|
| 269 |
+
slug = str(rows[row_idx][0])
|
| 270 |
+
else:
|
| 271 |
+
try:
|
| 272 |
+
slug = str(df[row_idx][0])
|
| 273 |
+
except (IndexError, TypeError, KeyError):
|
| 274 |
+
return "Pick a dataset row above to see details and load snippets."
|
| 275 |
+
return _detail(CATALOG, slug)
|
| 276 |
|
| 277 |
|
| 278 |
def _on_filter(
|
|
|
|
| 356 |
for w in filter_inputs:
|
| 357 |
w.change(_on_filter, filter_inputs, [table, count])
|
| 358 |
|
| 359 |
+
table.select(_on_select, [table], [detail])
|
|
|
|
|
|
|
| 360 |
|
| 361 |
|
| 362 |
if __name__ == "__main__":
|
| 363 |
+
demo.queue().launch(ssr_mode=False)
|