File size: 7,654 Bytes
32652fd
 
 
 
 
 
 
 
 
245266f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d602994
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245266f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32652fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d602994
 
 
 
 
 
245266f
d602994
245266f
 
 
 
 
 
 
 
 
 
 
 
32652fd
 
 
 
 
 
 
 
 
d602994
32652fd
 
245266f
 
32652fd
 
 
 
 
 
 
 
d602994
 
 
 
 
32652fd
 
 
 
 
 
d602994
245266f
 
 
32652fd
 
245266f
 
 
 
32652fd
d602994
 
 
 
32652fd
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<!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>