drAIML / app /views /models.py
Gregory-L's picture
drAIML 2.0.0: open healthcare consultation in the browser (stlite)
a709b7a verified
Raw History Blame Contribute Delete
4.93 kB
import pandas as pd
import streamlit as st
from draiml import catalogue, state
state.init()
ss = st.session_state
st.title("🧠 Models")
st.caption("Every model here is open source — an OSI licence on the model **and** on every base model it was built "
"from. MedGemma, Llama- and Gemma-3-based medical models are left out for that reason. Hosted availability "
"is read live from Hugging Face Inference Providers.")
def use(engine: str, model: str, url: str | None = None):
ss.engine, ss.model = engine, model
if url:
ss.custom_url = url
st.switch_page("views/consult.py")
tabs = st.tabs(["Hosted engines", "Medical specialists", "Medical vision", "Tools", "Live Hub search"])
with tabs[0]:
hosted = await catalogue.hosted_engines() # noqa: F704
st.markdown(f"**{len(hosted)}** open chat models are live on HF Inference Providers right now. ★ = recommended "
"for consultation. Calls bill the signed-in visitor's HF account.")
df = pd.DataFrame([{"★": "★" if e["curated"] else "", "model": e["id"], "licence": e["licence"],
"vision": "🖼" if e["vision"] else "", "context": e["ctx"] or None,
"$/M tok (in+out)": e["price_per_m"], "providers": ", ".join(e["providers"]),
"note": e["note"]} for e in hosted])
ev = st.dataframe(df, hide_index=True, use_container_width=True, on_select="rerun", selection_mode="single-row",
column_config={"context": st.column_config.NumberColumn(format="%d"),
"$/M tok (in+out)": st.column_config.NumberColumn(format="%.2f")})
rows = ev.selection.rows if ev and ev.selection else []
if rows:
mid = df.iloc[rows[0]]["model"]
if st.button(f"Consult with {mid}", type="primary"):
use("hf", mid)
with tabs[1]:
st.markdown("Medical fine-tunes with open weights. None is currently served by HF Inference Providers, so run "
"them yourself — one line with [Ollama](https://ollama.com) — and point drAIML at it. drAIML talks to "
"your machine straight from your browser; nothing passes through a server.")
st.code("OLLAMA_ORIGINS=https://pythai-draiml.static.hf.space ollama serve", language="bash")
for m in catalogue.curated_models("specialist"):
with st.container(border=True):
c1, c2 = st.columns([3, 1])
size = f" · {m['params_b']}B" if m.get("params_b") else ""
c1.markdown(f"**[{m['id']}](https://huggingface.co/{m['id']})** · `{m['licence']}`{size} · "
f"{m.get('specialty', '')}")
if m.get("note"):
c1.caption(m["note"])
if m.get("providers"):
c1.success("Live on HF Inference: " + ", ".join(m["providers"]))
cmd = catalogue.ollama_command(m.get("gguf"))
if cmd:
c1.code(cmd, language="bash")
if c2.button("Use via Ollama", key="sp_" + m["id"]):
use("custom", "hf.co/" + m["gguf"], ss.custom_url or "http://localhost:11434/v1")
else:
c1.caption("No open GGUF build found — serve the safetensors with vLLM or TGI, then use “Your endpoint”.")
with tabs[2]:
st.markdown("Open medical vision-language models (radiology, pathology, dermatology). Image upload in the "
"consultation is planned; today use them via your own endpoint.")
for m in catalogue.curated_models("vision") + catalogue.curated_models("vision-engine"):
cmd = catalogue.ollama_command(m.get("gguf"))
st.markdown(f"- **[{m['id']}](https://huggingface.co/{m['id']})** · `{m['licence']}` · {m.get('specialty', m.get('note', ''))}"
+ (f" \n `{cmd}`" if cmd else ""))
with tabs[3]:
st.markdown("Embeddings, encoders, entity recognition and speech — the building blocks.")
tools = [m for m in catalogue.curated()["models"] if m["role"] in ("embedding", "encoder", "ner", "speech")]
st.dataframe(pd.DataFrame([{"model": m["id"], "role": m["role"], "licence": m["licence"],
"hosted": ", ".join(m.get("providers") or []), "note": m.get("note", "")}
for m in tools]), hide_index=True, use_container_width=True)
with tabs[4]:
q = st.text_input("Search the Hub for open medical models", placeholder="radiology, oncology, clinical NER…")
res = await catalogue.hub_search("model", q) # noqa: F704
st.caption(f"{len(res)} open, ungated results tagged `medical` (closed, gated and GGUF repos are hidden). "
"Card licences only — the curated tabs also check base models.")
st.dataframe(pd.DataFrame(res), hide_index=True, use_container_width=True,
column_config={"id": st.column_config.TextColumn("model")})