Spaces:
Sleeping
Sleeping
Update templates/gui.html
Browse files- templates/gui.html +19 -24
templates/gui.html
CHANGED
|
@@ -14,32 +14,31 @@
|
|
| 14 |
///////////////////////////////////////////////BEGIN JS CODE//////////////////////////////////////////////////
|
| 15 |
// Function to send the Dropbox link and keyword to the server
|
| 16 |
function getURLParams() {
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
function processPdf() {
|
| 26 |
-
// const pdfLink = 'https://www.dropbox.com/scl/fi/hnp4mqigb51a5kp89kgfa/00801-ARC-20-ZZ-S-A-0002.pdf?rlkey=45abeoebzqw4qwnslnei6dkd6&st=m4yrcjm2&dl=1'; // Dropbox link
|
| 27 |
-
// const keyword = ['115 INTEGRATED MRI ROOM LININGS','710 TRANSPORTATION'] ; // Example keyword
|
| 28 |
|
|
|
|
| 29 |
const { pdfLink, keyword, pageNumber, zoomRect } = getURLParams();
|
| 30 |
-
if (pdfLink){
|
| 31 |
-
console.log('p')
|
| 32 |
-
}
|
| 33 |
-
else{
|
| 34 |
-
const pdfLink = 'https://www.dropbox.com/scl/fi/hnp4mqigb51a5kp89kgfa/00801-ARC-20-ZZ-S-A-0002.pdf?rlkey=45abeoebzqw4qwnslnei6dkd6&st=m4yrcjm2&dl=1'; // Dropbox link
|
| 35 |
-
const keyword = ['115 INTEGRATED MRI ROOM LININGS','710 TRANSPORTATION'] ; // Example keyword
|
| 36 |
|
|
|
|
|
|
|
|
|
|
| 37 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
// Create a new FormData object to send the data as form data
|
| 39 |
const formData = new FormData();
|
| 40 |
formData.append('pdf_link', pdfLink);
|
| 41 |
-
formData.append('keyword',
|
| 42 |
-
|
| 43 |
// Send the data to the Flask server
|
| 44 |
fetch('/api/process-data', {
|
| 45 |
method: 'POST',
|
|
@@ -47,11 +46,8 @@ function processPdf() {
|
|
| 47 |
})
|
| 48 |
.then(response => response.json())
|
| 49 |
.then(data => {
|
| 50 |
-
// Handle the server's response
|
| 51 |
if (data.download_link) {
|
| 52 |
-
// Redirect
|
| 53 |
-
// The download_link includes both the page number and the rect (coordinates)
|
| 54 |
-
window.location.href = data.download_link; // This will use the rect info from Flask
|
| 55 |
} else {
|
| 56 |
alert('Error: ' + data.error);
|
| 57 |
}
|
|
@@ -63,5 +59,4 @@ function processPdf() {
|
|
| 63 |
|
| 64 |
// Call the function to process the PDF
|
| 65 |
processPdf();
|
| 66 |
-
|
| 67 |
</script>
|
|
|
|
| 14 |
///////////////////////////////////////////////BEGIN JS CODE//////////////////////////////////////////////////
|
| 15 |
// Function to send the Dropbox link and keyword to the server
|
| 16 |
function getURLParams() {
|
| 17 |
+
const urlParams = new URLSearchParams(window.location.search);
|
| 18 |
+
return {
|
| 19 |
+
pdfLink: decodeURIComponent(urlParams.get('pdf_link') || ''), // Decode special characters
|
| 20 |
+
keyword: decodeURIComponent(urlParams.get('keyword') || ''), // Handle spaces properly
|
| 21 |
+
pageNumber: parseInt(urlParams.get('page')) || 1,
|
| 22 |
+
zoomRect: urlParams.get('zoom') || '' // Expecting format: "x,y,width,height"
|
| 23 |
+
};
|
| 24 |
+
}
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
function processPdf() {
|
| 27 |
const { pdfLink, keyword, pageNumber, zoomRect } = getURLParams();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
if (!pdfLink || !keyword) {
|
| 30 |
+
console.error("Missing PDF link or keyword.");
|
| 31 |
+
return;
|
| 32 |
}
|
| 33 |
+
|
| 34 |
+
console.log("Extracted PDF Link:", pdfLink);
|
| 35 |
+
console.log("Extracted Keyword:", keyword);
|
| 36 |
+
|
| 37 |
// Create a new FormData object to send the data as form data
|
| 38 |
const formData = new FormData();
|
| 39 |
formData.append('pdf_link', pdfLink);
|
| 40 |
+
formData.append('keyword', keyword); // Single keyword from URL
|
| 41 |
+
|
| 42 |
// Send the data to the Flask server
|
| 43 |
fetch('/api/process-data', {
|
| 44 |
method: 'POST',
|
|
|
|
| 46 |
})
|
| 47 |
.then(response => response.json())
|
| 48 |
.then(data => {
|
|
|
|
| 49 |
if (data.download_link) {
|
| 50 |
+
window.location.href = data.download_link; // Redirect to annotated PDF
|
|
|
|
|
|
|
| 51 |
} else {
|
| 52 |
alert('Error: ' + data.error);
|
| 53 |
}
|
|
|
|
| 59 |
|
| 60 |
// Call the function to process the PDF
|
| 61 |
processPdf();
|
|
|
|
| 62 |
</script>
|