-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2.js
More file actions
46 lines (40 loc) · 1.35 KB
/
script2.js
File metadata and controls
46 lines (40 loc) · 1.35 KB
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
document.getElementById("pdfUploadForm").addEventListener("submit", function (event) {
event.preventDefault();
const fileInput = document.getElementById("pdfFile");
const file = fileInput.files[0];
if (file) {
const formData = new FormData();
formData.append("file", file);
fetch("http://localhost:5000/upload", {
method: "POST",
body: formData,
})
.then(response => response.json())
.then(data => {
console.log("Received data:", data);
displayResults(data);
})
.catch(error => {
console.error("Error:", error);
alert("An error occurred while processing the document.");
});
} else {
alert("Please select a file to upload.");
}
});
function displayResults(data) {
const resultDiv = document.getElementById("analysisResult");
resultDiv.classList.remove("d-none");
if (!data.summary || !data.text) {
resultDiv.innerHTML = "<p>Error: Incomplete data received.</p>";
console.error("Incomplete data:", data);
return;
}
const resultHTML = `
<h3>Summary</h3>
<p>${data.summary}</p>
<h3>Extracted Text</h3>
<div class="extracted-text">${data.text}</div>
`;
document.getElementById("resultText").innerHTML = resultHTML;
}