Spaces:
Sleeping
Sleeping
Update web/analyzer.html (#20)
Browse files- Update web/analyzer.html (7519932defb2fabbb6b61363212cfab4b47c38b7)
Co-authored-by: Aanya Choudhary <TheFrogGod@users.noreply.huggingface.co>
- web/analyzer.html +197 -274
web/analyzer.html
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
|
@@ -6,34 +6,34 @@ web/analyzer.html<!DOCTYPE html>
|
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
<link rel="stylesheet" href="style.css" />
|
| 9 |
-
|
| 10 |
</head>
|
| 11 |
<body class="bg-[var(--latte-cream)] font-sans text-gray-800 min-h-screen">
|
| 12 |
<!-- NAVBAR -->
|
| 13 |
<nav
|
| 14 |
class="fixed top-0 left-0 w-full z-50 backdrop-blur-md bg-white/20 border-b border-white/30 shadow-md"
|
| 15 |
>
|
| 16 |
-
<div class="flex
|
| 17 |
-
<!-- Logo -->
|
| 18 |
<a
|
| 19 |
href="index.html"
|
| 20 |
class="text-2xl font-bold text-black hover:text-[var(--tropical-indigo)] transition"
|
|
|
|
| 21 |
>
|
| 22 |
-
CTRL + ALT + HEAL
|
| 23 |
-
</a>
|
| 24 |
|
| 25 |
-
<
|
| 26 |
-
|
| 27 |
-
<li><a href="
|
|
|
|
| 28 |
<li><a href="analyzer.html" class="nav-link">Analyzer</a></li>
|
| 29 |
-
<li><a href="past_data.html" class="nav-link
|
| 30 |
-
<li id="authNavItem">
|
|
|
|
|
|
|
| 31 |
</ul>
|
| 32 |
|
| 33 |
<!-- Hamburger Menu -->
|
| 34 |
<button
|
| 35 |
id="hamburger"
|
| 36 |
-
class="md:hidden text-[var(--latte-cream)] text-2xl"
|
| 37 |
>
|
| 38 |
☰
|
| 39 |
</button>
|
|
@@ -44,75 +44,31 @@ web/analyzer.html<!DOCTYPE html>
|
|
| 44 |
id="mobile-menu"
|
| 45 |
class="hidden flex-col space-y-4 bg-white/30 backdrop-blur-lg border border-white/20 rounded-xl shadow-lg mt-2 p-4 mx-6 md:hidden"
|
| 46 |
>
|
| 47 |
-
<li>
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
>
|
| 53 |
-
</li>
|
| 54 |
-
<li>
|
| 55 |
-
<a
|
| 56 |
-
href="analyzer.html"
|
| 57 |
-
class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
|
| 58 |
-
>Analyzer</a
|
| 59 |
-
>
|
| 60 |
-
</li>
|
| 61 |
-
<li>
|
| 62 |
-
<a
|
| 63 |
-
href="profile.html"
|
| 64 |
-
class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
|
| 65 |
-
>Profile</a
|
| 66 |
-
>
|
| 67 |
-
</li>
|
| 68 |
-
<li>
|
| 69 |
-
<a
|
| 70 |
-
href="login.html"
|
| 71 |
-
class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
|
| 72 |
-
>Login</a
|
| 73 |
-
>
|
| 74 |
-
</li>
|
| 75 |
-
<li>
|
| 76 |
-
<a
|
| 77 |
-
href="about.html"
|
| 78 |
-
class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
|
| 79 |
-
>About</a
|
| 80 |
-
>
|
| 81 |
-
</li>
|
| 82 |
-
|
| 83 |
-
>
|
| 84 |
-
</li>
|
| 85 |
</ul>
|
| 86 |
</nav>
|
| 87 |
|
| 88 |
-
<!--Shared helpers
|
| 89 |
<script src="script.js"></script>
|
| 90 |
<script>
|
| 91 |
const hamburger = document.getElementById("hamburger");
|
| 92 |
const mobileMenu = document.getElementById("mobile-menu");
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
-
|
| 95 |
-
mobileMenu.classList.toggle("hidden");
|
| 96 |
-
});
|
| 97 |
-
|
| 98 |
-
// Underline the active page only
|
| 99 |
const currentPath = window.location.pathname.split("/").pop();
|
| 100 |
-
|
| 101 |
document.querySelectorAll(".nav-link").forEach((link) => {
|
| 102 |
-
if (link.getAttribute("href") === currentPath)
|
| 103 |
-
link.classList.add("active-page"); // we'll style this in CSS
|
| 104 |
-
}
|
| 105 |
-
});
|
| 106 |
-
|
| 107 |
-
document.querySelectorAll("#mobile-menu a").forEach((link) => {
|
| 108 |
-
if (link.getAttribute("href") === currentPath) {
|
| 109 |
link.classList.add("active-page");
|
| 110 |
-
}
|
| 111 |
});
|
| 112 |
</script>
|
| 113 |
|
| 114 |
-
<!-- CHANGE MARKER TO USE THIS -->
|
| 115 |
-
<!-- secound change marker-->
|
| 116 |
<main class="max-w-5xl mx-auto px-4 mb-16 pt-24">
|
| 117 |
<!-- Upload Section -->
|
| 118 |
<div class="bg-white border border-gray-200 rounded-lg p-6 shadow mb-6">
|
|
@@ -134,45 +90,79 @@ web/analyzer.html<!DOCTYPE html>
|
|
| 134 |
</p>
|
| 135 |
</div>
|
| 136 |
|
| 137 |
-
<!--
|
| 138 |
<div
|
| 139 |
class="bg-[var(--latte-cream)] border border-[var(--wisteria)] rounded-lg p-6 mb-8"
|
| 140 |
>
|
| 141 |
-
<h3 class="text-lg font-semibold mb-3">
|
| 142 |
<div
|
| 143 |
-
id="
|
| 144 |
-
class="bg-[#
|
| 145 |
>
|
| 146 |
-
|
| 147 |
</div>
|
| 148 |
</div>
|
| 149 |
|
| 150 |
-
<!--
|
| 151 |
<div
|
| 152 |
class="bg-[var(--latte-cream)] border border-[var(--wisteria)] rounded-lg p-6 mb-8"
|
| 153 |
>
|
| 154 |
-
<h3 class="text-lg font-semibold mb-3">
|
| 155 |
<div
|
| 156 |
-
id="
|
| 157 |
-
class="
|
| 158 |
>
|
| 159 |
-
|
| 160 |
-
</div>
|
| 161 |
-
<div class="flex mt-4 gap-2">
|
| 162 |
-
<input
|
| 163 |
-
type="text"
|
| 164 |
-
id="user-question"
|
| 165 |
-
placeholder="Ask a question..."
|
| 166 |
-
class="flex-1 rounded px-3 py-2 focus:outline-none"
|
| 167 |
-
/>
|
| 168 |
-
<button id="ask-btn" class="btn-primary px-4 py-2 rounded">
|
| 169 |
-
Ask
|
| 170 |
-
</button>
|
| 171 |
</div>
|
| 172 |
</div>
|
| 173 |
</main>
|
| 174 |
|
| 175 |
-
<!--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
<script type="module">
|
| 177 |
import {
|
| 178 |
getFirestore,
|
|
@@ -205,47 +195,39 @@ web/analyzer.html<!DOCTYPE html>
|
|
| 205 |
window.firestoreDb = db;
|
| 206 |
window.firestoreHelpers = { collection, doc, addDoc, serverTimestamp };
|
| 207 |
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
const
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
// Hide Profile and Past Reports
|
| 242 |
-
if (profileNavDesktop) profileNavDesktop.style.display = "none";
|
| 243 |
-
if (pastNavDesktop) pastNavDesktop.style.display = "none";
|
| 244 |
-
if (profileNavMobile) profileNavMobile.style.display = "none";
|
| 245 |
-
if (pastNavMobile) pastNavMobile.style.display = "none";
|
| 246 |
-
}
|
| 247 |
-
}
|
| 248 |
-
});
|
| 249 |
|
| 250 |
window.logout = async () => {
|
| 251 |
try {
|
|
@@ -258,6 +240,7 @@ const profileNavDesktop = document.querySelector('ul.md\\:flex li a[href="profil
|
|
| 258 |
};
|
| 259 |
</script>
|
| 260 |
|
|
|
|
| 261 |
<script type="module">
|
| 262 |
import {
|
| 263 |
pipeline,
|
|
@@ -265,41 +248,14 @@ const profileNavDesktop = document.querySelector('ul.md\\:flex li a[href="profil
|
|
| 265 |
} from "https://cdn.jsdelivr.net/npm/@xenova/transformers@2.6.0";
|
| 266 |
|
| 267 |
const loadingEl = document.getElementById("loading");
|
| 268 |
-
|
| 269 |
const recsOutput = document.getElementById("recommendations-output");
|
| 270 |
-
const
|
| 271 |
-
"detected-measurement-results"
|
| 272 |
-
);
|
| 273 |
const authStatus = document.getElementById("auth-status");
|
| 274 |
let extractedText = "";
|
| 275 |
let currentUser = null;
|
| 276 |
|
| 277 |
-
|
| 278 |
-
.getElementById("pdf-upload")
|
| 279 |
-
.addEventListener("change", function () {
|
| 280 |
-
loadingEl.textContent = this.files.length
|
| 281 |
-
? `File selected: ${this.files[0].name}`
|
| 282 |
-
: "No file uploaded yet.";
|
| 283 |
-
});
|
| 284 |
-
|
| 285 |
-
const saveAnalysis = async (uid, payload) => {
|
| 286 |
-
try {
|
| 287 |
-
const docRef = await firebase
|
| 288 |
-
.firestore()
|
| 289 |
-
.collection("users")
|
| 290 |
-
.doc(uid)
|
| 291 |
-
.collection("analyses")
|
| 292 |
-
.add({
|
| 293 |
-
...payload,
|
| 294 |
-
createdAt: serverTimestamp(),
|
| 295 |
-
});
|
| 296 |
-
return docRef.id;
|
| 297 |
-
} catch (e) {
|
| 298 |
-
console.error("Failed to save analysis:", e);
|
| 299 |
-
}
|
| 300 |
-
};
|
| 301 |
-
|
| 302 |
-
const renderRecCard = (rec, idx) => {
|
| 303 |
const sev = (rec.severity || "").toLowerCase();
|
| 304 |
const sevClass = sev.includes("severe")
|
| 305 |
? "badge-high"
|
|
@@ -316,21 +272,21 @@ const profileNavDesktop = document.querySelector('ul.md\\:flex li a[href="profil
|
|
| 316 |
</div>
|
| 317 |
<ul class="rec-content space-y-1">
|
| 318 |
<li><em>Recommendations:</em>
|
| 319 |
-
<ul class="list-disc list-inside ml-6">
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
</li>
|
| 325 |
<li><em>Treatment:</em> ${
|
| 326 |
rec.treatment_suggestions || "Not available"
|
| 327 |
}</li>
|
| 328 |
<li><em>Home Care:</em>
|
| 329 |
-
<ul class="list-disc list-inside ml-6">
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
</li>
|
| 335 |
${
|
| 336 |
rec.info_link
|
|
@@ -338,20 +294,40 @@ const profileNavDesktop = document.querySelector('ul.md\\:flex li a[href="profil
|
|
| 338 |
: ""
|
| 339 |
}
|
| 340 |
</ul>
|
| 341 |
-
</div>
|
| 342 |
-
|
| 343 |
-
};
|
| 344 |
|
| 345 |
window.onAuthStateChanged(window.firebaseAuth, (user) => {
|
| 346 |
currentUser = user;
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
authStatus.textContent =
|
| 351 |
-
"Not signed in. Sign in to save and view past analyses.";
|
| 352 |
-
}
|
| 353 |
});
|
| 354 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
document
|
| 356 |
.getElementById("analyze-btn")
|
| 357 |
.addEventListener("click", async () => {
|
|
@@ -362,7 +338,7 @@ const profileNavDesktop = document.querySelector('ul.md\\:flex li a[href="profil
|
|
| 362 |
}
|
| 363 |
|
| 364 |
loadingEl.textContent = "Processing with AI...";
|
| 365 |
-
|
| 366 |
recsOutput.textContent = "";
|
| 367 |
|
| 368 |
const formData = new FormData();
|
|
@@ -384,119 +360,66 @@ const profileNavDesktop = document.querySelector('ul.md\\:flex li a[href="profil
|
|
| 384 |
}
|
| 385 |
|
| 386 |
extractedText = data.ocr_text || "";
|
| 387 |
-
|
| 388 |
|
| 389 |
const recs = Array.isArray(data.Detected_Anomolies)
|
| 390 |
? data.Detected_Anomolies
|
| 391 |
: data.Detected_Anomolies
|
| 392 |
? [data.Detected_Anomolies]
|
| 393 |
: [];
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
.join("");
|
| 398 |
-
} else {
|
| 399 |
-
recsOutput.textContent = "No recommendations found.";
|
| 400 |
-
}
|
| 401 |
-
|
| 402 |
-
const findings = Array.isArray(data.Detected_Measurement_Values)
|
| 403 |
-
? data.Detected_Measurement_Values
|
| 404 |
-
: data.Detected_Measurement_Values
|
| 405 |
-
? [data.Detected_Measurement_Values]
|
| 406 |
-
: [];
|
| 407 |
-
if (data.Detected_Measurement_Values) {
|
| 408 |
-
findingsOutput.innerHTML = findings
|
| 409 |
-
.map((finding, i) => renderRecCard(finding, i))
|
| 410 |
-
.join("");
|
| 411 |
-
}
|
| 412 |
|
| 413 |
if (currentUser) {
|
| 414 |
-
/*await saveAnalysis(currentUser.uid, {
|
| 415 |
-
reportDate: date,
|
| 416 |
-
ocr_text: extractedText,
|
| 417 |
-
resolutions: recs,
|
| 418 |
-
measurements: findings,
|
| 419 |
-
});*/
|
| 420 |
await postReportToBackend({
|
| 421 |
user_id: currentUser.email,
|
| 422 |
report_date: new Date(),
|
| 423 |
ocr_text: extractedText,
|
| 424 |
anomalies: JSON.stringify(recs),
|
| 425 |
-
measurements: JSON.stringify(findings),
|
| 426 |
});
|
| 427 |
}
|
| 428 |
-
|
| 429 |
loadingEl.textContent = "Analysis complete.";
|
| 430 |
});
|
| 431 |
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
},
|
| 439 |
-
body: JSON.stringify(report),
|
| 440 |
-
});
|
| 441 |
-
if (!response.ok) {
|
| 442 |
-
throw new Error(`HTTP error! status: ${response.status}`);
|
| 443 |
-
}
|
| 444 |
-
const data = await response.json();
|
| 445 |
-
console.log('Report successfully sent to backend:', data);
|
| 446 |
-
} catch (error) {
|
| 447 |
-
console.error('Error sending report to backend:', error);
|
| 448 |
-
}
|
| 449 |
}
|
| 450 |
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
}
|
| 482 |
-
|
| 483 |
-
const data = await response.json();
|
| 484 |
-
|
| 485 |
-
//now addign acctual reposnse
|
| 486 |
-
const messages = chat.querySelectorAll('p');
|
| 487 |
-
const lastMessage = messages[messages.length - 1];
|
| 488 |
-
lastMessage.innerHTML = `<strong>Chatbot:</strong> ${data.answer}`;
|
| 489 |
-
|
| 490 |
-
} catch (error) {
|
| 491 |
-
console.error("Error:", error);
|
| 492 |
-
const messages = chat.querySelectorAll('p');
|
| 493 |
-
const lastMessage = messages[messages.length - 1];
|
| 494 |
-
lastMessage.innerHTML = `<strong>Chatbot:</strong> Sorry, I encountered an error: ${error.message}`;
|
| 495 |
-
}
|
| 496 |
-
|
| 497 |
-
document.getElementById("user-question").value = "";
|
| 498 |
-
chat.scrollTop = chat.scrollHeight;
|
| 499 |
-
};
|
| 500 |
</script>
|
| 501 |
</body>
|
| 502 |
-
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
|
|
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
<link rel="stylesheet" href="style.css" />
|
|
|
|
| 9 |
</head>
|
| 10 |
<body class="bg-[var(--latte-cream)] font-sans text-gray-800 min-h-screen">
|
| 11 |
<!-- NAVBAR -->
|
| 12 |
<nav
|
| 13 |
class="fixed top-0 left-0 w-full z-50 backdrop-blur-md bg-white/20 border-b border-white/30 shadow-md"
|
| 14 |
>
|
| 15 |
+
<div class="flex items-center px-6 py-4 max-w-7xl mx-auto">
|
|
|
|
| 16 |
<a
|
| 17 |
href="index.html"
|
| 18 |
class="text-2xl font-bold text-black hover:text-[var(--tropical-indigo)] transition"
|
| 19 |
+
>CTRL + ALT + HEAL</a
|
| 20 |
>
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
<!-- Desktop Links -->
|
| 23 |
+
<ul class="hidden md:flex space-x-6 font-medium text-gray-800 ml-auto">
|
| 24 |
+
<li><a href="index.html" class="nav-link">Home</a></li>
|
| 25 |
+
<li><a href="profile.html" class="nav-link">Profile</a></li>
|
| 26 |
<li><a href="analyzer.html" class="nav-link">Analyzer</a></li>
|
| 27 |
+
<li><a href="past_data.html" class="nav-link">Past Reports</a></li>
|
| 28 |
+
<li id="authNavItem">
|
| 29 |
+
<a href="login.html" class="nav-link">Login</a>
|
| 30 |
+
</li>
|
| 31 |
</ul>
|
| 32 |
|
| 33 |
<!-- Hamburger Menu -->
|
| 34 |
<button
|
| 35 |
id="hamburger"
|
| 36 |
+
class="md:hidden text-[var(--latte-cream)] text-2xl ml-auto"
|
| 37 |
>
|
| 38 |
☰
|
| 39 |
</button>
|
|
|
|
| 44 |
id="mobile-menu"
|
| 45 |
class="hidden flex-col space-y-4 bg-white/30 backdrop-blur-lg border border-white/20 rounded-xl shadow-lg mt-2 p-4 mx-6 md:hidden"
|
| 46 |
>
|
| 47 |
+
<li><a href="index.html" class="block nav-link">Home</a></li>
|
| 48 |
+
<li><a href="analyzer.html" class="block nav-link">Analyzer</a></li>
|
| 49 |
+
<li><a href="profile.html" class="block nav-link">Profile</a></li>
|
| 50 |
+
<li><a href="login.html" class="block nav-link">Login</a></li>
|
| 51 |
+
<li><a href="about.html" class="block nav-link">About</a></li>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
</ul>
|
| 53 |
</nav>
|
| 54 |
|
| 55 |
+
<!-- Shared helpers -->
|
| 56 |
<script src="script.js"></script>
|
| 57 |
<script>
|
| 58 |
const hamburger = document.getElementById("hamburger");
|
| 59 |
const mobileMenu = document.getElementById("mobile-menu");
|
| 60 |
+
hamburger.addEventListener("click", () =>
|
| 61 |
+
mobileMenu.classList.toggle("hidden")
|
| 62 |
+
);
|
| 63 |
|
| 64 |
+
// Active page underline
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
const currentPath = window.location.pathname.split("/").pop();
|
|
|
|
| 66 |
document.querySelectorAll(".nav-link").forEach((link) => {
|
| 67 |
+
if (link.getAttribute("href") === currentPath)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
link.classList.add("active-page");
|
|
|
|
| 69 |
});
|
| 70 |
</script>
|
| 71 |
|
|
|
|
|
|
|
| 72 |
<main class="max-w-5xl mx-auto px-4 mb-16 pt-24">
|
| 73 |
<!-- Upload Section -->
|
| 74 |
<div class="bg-white border border-gray-200 rounded-lg p-6 shadow mb-6">
|
|
|
|
| 90 |
</p>
|
| 91 |
</div>
|
| 92 |
|
| 93 |
+
<!-- Extracted Text -->
|
| 94 |
<div
|
| 95 |
class="bg-[var(--latte-cream)] border border-[var(--wisteria)] rounded-lg p-6 mb-8"
|
| 96 |
>
|
| 97 |
+
<h3 class="text-lg font-semibold mb-3">Extracted Text</h3>
|
| 98 |
<div
|
| 99 |
+
id="text-output"
|
| 100 |
+
class="whitespace-pre-wrap h-60 overflow-auto bg-[#FAFBFC] text-sm border border-[var(--wisteria)] rounded p-4"
|
| 101 |
>
|
| 102 |
+
OCR results will appear here.
|
| 103 |
</div>
|
| 104 |
</div>
|
| 105 |
|
| 106 |
+
<!-- AI Findings -->
|
| 107 |
<div
|
| 108 |
class="bg-[var(--latte-cream)] border border-[var(--wisteria)] rounded-lg p-6 mb-8"
|
| 109 |
>
|
| 110 |
+
<h3 class="text-lg font-semibold mb-3">AI Findings</h3>
|
| 111 |
<div
|
| 112 |
+
id="recommendations-output"
|
| 113 |
+
class="bg-[#F9FAFB] text-sm border border-[var(--wisteria)] rounded p-4 space-y-4"
|
| 114 |
>
|
| 115 |
+
Findings and Recommendations will appear here.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
</div>
|
| 117 |
</div>
|
| 118 |
</main>
|
| 119 |
|
| 120 |
+
<!-- Floating Chat Button -->
|
| 121 |
+
<button
|
| 122 |
+
id="chat-toggle"
|
| 123 |
+
class="fixed bottom-6 right-6 bg-[var(--tropical-indigo)] text-white px-5 py-3 rounded-full shadow-lg hover:scale-105 transition"
|
| 124 |
+
>
|
| 125 |
+
💬 Chat
|
| 126 |
+
</button>
|
| 127 |
+
|
| 128 |
+
<!-- Chatbot Drawer -->
|
| 129 |
+
<div
|
| 130 |
+
id="chat-drawer"
|
| 131 |
+
class="fixed top-16 right-0 w-96 max-w-full h-[calc(100%-4rem)] bg-white shadow-lg border-l border-gray-200 transform translate-x-full transition-transform duration-300 ease-in-out z-40 flex flex-col"
|
| 132 |
+
>
|
| 133 |
+
<div class="flex justify-between items-center p-4 border-b">
|
| 134 |
+
<h3 class="text-lg font-semibold">Ask Chatbot</h3>
|
| 135 |
+
<button id="chat-close" class="text-gray-600 hover:text-black text-xl">
|
| 136 |
+
✖
|
| 137 |
+
</button>
|
| 138 |
+
</div>
|
| 139 |
+
<div id="chat-output" class="flex-1 overflow-auto p-4 space-y-2 text-sm">
|
| 140 |
+
<p><strong>Chatbot:</strong> Ask me something about your report</p>
|
| 141 |
+
</div>
|
| 142 |
+
<div class="flex gap-2 p-4 border-t">
|
| 143 |
+
<input
|
| 144 |
+
type="text"
|
| 145 |
+
id="user-question"
|
| 146 |
+
placeholder="Ask a question..."
|
| 147 |
+
class="flex-1 rounded px-3 py-2 focus:outline-none border"
|
| 148 |
+
/>
|
| 149 |
+
<button id="ask-btn" class="btn-primary px-4 py-2 rounded">Ask</button>
|
| 150 |
+
</div>
|
| 151 |
+
</div>
|
| 152 |
+
|
| 153 |
+
<script>
|
| 154 |
+
const chatDrawer = document.getElementById("chat-drawer");
|
| 155 |
+
const chatToggle = document.getElementById("chat-toggle");
|
| 156 |
+
const chatClose = document.getElementById("chat-close");
|
| 157 |
+
chatToggle.addEventListener("click", () =>
|
| 158 |
+
chatDrawer.classList.toggle("translate-x-full")
|
| 159 |
+
);
|
| 160 |
+
chatClose.addEventListener("click", () =>
|
| 161 |
+
chatDrawer.classList.add("translate-x-full")
|
| 162 |
+
);
|
| 163 |
+
</script>
|
| 164 |
+
|
| 165 |
+
<!-- Firebase Auth + Firestore -->
|
| 166 |
<script type="module">
|
| 167 |
import {
|
| 168 |
getFirestore,
|
|
|
|
| 195 |
window.firestoreDb = db;
|
| 196 |
window.firestoreHelpers = { collection, doc, addDoc, serverTimestamp };
|
| 197 |
|
| 198 |
+
onAuthStateChanged(auth, (user) => {
|
| 199 |
+
const authNavItem = document.getElementById("authNavItem");
|
| 200 |
+
const profileNavDesktop = document.querySelector(
|
| 201 |
+
'ul.md\\:flex li a[href="profile.html"]'
|
| 202 |
+
)?.parentElement;
|
| 203 |
+
const pastNavDesktop = document.querySelector(
|
| 204 |
+
'ul.md\\:flex li a[href="past_data.html"]'
|
| 205 |
+
)?.parentElement;
|
| 206 |
+
const profileNavMobile = document.querySelector(
|
| 207 |
+
'#mobile-menu a[href="profile.html"]'
|
| 208 |
+
)?.parentElement;
|
| 209 |
+
const pastNavMobile = document.querySelector(
|
| 210 |
+
'#mobile-menu a[href="past_data.html"]'
|
| 211 |
+
)?.parentElement;
|
| 212 |
+
|
| 213 |
+
if (authNavItem) {
|
| 214 |
+
if (user) {
|
| 215 |
+
authNavItem.innerHTML =
|
| 216 |
+
'<button onclick="logout()" class="hover:text-[#6B9080] text-red-600">Logout</button>';
|
| 217 |
+
if (profileNavDesktop) profileNavDesktop.style.display = "block";
|
| 218 |
+
if (pastNavDesktop) pastNavDesktop.style.display = "block";
|
| 219 |
+
if (profileNavMobile) profileNavMobile.style.display = "block";
|
| 220 |
+
if (pastNavMobile) pastNavMobile.style.display = "block";
|
| 221 |
+
} else {
|
| 222 |
+
authNavItem.innerHTML =
|
| 223 |
+
'<a href="login.html" class="hover:text-[#6B9080]">Login</a>';
|
| 224 |
+
if (profileNavDesktop) profileNavDesktop.style.display = "none";
|
| 225 |
+
if (pastNavDesktop) pastNavDesktop.style.display = "none";
|
| 226 |
+
if (profileNavMobile) profileNavMobile.style.display = "none";
|
| 227 |
+
if (pastNavMobile) pastNavMobile.style.display = "none";
|
| 228 |
+
}
|
| 229 |
+
}
|
| 230 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
|
| 232 |
window.logout = async () => {
|
| 233 |
try {
|
|
|
|
| 240 |
};
|
| 241 |
</script>
|
| 242 |
|
| 243 |
+
<!-- Analyzer + Chatbot -->
|
| 244 |
<script type="module">
|
| 245 |
import {
|
| 246 |
pipeline,
|
|
|
|
| 248 |
} from "https://cdn.jsdelivr.net/npm/@xenova/transformers@2.6.0";
|
| 249 |
|
| 250 |
const loadingEl = document.getElementById("loading");
|
| 251 |
+
const textOutput = document.getElementById("text-output");
|
| 252 |
const recsOutput = document.getElementById("recommendations-output");
|
| 253 |
+
const chat = document.getElementById("chat-output");
|
|
|
|
|
|
|
| 254 |
const authStatus = document.getElementById("auth-status");
|
| 255 |
let extractedText = "";
|
| 256 |
let currentUser = null;
|
| 257 |
|
| 258 |
+
function renderRecCard(rec, idx) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
const sev = (rec.severity || "").toLowerCase();
|
| 260 |
const sevClass = sev.includes("severe")
|
| 261 |
? "badge-high"
|
|
|
|
| 272 |
</div>
|
| 273 |
<ul class="rec-content space-y-1">
|
| 274 |
<li><em>Recommendations:</em>
|
| 275 |
+
<ul class="list-disc list-inside ml-6">${(
|
| 276 |
+
rec.recommendations || []
|
| 277 |
+
)
|
| 278 |
+
.map((r) => `<li>${r}</li>`)
|
| 279 |
+
.join("")}</ul>
|
| 280 |
</li>
|
| 281 |
<li><em>Treatment:</em> ${
|
| 282 |
rec.treatment_suggestions || "Not available"
|
| 283 |
}</li>
|
| 284 |
<li><em>Home Care:</em>
|
| 285 |
+
<ul class="list-disc list-inside ml-6">${(
|
| 286 |
+
rec.home_care_guidance || []
|
| 287 |
+
)
|
| 288 |
+
.map((r) => `<li>${r}</li>`)
|
| 289 |
+
.join("")}</ul>
|
| 290 |
</li>
|
| 291 |
${
|
| 292 |
rec.info_link
|
|
|
|
| 294 |
: ""
|
| 295 |
}
|
| 296 |
</ul>
|
| 297 |
+
</div>`;
|
| 298 |
+
}
|
|
|
|
| 299 |
|
| 300 |
window.onAuthStateChanged(window.firebaseAuth, (user) => {
|
| 301 |
currentUser = user;
|
| 302 |
+
authStatus.textContent = user
|
| 303 |
+
? `Signed in as ${user.email || user.uid}`
|
| 304 |
+
: "Not signed in. Sign in to save and view past analyses.";
|
|
|
|
|
|
|
|
|
|
| 305 |
});
|
| 306 |
|
| 307 |
+
document
|
| 308 |
+
.getElementById("pdf-upload")
|
| 309 |
+
.addEventListener("change", function () {
|
| 310 |
+
loadingEl.textContent = this.files.length
|
| 311 |
+
? `File selected: ${this.files[0].name}`
|
| 312 |
+
: "No file uploaded yet.";
|
| 313 |
+
});
|
| 314 |
+
|
| 315 |
+
async function postReportToBackend(report) {
|
| 316 |
+
try {
|
| 317 |
+
const response = await fetch(api("save_report/"), {
|
| 318 |
+
method: "POST",
|
| 319 |
+
headers: { "Content-Type": "application/json" },
|
| 320 |
+
body: JSON.stringify(report),
|
| 321 |
+
});
|
| 322 |
+
if (!response.ok)
|
| 323 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
| 324 |
+
const data = await response.json();
|
| 325 |
+
console.log("Report sent to backend:", data);
|
| 326 |
+
} catch (error) {
|
| 327 |
+
console.error("Error sending report:", error);
|
| 328 |
+
}
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
document
|
| 332 |
.getElementById("analyze-btn")
|
| 333 |
.addEventListener("click", async () => {
|
|
|
|
| 338 |
}
|
| 339 |
|
| 340 |
loadingEl.textContent = "Processing with AI...";
|
| 341 |
+
textOutput.textContent = "";
|
| 342 |
recsOutput.textContent = "";
|
| 343 |
|
| 344 |
const formData = new FormData();
|
|
|
|
| 360 |
}
|
| 361 |
|
| 362 |
extractedText = data.ocr_text || "";
|
| 363 |
+
textOutput.textContent = extractedText;
|
| 364 |
|
| 365 |
const recs = Array.isArray(data.Detected_Anomolies)
|
| 366 |
? data.Detected_Anomolies
|
| 367 |
: data.Detected_Anomolies
|
| 368 |
? [data.Detected_Anomolies]
|
| 369 |
: [];
|
| 370 |
+
recsOutput.innerHTML = recs.length
|
| 371 |
+
? recs.map(renderRecCard).join("")
|
| 372 |
+
: "No recommendations found.";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
|
| 374 |
if (currentUser) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
await postReportToBackend({
|
| 376 |
user_id: currentUser.email,
|
| 377 |
report_date: new Date(),
|
| 378 |
ocr_text: extractedText,
|
| 379 |
anomalies: JSON.stringify(recs),
|
|
|
|
| 380 |
});
|
| 381 |
}
|
|
|
|
| 382 |
loadingEl.textContent = "Analysis complete.";
|
| 383 |
});
|
| 384 |
|
| 385 |
+
document.getElementById("ask-btn").onclick = async () => {
|
| 386 |
+
const q = document.getElementById("user-question").value.trim();
|
| 387 |
+
if (!q) return;
|
| 388 |
+
if (!extractedText) {
|
| 389 |
+
alert("Please analyze a document first.");
|
| 390 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
}
|
| 392 |
|
| 393 |
+
chat.innerHTML += `<p><strong>You:</strong> ${q}</p>`;
|
| 394 |
+
chat.innerHTML += `<p><strong>Chatbot:</strong> <em>Thinking...</em></p>`;
|
| 395 |
+
chat.scrollTop = chat.scrollHeight;
|
| 396 |
+
|
| 397 |
+
try {
|
| 398 |
+
const res = await fetch(api("chat/"), {
|
| 399 |
+
method: "POST",
|
| 400 |
+
headers: { "Content-Type": "application/json" },
|
| 401 |
+
body: JSON.stringify({
|
| 402 |
+
question: q,
|
| 403 |
+
user_id: currentUser ? currentUser.uid : "anonymous",
|
| 404 |
+
}),
|
| 405 |
+
});
|
| 406 |
+
if (!res.ok) throw new Error(await res.text());
|
| 407 |
+
const data = await res.json();
|
| 408 |
+
const last = chat.querySelectorAll("p");
|
| 409 |
+
last[
|
| 410 |
+
last.length - 1
|
| 411 |
+
].innerHTML = `<strong>Chatbot:</strong> ${data.answer}`;
|
| 412 |
+
} catch (err) {
|
| 413 |
+
console.error("Error:", err);
|
| 414 |
+
const last = chat.querySelectorAll("p");
|
| 415 |
+
last[
|
| 416 |
+
last.length - 1
|
| 417 |
+
].innerHTML = `<strong>Chatbot:</strong> Sorry, error: ${err.message}`;
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
document.getElementById("user-question").value = "";
|
| 421 |
+
chat.scrollTop = chat.scrollHeight;
|
| 422 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
</script>
|
| 424 |
</body>
|
| 425 |
+
</html>
|