my
Browse files- app.py +10 -5
- templates/index3.html +149 -22
app.py
CHANGED
|
@@ -89,13 +89,13 @@ def upload_file():
|
|
| 89 |
if file:
|
| 90 |
file_path = os.path.join('./app/data1', file.filename)
|
| 91 |
file.save(file_path)
|
| 92 |
-
output_image, output_csv = process_image()
|
| 93 |
|
| 94 |
return jsonify({
|
| 95 |
'image_path': output_image,
|
| 96 |
-
'csv_path': output_csv
|
|
|
|
| 97 |
})
|
| 98 |
-
|
| 99 |
def process_image():
|
| 100 |
print("Current working directory:", os.getcwd())
|
| 101 |
|
|
@@ -164,7 +164,7 @@ def process_image():
|
|
| 164 |
else:
|
| 165 |
print("No bounding box found in the info.")
|
| 166 |
cropped_image = cv2.imread(cropped_image_path, cv2.IMREAD_GRAYSCALE)
|
| 167 |
-
recognized_text = pytesseract.image_to_string(cropped_image)
|
| 168 |
print(f"Recognized Text: {recognized_text}")
|
| 169 |
|
| 170 |
csv_writer.writerow([object_id, bounding_box_info, cropped_image_name, recognized_text])
|
|
@@ -226,7 +226,7 @@ def process_image():
|
|
| 226 |
cv2.imwrite(output_image_path, image)
|
| 227 |
print(f"Annotated image saved at {output_image_path}")
|
| 228 |
counter += 1
|
| 229 |
-
return output_image_path, output_csv_path
|
| 230 |
|
| 231 |
@app.route('/download_csv/<filename>')
|
| 232 |
def download_csv(filename):
|
|
@@ -236,5 +236,10 @@ def download_csv(filename):
|
|
| 236 |
def download_image(filename):
|
| 237 |
return send_from_directory('./app/Folder3', filename, as_attachment=True)
|
| 238 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
|
| 240 |
|
|
|
|
| 89 |
if file:
|
| 90 |
file_path = os.path.join('./app/data1', file.filename)
|
| 91 |
file.save(file_path)
|
| 92 |
+
output_image, output_csv,image_path = process_image()
|
| 93 |
|
| 94 |
return jsonify({
|
| 95 |
'image_path': output_image,
|
| 96 |
+
'csv_path': output_csv,
|
| 97 |
+
'original_image': image_path
|
| 98 |
})
|
|
|
|
| 99 |
def process_image():
|
| 100 |
print("Current working directory:", os.getcwd())
|
| 101 |
|
|
|
|
| 164 |
else:
|
| 165 |
print("No bounding box found in the info.")
|
| 166 |
cropped_image = cv2.imread(cropped_image_path, cv2.IMREAD_GRAYSCALE)
|
| 167 |
+
recognized_text = pytesseract.image_to_string(cropped_image,config="--psm 6 -c tessedit_char_whitelist=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-")
|
| 168 |
print(f"Recognized Text: {recognized_text}")
|
| 169 |
|
| 170 |
csv_writer.writerow([object_id, bounding_box_info, cropped_image_name, recognized_text])
|
|
|
|
| 226 |
cv2.imwrite(output_image_path, image)
|
| 227 |
print(f"Annotated image saved at {output_image_path}")
|
| 228 |
counter += 1
|
| 229 |
+
return output_image_path, output_csv_path,image_path
|
| 230 |
|
| 231 |
@app.route('/download_csv/<filename>')
|
| 232 |
def download_csv(filename):
|
|
|
|
| 236 |
def download_image(filename):
|
| 237 |
return send_from_directory('./app/Folder3', filename, as_attachment=True)
|
| 238 |
|
| 239 |
+
@app.route('/uploads/<filename>')
|
| 240 |
+
def serve_uploaded_file(filename):
|
| 241 |
+
return send_from_directory('./app/data1', filename)
|
| 242 |
+
|
| 243 |
+
|
| 244 |
|
| 245 |
|
templates/index3.html
CHANGED
|
@@ -6,24 +6,118 @@
|
|
| 6 |
<title>Invoice Extraction</title>
|
| 7 |
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 8 |
<style>
|
| 9 |
-
/* Your existing styles */
|
| 10 |
* { margin: 0; padding: 0; box-sizing: border-box; }
|
| 11 |
-
body { font-family: 'Poppins', sans-serif; background: linear-gradient(to right, #6a11cb, #2575fc); color: #333; display: flex; justify-content: center; align-items: center; height: 100vh; }
|
| 12 |
-
|
| 13 |
-
.
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
.spinner {
|
| 28 |
border: 4px solid #f3f3f3; /* Light background */
|
| 29 |
border-top: 4px solid #2575fc; /* Blue color for the spinning part */
|
|
@@ -34,14 +128,27 @@
|
|
| 34 |
margin: 10px auto;
|
| 35 |
}
|
| 36 |
|
| 37 |
-
/* Spinner animation */
|
| 38 |
@keyframes spin {
|
| 39 |
0% { transform: rotate(0deg); }
|
| 40 |
100% { transform: rotate(360deg); }
|
| 41 |
}
|
| 42 |
|
| 43 |
-
.output-section button {
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
</style>
|
| 46 |
</head>
|
| 47 |
<body>
|
|
@@ -66,8 +173,20 @@
|
|
| 66 |
Please wait, processing the file...
|
| 67 |
</div>
|
| 68 |
|
| 69 |
-
<!-- Output Section
|
| 70 |
<div class="output-section" id="output-section">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
<a id="download-csv" href="" download><button>Download CSV</button></a>
|
| 72 |
<a id="download-image" href="" download><button>Download Annotated Image</button></a>
|
| 73 |
</div>
|
|
@@ -80,6 +199,8 @@
|
|
| 80 |
const pleaseWaitSection = document.getElementById('please-wait');
|
| 81 |
const downloadCsvButton = document.getElementById('download-csv');
|
| 82 |
const downloadImageButton = document.getElementById('download-image');
|
|
|
|
|
|
|
| 83 |
|
| 84 |
uploadBtn.addEventListener('click', () => {
|
| 85 |
const file = invoiceInput.files[0];
|
|
@@ -100,9 +221,15 @@
|
|
| 100 |
.then(response => response.json())
|
| 101 |
.then(data => {
|
| 102 |
pleaseWaitSection.style.display = 'none'; // Hide "Please Wait"
|
| 103 |
-
outputSection.style.display = 'block'; // Show
|
|
|
|
|
|
|
| 104 |
downloadCsvButton.href = `/download_csv/${data.csv_path.split('/').pop()}`;
|
| 105 |
downloadImageButton.href = `/download_image/${data.image_path.split('/').pop()}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
})
|
| 107 |
.catch(error => {
|
| 108 |
pleaseWaitSection.style.display = 'none'; // Hide "Please Wait"
|
|
|
|
| 6 |
<title>Invoice Extraction</title>
|
| 7 |
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 8 |
<style>
|
|
|
|
| 9 |
* { margin: 0; padding: 0; box-sizing: border-box; }
|
| 10 |
+
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; }
|
| 11 |
+
|
| 12 |
+
.container {
|
| 13 |
+
width: 90%;
|
| 14 |
+
max-width: 800px;
|
| 15 |
+
background: #ffffff;
|
| 16 |
+
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
|
| 17 |
+
border-radius: 12px;
|
| 18 |
+
padding: 30px;
|
| 19 |
+
display: flex;
|
| 20 |
+
flex-direction: column;
|
| 21 |
+
justify-content: flex-start;
|
| 22 |
+
height: 100%;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.header {
|
| 26 |
+
text-align: center;
|
| 27 |
+
margin-bottom: 20px;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.header h1 {
|
| 31 |
+
font-size: 28px;
|
| 32 |
+
font-weight: 700;
|
| 33 |
+
color: #333;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
.header p {
|
| 37 |
+
font-size: 14px;
|
| 38 |
+
color: #777;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.upload-section {
|
| 42 |
+
margin-bottom: 20px;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.upload-section label {
|
| 46 |
+
display: block;
|
| 47 |
+
font-size: 16px;
|
| 48 |
+
font-weight: 500;
|
| 49 |
+
margin-bottom: 10px;
|
| 50 |
+
color: #555;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.upload-section input[type="file"] {
|
| 54 |
+
display: block;
|
| 55 |
+
padding: 12px;
|
| 56 |
+
font-size: 14px;
|
| 57 |
+
border: 1px solid #ddd;
|
| 58 |
+
border-radius: 8px;
|
| 59 |
+
width: 100%;
|
| 60 |
+
transition: all 0.3s ease;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.upload-section input[type="file"]:focus {
|
| 64 |
+
border-color: #2575fc;
|
| 65 |
+
outline: none;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
.actions {
|
| 69 |
+
text-align: center;
|
| 70 |
+
margin-top: 10px;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
.actions button {
|
| 74 |
+
background-color: #2575fc;
|
| 75 |
+
color: white;
|
| 76 |
+
padding: 12px 25px;
|
| 77 |
+
border: none;
|
| 78 |
+
border-radius: 8px;
|
| 79 |
+
font-size: 16px;
|
| 80 |
+
font-weight: 500;
|
| 81 |
+
cursor: pointer;
|
| 82 |
+
transition: background-color 0.3s ease;
|
| 83 |
+
margin: 10px 5px;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.actions button:hover {
|
| 87 |
+
background-color: #1a5bb8;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
.output-section {
|
| 91 |
+
margin-top: 20px;
|
| 92 |
+
text-align: center;
|
| 93 |
+
display: none;
|
| 94 |
+
padding-top: 20px;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
.please-wait {
|
| 98 |
+
font-size: 18px;
|
| 99 |
+
font-weight: 600;
|
| 100 |
+
color: #ffcc00;
|
| 101 |
+
display: none;
|
| 102 |
+
text-align: center;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
.output-images {
|
| 106 |
+
display: flex;
|
| 107 |
+
justify-content: center;
|
| 108 |
+
gap: 20px;
|
| 109 |
+
flex-wrap: wrap;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
.output-images img {
|
| 113 |
+
max-width: 100%;
|
| 114 |
+
width: 300px;
|
| 115 |
+
border: 2px solid #ddd;
|
| 116 |
+
border-radius: 8px;
|
| 117 |
+
object-fit: contain;
|
| 118 |
+
margin-bottom: 20px;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
.spinner {
|
| 122 |
border: 4px solid #f3f3f3; /* Light background */
|
| 123 |
border-top: 4px solid #2575fc; /* Blue color for the spinning part */
|
|
|
|
| 128 |
margin: 10px auto;
|
| 129 |
}
|
| 130 |
|
|
|
|
| 131 |
@keyframes spin {
|
| 132 |
0% { transform: rotate(0deg); }
|
| 133 |
100% { transform: rotate(360deg); }
|
| 134 |
}
|
| 135 |
|
| 136 |
+
.output-section button {
|
| 137 |
+
background-color: #34c759;
|
| 138 |
+
color: white;
|
| 139 |
+
padding: 10px 20px;
|
| 140 |
+
border: none;
|
| 141 |
+
border-radius: 8px;
|
| 142 |
+
font-size: 14px;
|
| 143 |
+
font-weight: 500;
|
| 144 |
+
cursor: pointer;
|
| 145 |
+
transition: background-color 0.3s ease;
|
| 146 |
+
margin: 10px 5px;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
.output-section button:hover {
|
| 150 |
+
background-color: #28a745;
|
| 151 |
+
}
|
| 152 |
</style>
|
| 153 |
</head>
|
| 154 |
<body>
|
|
|
|
| 173 |
Please wait, processing the file...
|
| 174 |
</div>
|
| 175 |
|
| 176 |
+
<!-- Output Section -->
|
| 177 |
<div class="output-section" id="output-section">
|
| 178 |
+
<!-- Display Images -->
|
| 179 |
+
<div class="output-images">
|
| 180 |
+
<div>
|
| 181 |
+
<h3>Original Image</h3>
|
| 182 |
+
<img id="original-image" src="" alt="Original" />
|
| 183 |
+
</div>
|
| 184 |
+
<div>
|
| 185 |
+
<h3>Annotated Image</h3>
|
| 186 |
+
<img id="annotated-image" src="" alt="Annotated" />
|
| 187 |
+
</div>
|
| 188 |
+
</div>
|
| 189 |
+
<!-- Download Buttons -->
|
| 190 |
<a id="download-csv" href="" download><button>Download CSV</button></a>
|
| 191 |
<a id="download-image" href="" download><button>Download Annotated Image</button></a>
|
| 192 |
</div>
|
|
|
|
| 199 |
const pleaseWaitSection = document.getElementById('please-wait');
|
| 200 |
const downloadCsvButton = document.getElementById('download-csv');
|
| 201 |
const downloadImageButton = document.getElementById('download-image');
|
| 202 |
+
const originalImage = document.getElementById('original-image');
|
| 203 |
+
const annotatedImage = document.getElementById('annotated-image');
|
| 204 |
|
| 205 |
uploadBtn.addEventListener('click', () => {
|
| 206 |
const file = invoiceInput.files[0];
|
|
|
|
| 221 |
.then(response => response.json())
|
| 222 |
.then(data => {
|
| 223 |
pleaseWaitSection.style.display = 'none'; // Hide "Please Wait"
|
| 224 |
+
outputSection.style.display = 'block'; // Show the output section
|
| 225 |
+
|
| 226 |
+
// Populate download links
|
| 227 |
downloadCsvButton.href = `/download_csv/${data.csv_path.split('/').pop()}`;
|
| 228 |
downloadImageButton.href = `/download_image/${data.image_path.split('/').pop()}`;
|
| 229 |
+
|
| 230 |
+
// Display images
|
| 231 |
+
originalImage.src = `/uploads/${data.original_image.split('/').pop()}`;
|
| 232 |
+
annotatedImage.src = `/download_image/${data.image_path.split('/').pop()}`;
|
| 233 |
})
|
| 234 |
.catch(error => {
|
| 235 |
pleaseWaitSection.style.display = 'none'; // Hide "Please Wait"
|