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)