Update static/frontend.html
Browse files- static/frontend.html +127 -129
static/frontend.html
CHANGED
|
@@ -2,154 +2,152 @@
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 6 |
-
<title>
|
| 7 |
<style>
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
}
|
| 18 |
-
input
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
border: 1px solid #ccc;
|
| 36 |
-
margin-top: 1rem;
|
| 37 |
-
}
|
| 38 |
-
.error {
|
| 39 |
-
color: red;
|
| 40 |
-
margin-top: 1rem;
|
| 41 |
-
}
|
| 42 |
</style>
|
| 43 |
</head>
|
| 44 |
<body>
|
| 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 |
<script>
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
const
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
try {
|
| 99 |
-
const response = await fetch('/upload_reports', {
|
| 100 |
-
method: 'POST',
|
| 101 |
-
body: formData
|
| 102 |
-
});
|
| 103 |
-
|
| 104 |
-
if (!response.ok) {
|
| 105 |
-
const errData = await response.json();
|
| 106 |
-
uploadResult.innerHTML = `<p class="error">Error: ${errData.error || response.statusText}</p>`;
|
| 107 |
-
return;
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
const data = await response.json();
|
| 111 |
-
uploadResult.innerHTML = `<h2>Upload Result</h2><pre>${JSON.stringify(data, null, 2)}</pre>`;
|
| 112 |
-
} catch (err) {
|
| 113 |
-
uploadResult.innerHTML = `<p class="error">Upload failed: ${err.message}</p>`;
|
| 114 |
-
}
|
| 115 |
});
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
const resultDiv = document.getElementById('result');
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
| 124 |
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
| 130 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
try {
|
| 135 |
-
const
|
| 136 |
-
method:
|
| 137 |
-
headers: {
|
| 138 |
-
body: JSON.stringify({ patient_id:
|
| 139 |
});
|
|
|
|
|
|
|
| 140 |
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
resultDiv.innerHTML = `<p class="error">Error: ${errorData.error || response.statusText}</p>`;
|
| 144 |
-
return;
|
| 145 |
-
}
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
| 149 |
} catch (err) {
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
| 151 |
}
|
| 152 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
</script>
|
| 154 |
</body>
|
| 155 |
</html>
|
|
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Patient Assistant Chat</title>
|
| 7 |
<style>
|
| 8 |
+
/* your existing styles here */
|
| 9 |
+
:root { --bg:#0f172a; --panel:#111827; --soft:#1f2937; --text:#e5e7eb; --muted:#9ca3af; --accent:#22c55e; }
|
| 10 |
+
* { box-sizing: border-box; }
|
| 11 |
+
body { margin:0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
|
| 12 |
+
.app { max-width: 900px; margin: 0 auto; padding: 20px; }
|
| 13 |
+
.card { background: var(--panel); border: 1px solid #242b3a; border-radius: 16px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
|
| 14 |
+
.header { padding: 16px 20px; border-bottom: 1px solid #242b3a; display: flex; align-items: center; gap: 12px; }
|
| 15 |
+
.badge { background: #0b3b26; color: #8bf2c0; padding: 6px 10px; border-radius: 999px; font-weight: 600; font-size: 12px; letter-spacing: .3px; }
|
| 16 |
+
.row { display:flex; gap:12px; align-items:center; flex-wrap: wrap; }
|
| 17 |
+
label { font-size: 13px; color: var(--muted); }
|
| 18 |
+
input[type="text"] { background: var(--soft); color: var(--text); border: 1px solid #2b3346; padding: 10px 12px; border-radius: 10px; min-width: 200px; outline: none; }
|
| 19 |
+
input[type="text"]:focus { border-color: #374462; box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
|
| 20 |
+
button { background: var(--accent); color: #052e19; border: none; padding: 10px 14px; border-radius: 10px; font-weight: 700; cursor: pointer; }
|
| 21 |
+
button.secondary { background: #334155; color: #dbeafe; }
|
| 22 |
+
button:disabled { opacity: .6; cursor: not-allowed; }
|
| 23 |
+
|
| 24 |
+
.chat { height: 420px; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; background: #0b1220; }
|
| 25 |
+
.msg { max-width: 80%; padding: 10px 12px; border-radius: 12px; border: 1px solid #1f2937; white-space: pre-wrap; word-break: break-word; }
|
| 26 |
+
.user { align-self: flex-end; background: #0b3b26; border-color: #14532d; }
|
| 27 |
+
.assist { align-self: flex-start; background: #111827; border-color: #1f2937; }
|
| 28 |
+
|
| 29 |
+
.composer { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 14px; border-top: 1px solid #242b3a; background: #0b1220; }
|
| 30 |
+
.composer input { width: 100%; }
|
| 31 |
+
|
| 32 |
+
.state { padding: 12px 16px; border-top: 1px dashed #243044; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12px; color: #cbd5e1; background: #0b1220; }
|
| 33 |
+
details > summary { cursor: pointer; }
|
| 34 |
+
.small { font-size: 12px; color: var(--muted); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
</style>
|
| 36 |
</head>
|
| 37 |
<body>
|
| 38 |
+
<div class="app">
|
| 39 |
+
<div class="card">
|
| 40 |
+
<div class="header">
|
| 41 |
+
<span class="badge">Patient Assistant</span>
|
| 42 |
+
<div class="row" style="gap:8px;">
|
| 43 |
+
<label for="pid">Patient ID</label>
|
| 44 |
+
<input id="pid" type="text" placeholder="e.g. 1234" />
|
| 45 |
+
<button id="savePid">Save</button>
|
| 46 |
+
<span id="status" class="small">Disconnected</span>
|
| 47 |
+
</div>
|
| 48 |
+
</div>
|
| 49 |
+
|
| 50 |
+
<div id="chat" class="chat"></div>
|
| 51 |
+
|
| 52 |
+
<div class="composer">
|
| 53 |
+
<input id="message" type="text" placeholder="Type your message…" />
|
| 54 |
+
<button id="send">Send</button>
|
| 55 |
+
</div>
|
| 56 |
+
|
| 57 |
+
<div class="state">
|
| 58 |
+
<details>
|
| 59 |
+
<summary>Agent State (from backend)</summary>
|
| 60 |
+
<pre id="stateView">{}</pre>
|
| 61 |
+
</details>
|
| 62 |
+
</div>
|
| 63 |
+
</div>
|
| 64 |
+
|
| 65 |
+
<p class="small" style="margin-top:10px; opacity:.8">
|
| 66 |
+
Configure your Node API URL in the script below (defaults to <code>/chat</code> on the same origin).
|
| 67 |
+
</p>
|
| 68 |
+
</div>
|
| 69 |
|
| 70 |
<script>
|
| 71 |
+
const NODE_CHAT_ENDPOINT = "/chat";
|
| 72 |
+
|
| 73 |
+
const chatEl = document.getElementById("chat");
|
| 74 |
+
const pidEl = document.getElementById("pid");
|
| 75 |
+
const savePidBtn = document.getElementById("savePid");
|
| 76 |
+
const msgEl = document.getElementById("message");
|
| 77 |
+
const sendBtn = document.getElementById("send");
|
| 78 |
+
const statusEl = document.getElementById("status");
|
| 79 |
+
const stateView = document.getElementById("stateView");
|
| 80 |
+
|
| 81 |
+
let chatHistory = [];
|
| 82 |
+
let patientState = {};
|
| 83 |
+
|
| 84 |
+
// Load saved patient id from localStorage
|
| 85 |
+
pidEl.value = localStorage.getItem("patient_id") || "";
|
| 86 |
+
updateStatus();
|
| 87 |
+
|
| 88 |
+
savePidBtn.addEventListener("click", () => {
|
| 89 |
+
localStorage.setItem("patient_id", pidEl.value.trim());
|
| 90 |
+
updateStatus();
|
| 91 |
+
msgEl.focus();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
});
|
| 93 |
|
| 94 |
+
sendBtn.addEventListener("click", onSend);
|
| 95 |
+
msgEl.addEventListener("keydown", (e) => { if (e.key === "Enter") onSend(); });
|
|
|
|
| 96 |
|
| 97 |
+
function updateStatus() {
|
| 98 |
+
const pid = (pidEl.value || "").trim();
|
| 99 |
+
statusEl.textContent = pid ? `Patient ${pid}` : "No patient selected";
|
| 100 |
+
}
|
| 101 |
|
| 102 |
+
function renderChat() {
|
| 103 |
+
chatEl.innerHTML = "";
|
| 104 |
+
for (const m of chatHistory) {
|
| 105 |
+
const div = document.createElement("div");
|
| 106 |
+
div.className = `msg ${m.role === "user" ? "user" : "assist"}`;
|
| 107 |
+
div.textContent = `${m.role === "user" ? "You" : "Assistant"}: ${m.content}`;
|
| 108 |
+
chatEl.appendChild(div);
|
| 109 |
}
|
| 110 |
+
chatEl.scrollTop = chatEl.scrollHeight;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
async function onSend() {
|
| 114 |
+
const patient_id = (pidEl.value || "").trim();
|
| 115 |
+
const message = (msgEl.value || "").trim();
|
| 116 |
+
if (!patient_id) { alert("Please enter Patient ID"); return; }
|
| 117 |
+
if (!message) return;
|
| 118 |
|
| 119 |
+
chatHistory.push({ role: "user", content: message });
|
| 120 |
+
renderChat();
|
| 121 |
+
msgEl.value = "";
|
| 122 |
+
sendBtn.disabled = true;
|
| 123 |
|
| 124 |
try {
|
| 125 |
+
const res = await fetch(NODE_CHAT_ENDPOINT, {
|
| 126 |
+
method: "POST",
|
| 127 |
+
headers: { "Content-Type": "application/json" },
|
| 128 |
+
body: JSON.stringify({ patient_id, chat_history: chatHistory, patient_state: patientState })
|
| 129 |
});
|
| 130 |
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
| 131 |
+
const data = await res.json();
|
| 132 |
|
| 133 |
+
const reply = data.assistant_reply || "(no reply)";
|
| 134 |
+
patientState = data.updated_state || patientState;
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
+
chatHistory.push({ role: "assistant", content: reply });
|
| 137 |
+
renderChat();
|
| 138 |
+
|
| 139 |
+
stateView.textContent = JSON.stringify(patientState, null, 2);
|
| 140 |
} catch (err) {
|
| 141 |
+
chatHistory.push({ role: "assistant", content: `Error: ${err.message}` });
|
| 142 |
+
renderChat();
|
| 143 |
+
} finally {
|
| 144 |
+
sendBtn.disabled = false;
|
| 145 |
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
// Initial greeting
|
| 149 |
+
chatHistory.push({ role: "assistant", content: "Hello! I am your patient assistant. Set your Patient ID and ask your question." });
|
| 150 |
+
renderChat();
|
| 151 |
</script>
|
| 152 |
</body>
|
| 153 |
</html>
|