File size: 7,269 Bytes
8df2f3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Card cropping</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
            margin: 0;
            padding: 0;
            position: relative;
            background-image: url('static/depositphotos_489854724-stock-illustration-light-multicolor-rainbow-vector-abstract.jpg');
            background-size: 2300px;
            background-repeat: no-repeat;
            background-position: center;
            background-color: rgba(255, 255, 255, 0.2);
            backdrop-filter: blur(7px);
            min-height: 100vh; /* Ensure page takes at least viewport height */
        }

        form {
            margin-bottom: 20px;
        }

        /* File uploader and predict button styles */
        .file-upload-label {
            padding: 10px;
        }

        #predictBtn {
            padding: 10px 20px;
            margin-top: 10px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }

        #predictBtn:hover {
            background-color: #0056b3;
        }

        #predictBtn:active {
            background-color: #004f9f;
        }

        #predictBtn:focus {
            outline: none;
        }

        .file-upload-input {
            display: none;
        }

        .file-upload-icon {
            font-size: 30px;
            margin-right: 1px;
        }

        .image-container {
            display: flex;
            justify-content: center;
            align-items: center;
            margin-bottom: 20px;
            position: relative;
        }

        .image-wrapper {
            position: relative;
            margin: 0 50px; /* Increased space between the images */
        }

        .image-label {
            text-align: center;
            background-color: #ffffff;
            padding: 5px 10px;
            border-radius: 5px;
            font-weight: bold;
            margin-top: 10px;
            display: none; /* Initially hide labels */
        }

        .image-container img {
            height: auto;
            display: none; /* Initially hide images */
        }

        #uploadedImage {
            max-width: 200px; /* Smaller size for uploaded image */
        }

        #croppedImage {
            max-width: 250px; 
        }

        #result {
            margin-top: 20px;
            position: relative;
        }

        #loading {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            display: none;
        }

        #logo {
            position: absolute;
            bottom: 5px;
            right: 5px;
            max-width: 100px; /* Increase logo size */
            height: auto;
        }

        .footprint {
            position: fixed;
            bottom: 0;
            left: 0;
            width: 100%;
            text-align: center;
            background-color: rgba(255, 255, 255, 0.2);
            padding: 10px 0;
            z-index: 1;
        }

        .footprint img {
            max-width: 100px;
            height: auto;
            margin-left: auto; /* Push the logo to the right */
            display: inline-block;
            vertical-align: middle; /* Align the logo vertically with the text */
        }
    </style>
</head>
<body>
    <br>
    <br>
    <h1>Visiting Card/Id Card Cropping System</h1>
    <form id="uploadForm" enctype="multipart/form-data">
        <label for="file-upload" class="file-upload-label">
            <input type="file" name="image" id="file-upload" class="file-upload-input" accept="image/*" required>
            <span class="file-upload-icon">📤</span> Choose an image
        </label>
        <button id="predictBtn" type="submit">Predict</button>
    </form>
    <div id="result">
        <div id="loading">
            <img src="path_to_loader_icon.gif" alt="Loader">
        </div>
        <p id="message"></p>
        <div class="image-container">
            <div class="image-wrapper">
                <img id="uploadedImage" src="" alt="Uploaded Image">
                <div class="image-label" id="uploadedLabel">Uploaded Image</div>
            </div>
            <div class="image-wrapper">
                <img id="croppedImage" src="" alt="Cropped Image">
                <div class="image-label" id="croppedLabel">Output</div>
            </div>
        </div>
    </div>

    <!-- Footprint -->
    <div class="footprint">
        <p>Copyright © XYZ It Ltd. 2024</p>
        <img src="static/360_F_517815080_tD3cmJRmhhztVmeHrnJd3DA4HT1Zkks7 (1).jpg" alt="Company Logo">
    </div>
    <script>
        document.getElementById('uploadForm').addEventListener('submit', async function(event) {
            event.preventDefault();
            const formData = new FormData(this);

            // Show loading icon when form is submitted
            document.getElementById('loading').style.display = 'block';

            const fileInput = document.getElementById('file-upload');
            const file = fileInput.files[0];
            let uploadedImageSrc = '';
            if (file) {
                const reader = new FileReader();
                reader.onload = function(e) {
                    uploadedImageSrc = e.target.result;
                }
                reader.readAsDataURL(file);
            }

            const response = await fetch('/detect-and-crop', {
                method: 'POST',
                body: formData
            });

            const result = await response.json();
            document.getElementById('message').textContent = result.message;

            if (uploadedImageSrc) {
                const uploadedImage = document.getElementById('uploadedImage');
                const uploadedLabel = document.getElementById('uploadedLabel');
                uploadedImage.src = uploadedImageSrc;
                uploadedImage.style.display = 'block';
                uploadedLabel.style.display = 'block';
            }

            if (result.output_filename) {
                const imageUrl = `/output/${result.output_filename}?${Date.now()}`;
                const croppedImage = document.getElementById('croppedImage');
                const croppedLabel = document.getElementById('croppedLabel');
                croppedImage.src = imageUrl;
                croppedImage.style.display = 'block';
                croppedLabel.style.display = 'block';
            } else {
                // Clear the src attribute when no output image available
                const croppedImage = document.getElementById('croppedImage');
                const croppedLabel = document.getElementById('croppedLabel');
                croppedImage.src = '';
                croppedImage.style.display = 'none';
                croppedLabel.style.display = 'none';
            }

            document.getElementById('loading').style.display = 'none';
        });
    </script>
</body>
</html>