File size: 2,096 Bytes
a709b7a
 
 
6fc53e8
a709b7a
 
 
 
 
 
 
 
 
 
6fc53e8
 
 
 
a709b7a
 
 
2f6fa33
a709b7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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)