Download app/views/datasets.py from PYTHAI/drAIML: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/spaces/PYTHAI/drAIML/resolve/main/app/views/datasets.py
- Command line
-
hf download hf://spaces/PYTHAI/drAIML/app/views/datasets.py
-
curl -L -o datasets.py https://huggingface.co/spaces/PYTHAI/drAIML/resolve/main/app/views/datasets.py
2.1 kB
| import pandas as pd | |
| import streamlit as st | |
| from draiml import catalogue, net, rag, state | |
| state.init() | |
| st.title("📚 Datasets") | |
| st.caption("Openly licensed health datasets on the Hugging Face Hub (OSI licences, CC-BY or CC0; nothing " | |
| "non-commercial, no-derivatives, custom or unlicensed). The ones marked 📌 feed drAIML's evidence index.") | |
| idx = state._index # already loaded if the visitor consulted or searched | |
| if idx is not None: | |
| index_sources = {s["repo"] for s in idx.sources} | |
| else: | |
| try: | |
| index_sources = {s["repo"] for s in (await net.get_json(f"{rag.BASE}/meta.json"))["sources"]} # noqa: F704 | |
| except Exception: | |
| index_sources = set() | |
| cur = catalogue.curated_datasets() | |
| df = pd.DataFrame([{"📌": "📌" if d["id"] in index_sources else "", "dataset": d["id"], "role": d["role"], | |
| "licence": d["licence"], "size": d.get("size") or "", "downloads": d.get("downloads"), | |
| "note": d.get("note", "")} for d in cur]) | |
| ev = st.dataframe(df, hide_index=True, use_container_width=True, on_select="rerun", selection_mode="single-row") | |
| rows = ev.selection.rows if ev and ev.selection else [] | |
| pick = df.iloc[rows[0]]["dataset"] if rows else None | |
| if pick: | |
| st.subheader(pick) | |
| st.markdown(f"[Open on the Hub](https://huggingface.co/datasets/{pick})") | |
| try: | |
| p = await catalogue.dataset_preview(pick, 5) # noqa: F704 | |
| st.caption(f"config `{p['config']}` · split `{p['split']}` · {p['num_rows'] or '?'} rows — first 5:") | |
| st.dataframe(pd.DataFrame(p["rows"]).astype(str), use_container_width=True) | |
| except Exception as e: | |
| st.info(f"No preview available ({e}).") | |
| else: | |
| st.caption("Select a row to preview it.") | |
| st.divider() | |
| st.subheader("Live Hub search") | |
| q = st.text_input("Search the Hub for open medical datasets", placeholder="radiology, ECG, clinical notes…") | |
| res = await catalogue.hub_search("dataset", q) # noqa: F704 | |
| st.caption(f"{len(res)} open, ungated results tagged `medical`.") | |
| st.dataframe(pd.DataFrame(res), hide_index=True, use_container_width=True) | |