TheFrogGod commited on
Commit
e6b7c34
·
verified ·
1 Parent(s): cdea9a5

Update web/analyzer.html

Browse files
Files changed (1) hide show
  1. web/analyzer.html +189 -279
web/analyzer.html CHANGED
@@ -1,4 +1,4 @@
1
- web/analyzer.html<!DOCTYPE html>
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 justify-between items-center w-full px-6 py-4">
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
- <ul class="hidden md:flex space-x-6 font-medium text-gray-800">
26
- <li><a href="index.html" class="nav-link ">Home</a></li>
27
- <li><a href="profile.html" class="nav-link ">Profile</a></li>
 
28
  <li><a href="analyzer.html" class="nav-link">Analyzer</a></li>
29
- <li><a href="past_data.html" class="nav-link ">Past Reports</a></li>
30
- <li id="authNavItem"><a href="login.html" class="nav-link">Login</a></li>
 
 
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
- <a
49
- href="index.html"
50
- class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
51
- >Home</a
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 (API base + query params) -->
89
  <script src="script.js"></script>
90
  <script>
91
  const hamburger = document.getElementById("hamburger");
92
  const mobileMenu = document.getElementById("mobile-menu");
 
 
 
93
 
94
- hamburger.addEventListener("click", () => {
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">
@@ -159,33 +115,54 @@ web/analyzer.html<!DOCTYPE html>
159
  Findings and Recommendations will appear here.
160
  </div>
161
  </div>
 
162
 
163
- <!-- Chatbot -->
164
- <div
165
- class="bg-[var(--latte-cream)] border border-[var(--wisteria)] rounded-lg p-6 mb-8"
166
- >
167
- <h3 class="text-lg font-semibold mb-3">Ask Chatbot</h3>
168
- <div
169
- id="chat-output"
170
- class="space-y-2 h-48 overflow-auto text-sm rounded p-4"
171
- >
172
- <p><strong>Chatbot:</strong> Ask me something about your report</p>
173
- </div>
174
- <div class="flex mt-4 gap-2">
175
- <input
176
- type="text"
177
- id="user-question"
178
- placeholder="Ask a question..."
179
- class="flex-1 rounded px-3 py-2 focus:outline-none"
180
- />
181
- <button id="ask-btn" class="btn-primary px-4 py-2 rounded">
182
- Ask
183
- </button>
184
- </div>
185
  </div>
186
- </main>
 
 
 
 
 
 
 
 
 
 
 
 
187
 
188
- <!-- Firebase -->
 
 
 
 
 
 
 
 
 
 
 
 
189
  <script type="module">
190
  import {
191
  getFirestore,
@@ -202,12 +179,12 @@ web/analyzer.html<!DOCTYPE html>
202
  } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-auth.js";
203
 
204
  const firebaseConfig = {
205
- apiKey: "AIzaSyAPhM_Ee7cLzyKHs5zyFy8g5ZOk9-pubRI",
206
- authDomain: "login-tutorial-7a9e1.firebaseapp.com",
207
- projectId: "login-tutorial-7a9e1",
208
- storageBucket: "login-tutorial-7a9e1.firebasestorage.app",
209
- messagingSenderId: "491093197824",
210
- appId: "1:491093197824:web:9f866...",
211
  };
212
 
213
  const app = initializeApp(firebaseConfig);
@@ -218,47 +195,39 @@ web/analyzer.html<!DOCTYPE html>
218
  window.firestoreDb = db;
219
  window.firestoreHelpers = { collection, doc, addDoc, serverTimestamp };
220
 
221
- onAuthStateChanged(auth, (user) => {
222
- const authNavItem = document.getElementById("authNavItem");
223
-
224
- // Desktop links
225
- const homeNavDesktop = document.querySelector('ul.md\\:flex li a[href="index.html"]')?.parentElement;
226
- const profileNavDesktop = document.querySelector('ul.md\\:flex li a[href="profile.html"]')?.parentElement;
227
- const pastNavDesktop = document.querySelector('ul.md\\:flex li a[href="past_data.html"]')?.parentElement;
228
-
229
- // Mobile links
230
- const profileNavMobile = document.querySelector('#mobile-menu a[href="profile.html"]')?.parentElement;
231
- const pastNavMobile = document.querySelector('#mobile-menu a[href="past_data.html"]')?.parentElement;
232
- const homeNavMobile = document.querySelector('#mobile-menu a[href="index.html"]')?.parentElement;
233
- if (authNavItem) {
234
- if (user) {
235
- authNavItem.innerHTML =
236
- '<button onclick="logout()" class="hover:text-[#6B9080] text-red-600">Logout</button>';
237
-
238
- // Hide Home
239
- if (homeNavDesktop) homeNavDesktop.style.display = "none";
240
- if (homeNavMobile) homeNavMobile.style.display = "none";
241
- // Show Profile and Past Reports
242
-
243
- if (profileNavDesktop) profileNavDesktop.style.display = "block";
244
- if (pastNavDesktop) pastNavDesktop.style.display = "block";
245
- if (profileNavMobile) profileNavMobile.style.display = "block";
246
- if (pastNavMobile) pastNavMobile.style.display = "block";
247
- } else {
248
- authNavItem.innerHTML =
249
- '<a href="login.html" class="hover:text-[#6B9080]">Login</a>';
250
-
251
- // Show Home
252
- if (homeNavDesktop) homeNavDesktop.style.display = "block";
253
- if (homeNavMobile) homeNavMobile.style.display = "block";
254
- // Hide Profile and Past Reports
255
- if (profileNavDesktop) profileNavDesktop.style.display = "none";
256
- if (pastNavDesktop) pastNavDesktop.style.display = "none";
257
- if (profileNavMobile) profileNavMobile.style.display = "none";
258
- if (pastNavMobile) pastNavMobile.style.display = "none";
259
- }
260
- }
261
- });
262
 
263
  window.logout = async () => {
264
  try {
@@ -271,6 +240,7 @@ const profileNavDesktop = document.querySelector('ul.md\\:flex li a[href="profil
271
  };
272
  </script>
273
 
 
274
  <script type="module">
275
  import {
276
  pipeline,
@@ -280,39 +250,12 @@ const profileNavDesktop = document.querySelector('ul.md\\:flex li a[href="profil
280
  const loadingEl = document.getElementById("loading");
281
  const textOutput = document.getElementById("text-output");
282
  const recsOutput = document.getElementById("recommendations-output");
283
- const findingsOutput = document.getElementById(
284
- "detected-measurement-results"
285
- );
286
  const authStatus = document.getElementById("auth-status");
287
  let extractedText = "";
288
  let currentUser = null;
289
 
290
- document
291
- .getElementById("pdf-upload")
292
- .addEventListener("change", function () {
293
- loadingEl.textContent = this.files.length
294
- ? `File selected: ${this.files[0].name}`
295
- : "No file uploaded yet.";
296
- });
297
-
298
- const saveAnalysis = async (uid, payload) => {
299
- try {
300
- const docRef = await firebase
301
- .firestore()
302
- .collection("users")
303
- .doc(uid)
304
- .collection("analyses")
305
- .add({
306
- ...payload,
307
- createdAt: serverTimestamp(),
308
- });
309
- return docRef.id;
310
- } catch (e) {
311
- console.error("Failed to save analysis:", e);
312
- }
313
- };
314
-
315
- const renderRecCard = (rec, idx) => {
316
  const sev = (rec.severity || "").toLowerCase();
317
  const sevClass = sev.includes("severe")
318
  ? "badge-high"
@@ -329,21 +272,21 @@ const profileNavDesktop = document.querySelector('ul.md\\:flex li a[href="profil
329
  </div>
330
  <ul class="rec-content space-y-1">
331
  <li><em>Recommendations:</em>
332
- <ul class="list-disc list-inside ml-6">
333
- ${(rec.recommendations || [])
334
- .map((r) => `<li>${r}</li>`)
335
- .join("")}
336
- </ul>
337
  </li>
338
  <li><em>Treatment:</em> ${
339
  rec.treatment_suggestions || "Not available"
340
  }</li>
341
  <li><em>Home Care:</em>
342
- <ul class="list-disc list-inside ml-6">
343
- ${(rec.home_care_guidance || [])
344
- .map((r) => `<li>${r}</li>`)
345
- .join("")}
346
- </ul>
347
  </li>
348
  ${
349
  rec.info_link
@@ -351,20 +294,40 @@ const profileNavDesktop = document.querySelector('ul.md\\:flex li a[href="profil
351
  : ""
352
  }
353
  </ul>
354
- </div>
355
- `;
356
- };
357
 
358
  window.onAuthStateChanged(window.firebaseAuth, (user) => {
359
  currentUser = user;
360
- if (user) {
361
- authStatus.textContent = `Signed in as ${user.email || user.uid}`;
362
- } else {
363
- authStatus.textContent =
364
- "Not signed in. Sign in to save and view past analyses.";
365
- }
366
  });
367
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
368
  document
369
  .getElementById("analyze-btn")
370
  .addEventListener("click", async () => {
@@ -404,112 +367,59 @@ const profileNavDesktop = document.querySelector('ul.md\\:flex li a[href="profil
404
  : data.Detected_Anomolies
405
  ? [data.Detected_Anomolies]
406
  : [];
407
- if (data.Detected_Anomolies) {
408
- recsOutput.innerHTML = recs
409
- .map((rec, i) => renderRecCard(rec, i))
410
- .join("");
411
- } else {
412
- recsOutput.textContent = "No recommendations found.";
413
- }
414
-
415
- const findings = Array.isArray(data.Detected_Measurement_Values)
416
- ? data.Detected_Measurement_Values
417
- : data.Detected_Measurement_Values
418
- ? [data.Detected_Measurement_Values]
419
- : [];
420
- if (data.Detected_Measurement_Values) {
421
- findingsOutput.innerHTML = findings
422
- .map((finding, i) => renderRecCard(finding, i))
423
- .join("");
424
- }
425
 
426
  if (currentUser) {
427
- /*await saveAnalysis(currentUser.uid, {
428
- reportDate: date,
429
- ocr_text: extractedText,
430
- resolutions: recs,
431
- measurements: findings,
432
- });*/
433
  await postReportToBackend({
434
  user_id: currentUser.email,
435
  report_date: new Date(),
436
  ocr_text: extractedText,
437
  anomalies: JSON.stringify(recs),
438
- measurements: JSON.stringify(findings),
439
  });
440
  }
441
-
442
  loadingEl.textContent = "Analysis complete.";
443
  });
444
 
445
- async function postReportToBackend(report) {
446
- try {
447
- const response = await fetch(api('save_report/'), {
448
- method: 'POST',
449
- headers: {
450
- 'Content-Type': 'application/json',
451
- },
452
- body: JSON.stringify(report),
453
- });
454
- if (!response.ok) {
455
- throw new Error(`HTTP error! status: ${response.status}`);
456
- }
457
- const data = await response.json();
458
- console.log('Report successfully sent to backend:', data);
459
- } catch (error) {
460
- console.error('Error sending report to backend:', error);
461
- }
462
  }
463
 
464
- document.getElementById("ask-btn").onclick = async () => {
465
- const q = document.getElementById("user-question").value.trim();
466
- if (!q) return;
467
-
468
- if (!extractedText) {
469
- alert("Please analyze a document first before asking questions.");
470
- return;
471
- }
472
-
473
- const chat = document.getElementById("chat-output");
474
- chat.innerHTML += `<p><strong>You:</strong> ${q}</p>`;
475
- chat.scrollTop = chat.scrollHeight;
476
-
477
- chat.innerHTML += `<p><strong>Chatbot:</strong> <em>Thinking...</em></p>`;
478
- chat.scrollTop = chat.scrollHeight;
479
-
480
- try {
481
- const response = await fetch(api('chat/'), {
482
- method: "POST",
483
- headers: {
484
- "Content-Type": "application/json",
485
- },
486
- body: JSON.stringify({
487
- question: q,
488
- user_id: currentUser ? currentUser.uid : "anonymous"
489
- }),
490
- });
491
-
492
- if (!response.ok) {
493
- throw new Error(`HTTP error! status: ${response.status}`);
494
- }
495
-
496
- const data = await response.json();
497
-
498
- //now addign acctual reposnse
499
- const messages = chat.querySelectorAll('p');
500
- const lastMessage = messages[messages.length - 1];
501
- lastMessage.innerHTML = `<strong>Chatbot:</strong> ${data.answer}`;
502
-
503
- } catch (error) {
504
- console.error("Error:", error);
505
- const messages = chat.querySelectorAll('p');
506
- const lastMessage = messages[messages.length - 1];
507
- lastMessage.innerHTML = `<strong>Chatbot:</strong> Sorry, I encountered an error: ${error.message}`;
508
- }
509
-
510
- document.getElementById("user-question").value = "";
511
- chat.scrollTop = chat.scrollHeight;
512
- };
513
  </script>
514
  </body>
515
- </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">
 
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,
 
179
  } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-auth.js";
180
 
181
  const firebaseConfig = {
182
+ apiKey: "AIzaSyAKWstCc7HqMgV8DmH2Sy6QwUP3JvZxu9g",
183
+ authDomain: "appchallenge-c8fe3.firebaseapp.com",
184
+ projectId: "appchallenge-c8fe3",
185
+ storageBucket: "appchallenge-c8fe3.firebasestorage.app",
186
+ messagingSenderId: "943791692455",
187
+ appId: "1:943791692455:web:ae04d06bf09669b6bdd982",
188
  };
189
 
190
  const app = initializeApp(firebaseConfig);
 
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,
 
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 () => {
 
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>