Ashrafb commited on
Commit
4ded6a3
·
verified ·
1 Parent(s): 49b7af6

Create Indexcompress.html

Browse files
Files changed (1) hide show
  1. static/Indexcompress.html +420 -0
static/Indexcompress.html ADDED
@@ -0,0 +1,420 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.11/katex.min.css">
7
+ <link href="https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@100&display=swap" rel="stylesheet">
8
+ <style>
9
+ body {
10
+ background-color: #121212;
11
+ color: #FFFFFF;
12
+ }
13
+
14
+ /* Dark mode for upload buttons */
15
+ .uploadButton {
16
+ background-color: #1E7E34;
17
+ }
18
+
19
+ /* Dark mode for file input labels */
20
+ .uploadLabel {
21
+ background-color: #BF2C25;
22
+ }
23
+
24
+ /* Dark mode for face number inputs */
25
+ input[type="number"] {
26
+ background-color: #333333;
27
+ color: #FFFFFF;
28
+ border: 1px solid #555555;
29
+ }
30
+
31
+ /* Dark mode for swap button */
32
+ button[type="button"] {
33
+ background-color: #1E7E34;
34
+ }
35
+
36
+ /* Dark mode hover effect for swap button */
37
+ button[type="button"]:hover {
38
+ background-color: #2E9E44;
39
+ }
40
+
41
+ /* Style for upload buttons */
42
+ input[type="file"] {
43
+ display: none; /* Hide the default file input */
44
+ }
45
+
46
+ .uploadButton {
47
+ background-color: #4CAF50;
48
+ border: none;
49
+ color: white;
50
+ padding: 10px 20px;
51
+ text-align: center;
52
+ text-decoration: none;
53
+ display: inline-block;
54
+ font-size: 16px;
55
+ margin-top: 10px;
56
+ cursor: pointer;
57
+ border-radius: 5px;
58
+ margin: auto;
59
+ }
60
+
61
+ /* Style for file input labels */
62
+ #predict {
63
+ display: flex;
64
+ flex-direction: column;
65
+ align-items: center;
66
+ }
67
+
68
+ .uploadLabel {
69
+ padding: 10px 20px;
70
+ background-color: #f44336;
71
+ color: white;
72
+ border-radius: 5px;
73
+ cursor: pointer;
74
+ display: inline-block;
75
+ }
76
+
77
+ .uploadLabel input[type="file"] {
78
+ display: none;
79
+ }
80
+
81
+
82
+
83
+ /* Style for labels */
84
+ label {
85
+ font-weight: bold;
86
+ }
87
+
88
+ /* Optional: Increase space between elements */
89
+ form > * {
90
+ margin-bottom: 10px;
91
+ }
92
+ /* Style for the swap button */
93
+ button[type="button"] {
94
+ background-image: linear-gradient(
95
+ 45deg,
96
+ hsl(240deg 75% 29%) 0%,
97
+ hsl(254deg 78% 28%) 6%,
98
+ hsl(264deg 82% 27%) 13%,
99
+ hsl(272deg 87% 26%) 19%,
100
+ hsl(278deg 93% 25%) 25%,
101
+ hsl(284deg 98% 24%) 31%,
102
+ hsl(289deg 100% 23%) 37%,
103
+ hsl(294deg 100% 23%) 44%,
104
+ hsl(299deg 100% 22%) 50%,
105
+ hsl(303deg 100% 23%) 56%,
106
+ hsl(307deg 100% 24%) 63%,
107
+ hsl(311deg 100% 25%) 69%,
108
+ hsl(313deg 100% 26%) 75%,
109
+ hsl(316deg 95% 28%) 81%,
110
+ hsl(320deg 88% 30%) 87%,
111
+ hsl(323deg 81% 32%) 94%,
112
+ hsl(326deg 75% 33%) 100%
113
+ );
114
+ border: none;
115
+ color: white;
116
+ padding: 10px 20px;
117
+ text-align: center;
118
+ text-decoration: none;
119
+ display: inline-block;
120
+ font-size: 16px;
121
+ margin-top: 10px;
122
+ cursor: pointer;
123
+ border-radius: 5px;
124
+ display: block; /* Change display property to block */
125
+ margin: 0 auto;
126
+ Width :200px;
127
+ }
128
+
129
+ /* Hover effect for the swap button */
130
+ button[type="button"]:hover {
131
+ background-color: #45a049;
132
+ }
133
+ h1 {
134
+ text-align: center;
135
+ margin-bottom: 20px;
136
+ font-family: 'Barlow Condensed';
137
+ color: pink;
138
+ font-size: 40px; /* Adjust the font size as needed */
139
+ }
140
+
141
+ h2 {
142
+ font-size: 24px; /* Adjust size as needed */
143
+ font-family: 'Barlow Condensed';
144
+ color: #FFFFFF; /* Text color */
145
+
146
+ margin-top: 20px; /* Top margin */
147
+ margin-bottom: 10px; /* Bottom margin */
148
+ }
149
+
150
+
151
+ #resultImage {
152
+ border: 2px solid blue;
153
+ width: 269px;
154
+ height: 300px;
155
+ display: flex;
156
+ flex-direction: column;
157
+ overflow-y: scroll;
158
+ margin: auto;
159
+ margin-top: 30px;
160
+ padding-bottom: 7px;
161
+ gap: 14px;
162
+ background: linear-gradient(black , black) padding-box,
163
+ linear-gradient(to right, red, blue) border-box;
164
+ border-radius: 20px;
165
+ border: 2.5px solid transparent;
166
+ }
167
+
168
+ #sourceImageContainer, #destinationImageContainer {
169
+ border: 2px solid blue;
170
+ width: 200px;
171
+ height: 200px;
172
+ display: flex;
173
+ flex-direction: column;
174
+ overflow-y: scroll;
175
+ margin: auto;
176
+ margin-top: 30px;
177
+ padding-bottom: 7px;
178
+ gap: 100px;
179
+ background: linear-gradient(black , black) padding-box,
180
+ linear-gradient(to right, red, blue) border-box;
181
+ border-radius: 20px;
182
+ border: 2.5px solid transparent;
183
+ }
184
+
185
+ #sourceImage, #destinationImage {
186
+ max-width: 100%;
187
+ height: auto;
188
+ display: block;
189
+ margin: auto;
190
+ }
191
+
192
+ #loadingSpinner {
193
+ border: 3px solid rgba(255, 255, 255, 0.3);
194
+ border-radius: 50%;
195
+ border-top: 3px solid #ffffff;
196
+ width: 20px;
197
+ height: 20px;
198
+ animation: spin 2s linear infinite;
199
+ position: relative;
200
+ top: 50%;
201
+ left: 50%;
202
+ transform: translate(-50%, -50%);
203
+ display: none; /* Initially hide the loading spinner */
204
+ }
205
+
206
+ @keyframes spin {
207
+ 0% { transform: rotate(0deg); }
208
+ 100% { transform: rotate(360deg); }
209
+ }
210
+
211
+ /* Style for version selection */
212
+ #version {
213
+ font-size: 18px; /* Adjust size as needed */
214
+ font-family: 'Barlow Condensed', sans-serif; /* Use the specified font */
215
+ color: #FFFFFF; /* Text color */
216
+ margin-bottom: 5px; /* Bottom margin */
217
+ padding: 8px;
218
+ border: 1px solid #ccc;
219
+ border-radius: 4px;
220
+ box-sizing: border-box;
221
+ margin-top: 5px;
222
+ font-size: 28px;
223
+ Width :200px;
224
+ text-align: center;
225
+ }
226
+
227
+ /* Style for the radio buttons */
228
+ input[type="radio"] {
229
+ margin-right: 30px; /* Add some space between radio button and label */
230
+ }
231
+
232
+ /* Style for the labels of radio buttons */
233
+ label[for="simple"], label[for="complex"] {
234
+ font-family: 'Barlow Condensed', sans-serif; /* Use the specified font */
235
+ color: #FFFFFF; /* Text color */
236
+ margin-right: 10px; /* Add some space between label and next element */
237
+ font-size: 20px;
238
+ }
239
+ #downloadButton{
240
+
241
+ background-image: linear-gradient(
242
+ 45deg,
243
+ hsl(240deg 75% 29%) 0%,
244
+ hsl(254deg 78% 28%) 6%,
245
+ hsl(264deg 82% 27%) 13%,
246
+ hsl(272deg 87% 26%) 19%,
247
+ hsl(278deg 93% 25%) 25%,
248
+ hsl(284deg 98% 24%) 31%,
249
+ hsl(289deg 100% 23%) 37%,
250
+ hsl(294deg 100% 23%) 44%,
251
+ hsl(299deg 100% 22%) 50%,
252
+ hsl(303deg 100% 23%) 56%,
253
+ hsl(307deg 100% 24%) 63%,
254
+ hsl(311deg 100% 25%) 69%,
255
+ hsl(313deg 100% 26%) 75%,
256
+ hsl(316deg 95% 28%) 81%,
257
+ hsl(320deg 88% 30%) 87%,
258
+ hsl(323deg 81% 32%) 94%,
259
+ hsl(326deg 75% 33%) 100%
260
+ );
261
+ border: none;
262
+ color: white;
263
+ padding: 10px 20px;
264
+ text-align: center;
265
+ text-decoration: none;
266
+ display: inline-block;
267
+ font-size: 16px;
268
+ margin-top: 10px;
269
+ cursor: pointer;
270
+ border-radius: 5px;
271
+ display: block; /* Change display property to block */
272
+ margin: 0 auto;
273
+ Width :200px;
274
+ }
275
+
276
+ </style>
277
+ </head>
278
+ <body>
279
+ <h1>Aiconvert.online </h1>
280
+ <form id="predict" action="/predict/" method="post" enctype="multipart/form-data">
281
+ <label for="sourceFile" class="uploadLabel">Choose image </label>
282
+ <input type="file" id="sourceFile" name="source_file" accept="image/*" required onchange="previewImage(event, 'sourceImage')">
283
+ <div id="sourceImageContainer">
284
+ <img id="sourceImage">
285
+ </div><br>
286
+ <label for="version" id="version" > Version:</label><br>
287
+ <input type="radio" id="simple" name="version" value="Simple Lines" >
288
+ <label for="simple">Simple Lines</label><br>
289
+ <input type="radio" id="complex" name="version" value="Complex Lines"checked >
290
+ <label for="complex">Complex Lines</label><br><br>
291
+
292
+ <button type="button">Generate </button>
293
+ </form>
294
+ <div id="resultImage">
295
+ <div id="loadingSpinner" style="display: none;">
296
+ <!-- Replace this with your loading spinner HTML/CSS -->
297
+ </div>
298
+ <div id="resultContainer"></div>
299
+ </div>
300
+ <button id="downloadButton" style="display: block ;" onclick="downloadResultImage()">Download </button>
301
+
302
+ <script>
303
+ function previewImage(event) {
304
+ const file = event.target.files[0];
305
+ const imagePreview = document.getElementById('sourceImageContainer');
306
+ imagePreview.innerHTML = `<img src="${URL.createObjectURL(file)}" alt="Uploaded Image" style="max-width: 300px; max-height: 300px;">`;
307
+ }
308
+
309
+ async function uploadFile() {
310
+ const sourceFileInput = document.getElementById('sourceFile');
311
+ const resultContainer = document.getElementById('resultContainer');
312
+ // Check if source file input is empty
313
+ if (!sourceFileInput.files[0]) {
314
+ // Update the result container with the error message
315
+ resultContainer.innerHTML = "<p>Please upload an image.</p>";
316
+ return;
317
+ }
318
+
319
+ // Clear the result container
320
+ resultContainer.innerHTML = "";
321
+ // Compress the image to 500 KB before sending
322
+ const compressedFile = await compressImage(sourceFile.files[0]);
323
+
324
+ const formData = new FormData();
325
+ formData.append('file', compressedFile);
326
+ formData.append('version', document.querySelector('input[name="version"]:checked').value);
327
+
328
+ try {
329
+ // Display loading spinner
330
+ const loadingSpinner = document.getElementById('loadingSpinner');
331
+ loadingSpinner.style.display = 'block';
332
+
333
+ const response = await fetch('https://ashrafb-imlidrdokefast.hf.space/predict', {
334
+ method: 'POST',
335
+ body: formData
336
+ });
337
+
338
+ if (response.ok) {
339
+ const blob = await response.blob();
340
+ const imageUrl = URL.createObjectURL(blob);
341
+ resultContainer.innerHTML = `<img src="${imageUrl}" alt="Result Image" style="max-width: 100%;">`;
342
+ } else {
343
+ // If server error, display the error message
344
+ const errorMessage = await response.text();
345
+ resultContainer.innerHTML = `<p>Oops! Something went wrong. Please try again later. </p>`;
346
+ }
347
+ } catch (error) {
348
+ console.error('Error converting image to line drawing:', error);
349
+ // Display error message
350
+ resultContainer.innerHTML = `<p>Oops! Something went wrong. Please try again later</p>`;
351
+ }
352
+
353
+
354
+ // Hide loading spinner if there's an error
355
+ const loadingSpinner = document.getElementById('loadingSpinner');
356
+ loadingSpinner.style.display = 'none';
357
+ }
358
+
359
+ const generateButton = document.querySelector('button');
360
+ generateButton.addEventListener('click', uploadFile);
361
+
362
+ async function compressImage(file) {
363
+ return new Promise((resolve, reject) => {
364
+ const reader = new FileReader();
365
+ reader.onload = function(event) {
366
+ const img = new Image();
367
+ img.src = event.target.result;
368
+
369
+ img.onload = function() {
370
+ const canvas = document.createElement('canvas');
371
+ const ctx = canvas.getContext('2d');
372
+
373
+ // Calculate the new dimensions to resize the image while maintaining aspect ratio
374
+ const maxWidth = 1000;
375
+ const maxHeight = 1000;
376
+ let width = img.width;
377
+ let height = img.height;
378
+
379
+ if (width > height) {
380
+ if (width > maxWidth) {
381
+ height *= maxWidth / width;
382
+ width = maxWidth;
383
+ }
384
+ } else {
385
+ if (height > maxHeight) {
386
+ width *= maxHeight / height;
387
+ height = maxHeight;
388
+ }
389
+ }
390
+
391
+ // Set the canvas dimensions
392
+ canvas.width = width;
393
+ canvas.height = height;
394
+
395
+ // Draw the image on the canvas with the new dimensions
396
+ ctx.drawImage(img, 0, 0, width, height);
397
+
398
+ // Convert canvas content to a blob
399
+ canvas.toBlob((blob) => {
400
+ resolve(blob);
401
+ }, 'image/jpeg', 1); // Adjust quality as needed (0.7 is 70% quality)
402
+ }
403
+ }
404
+
405
+ // Read the file as data URL
406
+ reader.readAsDataURL(file);
407
+ });
408
+ }
409
+ function downloadResultImage() {
410
+ const resultImage = document.getElementById('resultContainer').querySelector('img');
411
+ const link = document.createElement('a');
412
+ link.href = resultImage.src;
413
+ link.download = 'result_image.png';
414
+ document.body.appendChild(link);
415
+ link.click();
416
+ document.body.removeChild(link);
417
+ }
418
+ </script>
419
+ </body>
420
+ </html>