Spaces:
Sleeping
Sleeping
update analyzer.html with working code
Browse files- web/analyzer.html +14 -20
web/analyzer.html
CHANGED
|
@@ -189,8 +189,7 @@
|
|
| 189 |
</li>
|
| 190 |
</ul>
|
| 191 |
</nav>
|
| 192 |
-
|
| 193 |
-
<script src="script.js"></script>
|
| 194 |
<script>
|
| 195 |
const hamburger = document.getElementById("hamburger");
|
| 196 |
const mobileMenu = document.getElementById("mobile-menu");
|
|
@@ -231,11 +230,11 @@
|
|
| 231 |
accept=".pdf, image/*"
|
| 232 |
class="w-full mb-4 rounded px-3 py-2"
|
| 233 |
/>
|
| 234 |
-
|
| 235 |
type="date"
|
| 236 |
id="report-date"
|
| 237 |
class="w-full mb-4 rounded px-3 py-2"
|
| 238 |
-
/>
|
| 239 |
<button id="analyze-btn" class="btn-primary px-4 py-2 rounded">
|
| 240 |
Analyze with AI
|
| 241 |
</button>
|
|
@@ -451,15 +450,15 @@
|
|
| 451 |
.getElementById("analyze-btn")
|
| 452 |
.addEventListener("click", async () => {
|
| 453 |
const file = document.getElementById("pdf-upload").files[0];
|
| 454 |
-
|
| 455 |
if (!file) {
|
| 456 |
loadingEl.textContent = "Please upload a file first.";
|
| 457 |
return;
|
| 458 |
}
|
| 459 |
-
|
| 460 |
loadingEl.textContent = "Please select the report date.";
|
| 461 |
return;
|
| 462 |
-
}
|
| 463 |
|
| 464 |
loadingEl.textContent = "Processing with AI...";
|
| 465 |
textOutput.textContent = "";
|
|
@@ -471,7 +470,7 @@
|
|
| 471 |
|
| 472 |
let data;
|
| 473 |
try {
|
| 474 |
-
const res = await fetch(
|
| 475 |
method: "POST",
|
| 476 |
body: formData,
|
| 477 |
});
|
|
@@ -508,21 +507,16 @@
|
|
| 508 |
findingsOutput.innerHTML = findings
|
| 509 |
.map((finding, i) => renderRecCard(finding, i))
|
| 510 |
.join("");
|
| 511 |
-
}
|
|
|
|
|
|
|
|
|
|
| 512 |
if (currentUser) {
|
| 513 |
-
|
| 514 |
reportDate: date,
|
| 515 |
ocr_text: extractedText,
|
| 516 |
-
|
| 517 |
measurements: findings,
|
| 518 |
-
});*/
|
| 519 |
-
|
| 520 |
-
await postReportToBackend({
|
| 521 |
-
user_id: currentUser.email,
|
| 522 |
-
report_date: new Date(),
|
| 523 |
-
ocr_text: extractedText,
|
| 524 |
-
anomalies: JSON.stringify(recs),
|
| 525 |
-
measurements: JSON.stringify(findings),
|
| 526 |
});
|
| 527 |
}
|
| 528 |
|
|
@@ -531,7 +525,7 @@
|
|
| 531 |
|
| 532 |
async function postReportToBackend(report) {
|
| 533 |
try {
|
| 534 |
-
const response = await fetch(
|
| 535 |
method: 'POST',
|
| 536 |
headers: {
|
| 537 |
'Content-Type': 'application/json',
|
|
|
|
| 189 |
</li>
|
| 190 |
</ul>
|
| 191 |
</nav>
|
| 192 |
+
|
|
|
|
| 193 |
<script>
|
| 194 |
const hamburger = document.getElementById("hamburger");
|
| 195 |
const mobileMenu = document.getElementById("mobile-menu");
|
|
|
|
| 230 |
accept=".pdf, image/*"
|
| 231 |
class="w-full mb-4 rounded px-3 py-2"
|
| 232 |
/>
|
| 233 |
+
<input
|
| 234 |
type="date"
|
| 235 |
id="report-date"
|
| 236 |
class="w-full mb-4 rounded px-3 py-2"
|
| 237 |
+
/>
|
| 238 |
<button id="analyze-btn" class="btn-primary px-4 py-2 rounded">
|
| 239 |
Analyze with AI
|
| 240 |
</button>
|
|
|
|
| 450 |
.getElementById("analyze-btn")
|
| 451 |
.addEventListener("click", async () => {
|
| 452 |
const file = document.getElementById("pdf-upload").files[0];
|
| 453 |
+
const date = document.getElementById("report-date").value;
|
| 454 |
if (!file) {
|
| 455 |
loadingEl.textContent = "Please upload a file first.";
|
| 456 |
return;
|
| 457 |
}
|
| 458 |
+
if (!date) {
|
| 459 |
loadingEl.textContent = "Please select the report date.";
|
| 460 |
return;
|
| 461 |
+
}
|
| 462 |
|
| 463 |
loadingEl.textContent = "Processing with AI...";
|
| 464 |
textOutput.textContent = "";
|
|
|
|
| 470 |
|
| 471 |
let data;
|
| 472 |
try {
|
| 473 |
+
const res = await fetch("http://localhost:9000/analyze/", {
|
| 474 |
method: "POST",
|
| 475 |
body: formData,
|
| 476 |
});
|
|
|
|
| 507 |
findingsOutput.innerHTML = findings
|
| 508 |
.map((finding, i) => renderRecCard(finding, i))
|
| 509 |
.join("");
|
| 510 |
+
} else {
|
| 511 |
+
findingsOutput.textContent = "No measurements found.";
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
if (currentUser) {
|
| 515 |
+
await saveAnalysis(currentUser.uid, {
|
| 516 |
reportDate: date,
|
| 517 |
ocr_text: extractedText,
|
| 518 |
+
resolutions: recs,
|
| 519 |
measurements: findings,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 520 |
});
|
| 521 |
}
|
| 522 |
|
|
|
|
| 525 |
|
| 526 |
async function postReportToBackend(report) {
|
| 527 |
try {
|
| 528 |
+
const response = await fetch('http://localhost:9000/save_report/', {
|
| 529 |
method: 'POST',
|
| 530 |
headers: {
|
| 531 |
'Content-Type': 'application/json',
|