mydemo1 / templates /index3.html
CloudAnts's picture
my
245266f
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Invoice Extraction</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Poppins', sans-serif; background: linear-gradient(to right, #6a11cb, #2575fc); color: #333; display: flex; justify-content: center; align-items: center; min-height: 100vh; }
.container {
width: 90%;
max-width: 800px;
background: #ffffff;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
border-radius: 12px;
padding: 30px;
display: flex;
flex-direction: column;
justify-content: flex-start;
height: 100%;
}
.header {
text-align: center;
margin-bottom: 20px;
}
.header h1 {
font-size: 28px;
font-weight: 700;
color: #333;
}
.header p {
font-size: 14px;
color: #777;
}
.upload-section {
margin-bottom: 20px;
}
.upload-section label {
display: block;
font-size: 16px;
font-weight: 500;
margin-bottom: 10px;
color: #555;
}
.upload-section input[type="file"] {
display: block;
padding: 12px;
font-size: 14px;
border: 1px solid #ddd;
border-radius: 8px;
width: 100%;
transition: all 0.3s ease;
}
.upload-section input[type="file"]:focus {
border-color: #2575fc;
outline: none;
}
.actions {
text-align: center;
margin-top: 10px;
}
.actions button {
background-color: #2575fc;
color: white;
padding: 12px 25px;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 500;
cursor: pointer;
transition: background-color 0.3s ease;
margin: 10px 5px;
}
.actions button:hover {
background-color: #1a5bb8;
}
.output-section {
margin-top: 20px;
text-align: center;
display: none;
padding-top: 20px;
}
.please-wait {
font-size: 18px;
font-weight: 600;
color: #ffcc00;
display: none;
text-align: center;
}
.output-images {
display: flex;
justify-content: center;
gap: 20px;
flex-wrap: wrap;
}
.output-images img {
max-width: 100%;
width: 300px;
border: 2px solid #ddd;
border-radius: 8px;
object-fit: contain;
margin-bottom: 20px;
}
.spinner {
border: 4px solid #f3f3f3; /* Light background */
border-top: 4px solid #2575fc; /* Blue color for the spinning part */
border-radius: 50%;
width: 50px;
height: 50px;
animation: spin 2s linear infinite;
margin: 10px auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.output-section button {
background-color: #34c759;
color: white;
padding: 10px 20px;
border: none;
border-radius: 8px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: background-color 0.3s ease;
margin: 10px 5px;
}
.output-section button:hover {
background-color: #28a745;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Invoice Processing</h1>
<p>Upload your invoice and extract data with ease</p>
</div>
<div class="upload-section">
<label for="invoice-upload">Upload Invoice Image:</label>
<input type="file" id="invoice-upload" accept="image/*">
</div>
<div class="actions">
<button id="upload-btn">Upload & Process</button>
</div>
<!-- Please Wait Section with Spinner -->
<div class="please-wait" id="please-wait">
<div class="spinner"></div>
Please wait, processing the file...
</div>
<!-- Output Section -->
<div class="output-section" id="output-section">
<!-- Display Images -->
<div class="output-images">
<div>
<h3>Original Image</h3>
<img id="original-image" src="" alt="Original" />
</div>
<div>
<h3>Annotated Image</h3>
<img id="annotated-image" src="" alt="Annotated" />
</div>
</div>
<!-- Download Buttons -->
<a id="download-csv" href="" download><button>Download CSV</button></a>
<a id="download-image" href="" download><button>Download Annotated Image</button></a>
</div>
</div>
<script>
const uploadBtn = document.getElementById('upload-btn');
const invoiceInput = document.getElementById('invoice-upload');
const outputSection = document.getElementById('output-section');
const pleaseWaitSection = document.getElementById('please-wait');
const downloadCsvButton = document.getElementById('download-csv');
const downloadImageButton = document.getElementById('download-image');
const originalImage = document.getElementById('original-image');
const annotatedImage = document.getElementById('annotated-image');
uploadBtn.addEventListener('click', () => {
const file = invoiceInput.files[0];
if (!file) return alert('Please select a file.');
const formData = new FormData();
formData.append('invoice-upload', file);
// Show the "Please Wait" message and spinner
pleaseWaitSection.style.display = 'block';
outputSection.style.display = 'none';
// Send the file to the server for processing
fetch('/upload', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
pleaseWaitSection.style.display = 'none'; // Hide "Please Wait"
outputSection.style.display = 'block'; // Show the output section
// Populate download links
downloadCsvButton.href = `/download_csv/${data.csv_path.split('/').pop()}`;
downloadImageButton.href = `/download_image/${data.image_path.split('/').pop()}`;
// Display images
originalImage.src = `/uploads/${data.original_image.split('/').pop()}`;
annotatedImage.src = `/download_image/${data.image_path.split('/').pop()}`;
})
.catch(error => {
pleaseWaitSection.style.display = 'none'; // Hide "Please Wait"
alert('Error processing the image: ' + error);
});
});
</script>
</body>
</html>