File size: 10,945 Bytes
d418c4b
a709b7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2673d16
a709b7a
 
 
 
 
 
 
 
 
 
 
 
23d27dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a709b7a
 
 
 
 
 
 
 
 
 
23d27dd
a709b7a
 
 
 
 
 
23d27dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a709b7a
 
 
23d27dd
 
 
 
16a2b33
a709b7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23d27dd
16a2b33
6fc53e8
 
 
a709b7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d418c4b
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>drAIML Consultation</title>
<meta name="description" content="drAIML 2.0 — open-source healthcare consultation with open medical models and evidence from openly licensed datasets. Runs in your browser." />
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'><rect width='64' height='64' rx='14' fill='%230e7c7b'/><path d='M27 14h10v13h13v10H37v13H27V37H14V27h13z' fill='white'/></svg>" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@stlite/browser@1.12.1/build/stlite.css" />
<style>
  :root {
    --bg: #f6f8f8; --surface: #ffffff; --ink: #12302f; --muted: #557170; --accent: #0e7c7b; --accent-ink: #ffffff;
    --line: #d9e4e3; --warn: #b4232c;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #0d1716; --surface: #13201f; --ink: #e3efee; --muted: #93aeac; --accent: #3fb5b2; --accent-ink: #062120;
      --line: #22403e; --warn: #f07178;
    }
  }
  :root[data-theme="dark"] {
    --bg: #0d1716; --surface: #13201f; --ink: #e3efee; --muted: #93aeac; --accent: #3fb5b2; --accent-ink: #062120;
    --line: #22403e; --warn: #f07178;
  }
  html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
    font-family: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif; }
  body { display: flex; flex-direction: column; }
  header { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--surface);
    border-bottom: 1px solid var(--line); min-height: 48px; box-sizing: border-box; flex-wrap: wrap; }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; text-decoration: none; color: var(--ink); }
  .brand svg { width: 28px; height: 28px; flex: none; }
  .brand small { font-weight: 500; color: var(--muted); font-size: 0.8rem; }
  .spacer { flex: 1; }
  .who { color: var(--muted); font-size: 0.9rem; }
  [hidden] { display: none !important; }
  button.hf { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface);
    color: var(--ink); border-radius: 8px; padding: 6px 12px; font: inherit; font-size: 0.9rem; cursor: pointer; }
  button.hf.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
  button.hf:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .sos { color: var(--warn); font-size: 0.85rem; font-weight: 600; }
  #root { flex: 1; min-height: 0; position: relative; }
  #boot { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 16px; color: var(--muted); }
  #boot .bar { width: min(320px, 80vw); height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin: 14px auto 0; }
  #boot .bar i { display: block; height: 100%; width: 40%; background: var(--accent); animation: slide 1.4s ease-in-out infinite; }
  @keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }
  @media (prefers-reduced-motion: reduce) { #boot .bar i { animation: none; width: 100%; } }
  @media (max-width: 560px) { .brand small, .sos { display: none; } }
  .chip { font-size: 0.8rem; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
  .chip[data-state="ready"] { color: var(--accent); border-color: var(--accent); }
  dialog#bonsai-agreement { max-width: min(560px, calc(100vw - 32px)); width: 100%; border: 1px solid var(--line);
    border-radius: 14px; padding: 0; background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
  dialog#bonsai-agreement::backdrop { background: rgba(6, 20, 19, .55); }
  .agree { padding: 20px 22px 18px; max-height: calc(100vh - 64px); overflow-y: auto; box-sizing: border-box; }
  .agree h2 { margin: 0 0 4px; font-size: 1.2rem; }
  .agree .lede { margin: 0 0 14px; color: var(--muted); font-size: 0.92rem; }
  .agree h3 { margin: 14px 0 4px; font-size: 0.82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  .agree p, .agree li { font-size: 0.93rem; line-height: 1.45; margin: 0 0 6px; }
  .agree ul { margin: 0; padding-left: 18px; }
  .agree a { color: var(--accent); }
  .agree .warn { color: var(--warn); font-weight: 600; }
  .agree .row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
  .agree .prog { margin-top: 14px; font-size: 0.88rem; color: var(--muted); }
  .agree .prog b { display: block; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
  .agree .prog i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
  button.hf:disabled { opacity: .55; cursor: default; }
</style>
</head>
<body>
<header>
  <a class="brand" href="https://huggingface.co/spaces/PYTHAI/drAIML" target="_top" aria-label="drAIML home">
    <svg viewBox="0 0 64 64" aria-hidden="true"><rect width="64" height="64" rx="14" fill="#0e7c7b"/><path d="M27 14h10v13h13v10H37v13H27V37H14V27h13z" fill="#fff"/></svg>
    <span>drAIML <small>2.0 · open healthcare consultation</small></span>
  </a>
  <span class="spacer"></span>
  <span class="sos">Emergency? Call your local emergency number.</span>
  <span class="chip" id="bonsai-chip" hidden role="status"></span>
  <span class="who" id="who"></span>
  <button class="hf primary" id="signin" hidden>Sign in with Hugging Face</button>
  <button class="hf" id="signout" hidden>Sign out</button>
</header>
<div id="root"><div id="boot"><div><strong>Starting drAIML…</strong><br />Loading Python and Streamlit in your browser (first visit ≈ 20–40 s).<div class="bar"><i></i></div></div></div></div>

<dialog id="bonsai-agreement" aria-labelledby="agree-title">
  <div class="agree">
    <h2 id="agree-title">drAIML Agreement · Bonsai in this browser</h2>
    <p class="lede">Before drAIML puts a medical consultation model inside your browser, please read and agree.</p>
    <h3>What happens</h3>
    <ul>
      <li>drAIML downloads <a href="https://huggingface.co/prism-ml/Bonsai-1.7B-gguf" target="_blank" rel="noopener">Bonsai-1.7B</a>
        (1-bit, 248 MB) once, from Prism ML's Hugging Face repository at a fixed revision, checks it against its published
        sha256 and keeps it in this browser's storage.</li>
      <li>The <a href="https://github.com/browseML/browseML" target="_blank" rel="noopener">browseML</a> engine runs it on your
        own computer. What you type is not sent anywhere: no server, no account, no key, no cost.</li>
      <li>drAIML's open medical evidence is searched in your browser and given to the model with your question.</li>
    </ul>
    <h3>Your health</h3>
    <ul>
      <li>drAIML gives information, <strong>not a diagnosis</strong>, and does not replace a doctor, physiotherapist or therapist.</li>
      <li>Bonsai is a small model: it is quick and private, but makes mistakes more often than large models. Check anything
        important with a clinician.</li>
      <li class="warn">In an emergency, call your local emergency number now.</li>
    </ul>
    <h3>Licences</h3>
    <p>Bonsai-1.7B © Prism ML, Apache-2.0, built from Qwen3-1.7B (Apache-2.0). Created using Bonsai by Prism ML.
      browseML: MIT or Apache-2.0. drAIML: MIT.</p>
    <p>You can remove the model at any time with <em>Remove</em> under Engine in the sidebar.</p>
    <div class="prog" data-progress hidden role="status" aria-live="polite"><span></span><b><i></i></b></div>
    <div class="row">
      <button class="hf" data-decline>Not now</button>
      <button class="hf primary" data-agree>I agree — download 248 MB and start</button>
    </div>
  </div>
</dialog>

<script type="module">
import { mount } from "https://cdn.jsdelivr.net/npm/@stlite/browser@1.12.1/build/stlite.js";
import { oauthLoginUrl, oauthHandleRedirectIfPresent } from "https://cdn.jsdelivr.net/npm/@huggingface/hub@2.17.10/+esm";
import { startBridge } from "./bonsai.js";

// this tab's id: Python (in its Web Worker) and this page find each other by it over a BroadcastChannel
const PAGE_ID = (crypto.randomUUID && crypto.randomUUID()) || String(Math.random()).slice(2);
startBridge(PAGE_ID, { signin: () => document.getElementById("signin").click() });

const KEY = "draiml-oauth";
const vars = (window.huggingface && window.huggingface.variables) || {};
const canOAuth = Boolean(vars.OAUTH_CLIENT_ID);

function readSession() {
  try {
    const s = JSON.parse(localStorage.getItem(KEY) || "null");
    if (s && s.accessToken && (!s.accessTokenExpiresAt || new Date(s.accessTokenExpiresAt) > new Date())) return s;
  } catch (_) { /* storage blocked */ }
  return null;
}

let session = null;
try {
  const fresh = await oauthHandleRedirectIfPresent();
  if (fresh) {
    session = fresh;
    try { localStorage.setItem(KEY, JSON.stringify(fresh)); } catch (_) {}
    history.replaceState(null, "", location.pathname);
  }
} catch (e) { console.warn("[drAIML] oauth redirect", e); }
session = session || readSession();

const who = document.getElementById("who");
const signin = document.getElementById("signin");
const signout = document.getElementById("signout");
if (session) {
  const u = session.userInfo || {};
  who.textContent = u.preferred_username || u.name || "";
  signout.hidden = false;
} else if (canOAuth) {
  signin.hidden = false;
}
signin.onclick = async () => {
  location.href = (await oauthLoginUrl({ scopes: vars.OAUTH_SCOPES || "openid profile inference-api" })) + "&prompt=consent";
};
signout.onclick = () => { try { localStorage.removeItem(KEY); } catch (_) {} location.reload(); };

const manifest = await (await fetch("app/manifest.json", { cache: "no-cache" })).json();
const files = {};
for (const p of manifest.files) files[p] = { url: "app/" + p + "?v=" + manifest.build };

const env = { DRAIML_PAGE_ID: PAGE_ID };
if (canOAuth && !session) env.DRAIML_OAUTH = "1";
if (["127.0.0.1", "localhost"].includes(location.hostname)) {
  env.DRAIML_EVIDENCE_BASE = location.origin + "/build/evidence";  // local development: serve the index you built
}
if (session) {
  env.HF_TOKEN = session.accessToken;
  const u = session.userInfo || {};
  env.HF_USER = u.preferred_username || u.name || "";
}

const dark = document.documentElement.dataset.theme === "dark" ||
  (!document.documentElement.dataset.theme && matchMedia("(prefers-color-scheme: dark)").matches);

document.getElementById("boot").remove();
mount({
  entrypoint: "app.py",
  files,
  requirements: manifest.requirements || [],
  env,
  streamlitConfig: {
    "client.toolbarMode": "viewer",
    "theme.base": dark ? "dark" : "light",
    "theme.primaryColor": dark ? "#3fb5b2" : "#0e7c7b",
  },
}, document.getElementById("root"));
</script>
</body>
</html>