Ashrafb commited on
Commit
131431b
·
verified ·
1 Parent(s): 6d3904b

Update static/index1.html

Browse files
Files changed (1) hide show
  1. static/index1.html +195 -126
static/index1.html CHANGED
@@ -1,19 +1,18 @@
1
- <!-- index.html -->
2
-
3
  <!DOCTYPE html>
4
  <html lang="en">
5
  <head>
6
  <meta charset="UTF-8">
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
- <title>Image Enhancement</title>
 
9
  <style>
10
- body {
11
  background-color: #121212;
12
  color: #FFFFFF;
13
  }
14
 
15
  /* Dark mode for upload buttons */
16
- .uploadButton {
17
  background-color: #1E7E34;
18
  }
19
 
@@ -23,7 +22,7 @@
23
  }
24
 
25
  /* Dark mode for face number inputs */
26
- input[type="number"] {
27
  background-color: #333333;
28
  color: #FFFFFF;
29
  border: 1px solid #555555;
@@ -39,10 +38,19 @@ button[type="button"]:hover {
39
  background-color: #2E9E44;
40
  }
41
 
42
- /* Style for upload buttons */
43
  input[type="file"] {
44
  display: none; /* Hide the default file input */
45
  }
 
 
 
 
 
 
 
 
 
46
 
47
  .uploadButton {
48
  background-color: #4CAF50;
@@ -61,7 +69,7 @@ input[type="file"] {
61
  }
62
 
63
  /* Style for file input labels */
64
- #uploadForm {
65
  display: flex;
66
  flex-direction: column;
67
  align-items: center;
@@ -75,7 +83,6 @@ input[type="file"] {
75
  cursor: pointer;
76
  display: block;
77
  margin: 0 auto;
78
-
79
  }
80
 
81
  .uploadLabel input[type="file"] {
@@ -83,7 +90,7 @@ input[type="file"] {
83
  }
84
 
85
  /* Style for face number inputs */
86
- #version #scale {
87
  padding: 8px;
88
  Width :50px;
89
  border: 1px solid #ccc;
@@ -102,6 +109,7 @@ label {
102
  form > * {
103
  margin-bottom: 10px;
104
  }
 
105
  /* Style for the swap button */
106
  button {
107
  background-image: linear-gradient(
@@ -143,6 +151,24 @@ button {
143
  button:hover {
144
  background-color: #45a049;
145
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
  h1 {
148
  text-align: center;
@@ -152,14 +178,14 @@ h1 {
152
  font-size: 40px; /* Adjust the font size as needed */
153
  }
154
 
155
- h2 {
156
  font-size: 24px; /* Adjust size as needed */
157
  font-family: 'Barlow Condensed';
158
  color: #FFFFFF; /* Text color */
159
-
160
  margin-top: 20px; /* Top margin */
161
  margin-bottom: 10px; /* Bottom margin */
162
  }
 
163
  select {
164
  width: 150px; /* Adjust width as needed */
165
  padding: 8px;
@@ -169,6 +195,9 @@ select {
169
  color: white; /* Text color */
170
  font-size: 16px;
171
  }
 
 
 
172
  /* Style for the scale number input */
173
  input[type="number"]#scale {
174
  padding: 8px;
@@ -195,24 +224,32 @@ input[type="number"]#scale:focus {
195
  color: white; /* Set text color */
196
  }
197
 
198
- #resultImage {
199
- border: 2px solid blue;
200
- width: 265px;
201
- height: 300px;
202
- display: flex;
203
- flex-direction: column;
204
- overflow-y: scroll;
205
- margin: auto;
206
- margin-top: 30px;
207
- padding-bottom: 7px;
208
- gap: 14px;
209
- background: linear-gradient(black , black) padding-box,
210
- linear-gradient(to right, red, blue) border-box;
211
- border-radius: 20px;
212
- border: 2.5px solid transparent;
213
- }
 
214
 
215
- #sourceImageContainer, #destinationImageContainer {
 
 
 
 
 
 
 
216
  border: 2px solid blue;
217
  width: 200px;
218
  height: 200px;
@@ -229,142 +266,174 @@ input[type="number"]#scale:focus {
229
  border: 2.5px solid transparent;
230
  }
231
 
232
- #sourceImage, #destinationImage {
233
  max-width: 100%;
234
  height: auto;
235
  display: block;
236
  margin: auto;
237
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
238
 
239
- #loadingSpinner {
240
- border: 3px solid rgba(255, 255, 255, 0.3);
241
- border-radius: 50%;
242
- border-top: 5px solid #ffffff;
243
- width: 20px;
244
- height: 20px;
245
- animation: spin 2s linear infinite;
246
- position: relative;
247
- top: 50%;
248
- left: 50%;
249
- transform: translate(-50%, -50%);
250
- display: none; /* Initially hide the loading spinner */
251
- }
252
-
253
- @keyframes spin {
254
- 0% { transform: rotate(0deg); }
255
- 100% { transform: rotate(360deg); }
256
- }
257
-
258
- </style>
259
  </head>
260
  <body>
261
  <h1>Aiconvert.online</h1>
262
- <form id="uploadForm" enctype="multipart/form-data">
263
- <!-- Label for the file input -->
264
- <label for="image" class="uploadLabel">Choose image</label>
265
- <!-- Hidden file input -->
266
- <input type="file" id="image" name="file" accept="image/*" required onchange="previewImage(event, 'sourceImage')" style="display: none;">
267
-
268
-
269
- <div id="sourceImageContainer">
270
- <img id="sourceImage">
271
- </div>
272
- <br>
273
-
274
- <label for="version">Select Version:</label>
275
- <select id="version" name="version">
276
- <option value="v1.2">M1</option>
277
- <option value="v1.3">M2</option>
278
- <option value="v1.4">M3</option>
279
- <!-- Add more options as needed -->
280
- </select>
281
 
282
- <label for="scale">Scale:</label>
283
- <input type="number" id="scale" name="scale" min="1" value="2"><br>
284
-
285
-
 
 
 
286
 
287
- <button type="submit">Enhance Image</button>
288
  </form>
289
-
290
- <div id="resultImage">
291
- <div id="loadingSpinner">
292
- <div id="spinner"></div>
293
- </div>
294
- <div id="estimatedTime" style="display: none;">Estimated time: 90s</div>
295
- </div>
296
 
 
 
 
297
  <div id="resultContainer"></div>
 
298
  </div>
 
299
 
300
- <!-- Placeholder for the result image -->
301
- <script>
302
-
 
 
 
303
 
304
- function previewImage(event, imageId) {
305
- const fileInput = event.target;
306
- const file = fileInput.files[0];
307
- const reader = new FileReader();
308
 
309
- reader.onload = function(e) {
310
- const image = document.getElementById(imageId);
311
- image.src = e.target.result;
 
 
 
 
 
 
312
  }
313
 
314
- reader.readAsDataURL(file);
315
- }
316
 
317
- // Function to handle form submission
318
- async function handleSubmit(event) {
319
- event.preventDefault();
320
- const formData = new FormData(this);
321
 
322
- // Show the loading spinner
323
- const loadingSpinner = document.getElementById('loadingSpinner');
324
- const spinner = document.getElementById('spinner');
325
- const estimatedTime = document.getElementById('estimatedTime');
326
 
 
 
327
  loadingSpinner.style.display = 'block';
328
- spinner.style.display = 'block';
329
  estimatedTime.style.display = 'block';
330
-
331
  try {
332
- const response = await fetch('/upload/', {
333
  method: 'POST',
334
  body: formData
335
  });
336
 
 
 
 
337
  if (response.ok) {
338
- // If successful response, display the result image
339
- const blob = await response.blob();
340
- const imageUrl = URL.createObjectURL(blob);
341
- resultImage.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
- resultImage.innerHTML = `<p style="color: white;">Oops! Something went wrong. Please try again later.</p>`;
346
  }
347
-
348
- // Hide the loading spinner
349
- loadingSpinner.style.display = 'none';
350
  } catch (error) {
351
  console.error('Error:', error);
 
352
  }
353
-
354
- // Remove the existing event listener
355
- this.removeEventListener('submit', handleSubmit);
356
- // Reattach the event listener
357
- this.addEventListener('submit', handleSubmit);
358
  }
359
 
360
- // Add event listener to the form
361
- document.getElementById('uploadForm').addEventListener('submit', handleSubmit);
362
-
363
-
364
-
365
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
 
367
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
368
 
 
369
  </body>
370
  </html>
 
 
 
 
 
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
+ #upload-form button[type="button"] {
16
  background-color: #1E7E34;
17
  }
18
 
 
22
  }
23
 
24
  /* Dark mode for face number inputs */
25
+ #scale {
26
  background-color: #333333;
27
  color: #FFFFFF;
28
  border: 1px solid #555555;
 
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
+ #upload-form label[for="image"] {
46
+ padding: 10px 20px;
47
+ background-color: #f44336;
48
+ color: white;
49
+ border-radius: 5px;
50
+ cursor: pointer;
51
+ display: inline-block;
52
+ margin: 0 auto;
53
+ }
54
 
55
  .uploadButton {
56
  background-color: #4CAF50;
 
69
  }
70
 
71
  /* Style for file input labels */
72
+ #upload-form {
73
  display: flex;
74
  flex-direction: column;
75
  align-items: center;
 
83
  cursor: pointer;
84
  display: block;
85
  margin: 0 auto;
 
86
  }
87
 
88
  .uploadLabel input[type="file"] {
 
90
  }
91
 
92
  /* Style for face number inputs */
93
+ #version, #scale {
94
  padding: 8px;
95
  Width :50px;
96
  border: 1px solid #ccc;
 
109
  form > * {
110
  margin-bottom: 10px;
111
  }
112
+
113
  /* Style for the swap button */
114
  button {
115
  background-image: linear-gradient(
 
151
  button:hover {
152
  background-color: #45a049;
153
  }
154
+ /* Style for file input */
155
+ #image {
156
+ display: none; /* Hide the default file input */
157
+ }
158
+
159
+ .uploadLabel {
160
+ padding: 10px 20px;
161
+ background-color: #f44336;
162
+ color: white;
163
+ border-radius: 5px;
164
+ cursor: pointer;
165
+ display: inline-block;
166
+ margin: 0 auto;
167
+ }
168
+
169
+ .uploadLabel input[type="file"] {
170
+ display: none;
171
+ }
172
 
173
  h1 {
174
  text-align: center;
 
178
  font-size: 40px; /* Adjust the font size as needed */
179
  }
180
 
181
+ h2 {
182
  font-size: 24px; /* Adjust size as needed */
183
  font-family: 'Barlow Condensed';
184
  color: #FFFFFF; /* Text color */
 
185
  margin-top: 20px; /* Top margin */
186
  margin-bottom: 10px; /* Bottom margin */
187
  }
188
+
189
  select {
190
  width: 150px; /* Adjust width as needed */
191
  padding: 8px;
 
195
  color: white; /* Text color */
196
  font-size: 16px;
197
  }
198
+ #version{
199
+ width :60px;
200
+ }
201
  /* Style for the scale number input */
202
  input[type="number"]#scale {
203
  padding: 8px;
 
224
  color: white; /* Set text color */
225
  }
226
 
227
+ #resultImage {
228
+ border: 2px solid blue;
229
+ width: 265px;
230
+ height: 300px;
231
+ display: flex;
232
+ flex-direction: column;
233
+ overflow-y: scroll;
234
+ margin: auto;
235
+ margin-top: 30px;
236
+ padding-bottom: 7px;
237
+ gap: 14px;
238
+ background: linear-gradient(black , black) padding-box,
239
+ linear-gradient(to right, red, blue) border-box;
240
+ border-radius: 20px;
241
+ border: 2.5px solid transparent;
242
+ }
243
+
244
 
245
+
246
+ #resultContainer img {
247
+ max-width: 100%;
248
+ height: auto;
249
+ display: block;
250
+ margin: auto;
251
+ }
252
+ #image-preview {
253
  border: 2px solid blue;
254
  width: 200px;
255
  height: 200px;
 
266
  border: 2.5px solid transparent;
267
  }
268
 
269
+ #sourceImage {
270
  max-width: 100%;
271
  height: auto;
272
  display: block;
273
  margin: auto;
274
  }
275
+ #loadingSpinner {
276
+ border: 3px solid rgba(255, 255, 255, 0.3);
277
+ border-radius: 50%;
278
+ border-top: 3px solid #ffffff;
279
+ width: 20px;
280
+ height: 20px;
281
+ animation: spin 2s linear infinite;
282
+ position: relative;
283
+ top: 50%;
284
+ left: 50%;
285
+ transform: translate(-50%, -50%);
286
+ display: none; /* Initially hide the loading spinner */
287
+ }
288
 
289
+ @keyframes spin {
290
+ 0% { transform: rotate(0deg); }
291
+ 100% { transform: rotate(360deg); }
292
+ }
293
+ </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  </head>
295
  <body>
296
  <h1>Aiconvert.online</h1>
297
+ <form id="upload-form" enctype="multipart/form-data">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
 
299
+ <label for="image">Select image:</label>
300
+ <input type="file" id="image" accept="image/*" required onchange="previewImage(event)">
301
+ <div id="image-preview">
302
+
303
+ <img id="sourceImage">
304
+ </div><br>
305
+
306
 
307
+ <button type="button" onclick="uploadImage()">Restore Image</button>
308
  </form>
 
 
 
 
 
 
 
309
 
310
+ <div id="resultImage">
311
+ <div id="estimatedTime" style="display: none;">Average estimated time: 240s</div>
312
+ <div id="loadingSpinner" style="display: none;"></div>
313
  <div id="resultContainer"></div>
314
+
315
  </div>
316
+ <button id="downloadButton" style="display: block ;" onclick="downloadResultImage()">Download </button>
317
 
318
+ <script>
319
+ function previewImage(event) {
320
+ const file = event.target.files[0];
321
+ const imagePreview = document.getElementById('image-preview');
322
+ imagePreview.innerHTML = `<img src="${URL.createObjectURL(file)}" alt="Uploaded Image" style="max-width: 300px; max-height: 300px;">`;
323
+ }
324
 
 
 
 
 
325
 
326
+
327
+ async function uploadImage() {
328
+ const fileInput = document.getElementById('image');
329
+
330
+
331
+ // Check if the file input is empty
332
+ if (!fileInput.files[0]) {
333
+ document.getElementById('resultContainer').innerHTML = `<p style="color: white;">Please upload an image.</p>`;
334
+ return;
335
  }
336
 
337
+ // Clear the result container
338
+ document.getElementById('resultContainer').innerHTML = "";
339
 
340
+ // Compress the image to 500 KB before sending
341
+ const compressedFile = await compressImage(fileInput.files[0]);
 
 
342
 
343
+ const formData = new FormData();
344
+ formData.append('file', compressedFile);
345
+
 
346
 
347
+ // Display loading spinner
348
+ const loadingSpinner = document.getElementById('loadingSpinner');
349
  loadingSpinner.style.display = 'block';
350
+ const estimatedTime = document.getElementById('estimatedTime');
351
  estimatedTime.style.display = 'block';
 
352
  try {
353
+ const response = await fetch('https://ashrafb-bopbdocke.hf.space/upload/', {
354
  method: 'POST',
355
  body: formData
356
  });
357
 
358
+ // Hide loading spinner
359
+ loadingSpinner.style.display = 'none';
360
+ estimatedTime.style.display = 'none';
361
  if (response.ok) {
362
+ const resultContainer = document.getElementById('resultContainer');
363
+ const data = await response.json();
364
+ const sketchImage = document.createElement('img');
365
+ sketchImage.style.maxWidth = '100%'; // Adjust this value as needed
366
+ sketchImage.style.maxHeight = '100%'; // Adjust this value as needed
367
+ sketchImage.src = data.sketch_image_base64;
368
+ resultContainer.appendChild(sketchImage);
369
  } else {
370
+ document.getElementById('resultContainer').innerHTML = `<p style="color: white;">Oops! Something went wrong. Please try again later.</p>`;
 
 
371
  }
 
 
 
372
  } catch (error) {
373
  console.error('Error:', error);
374
+ document.getElementById('resultContainer').innerHTML = `<p style="color: white;">Oops! Something went wrong. Please try again later.</p>`;
375
  }
 
 
 
 
 
376
  }
377
 
378
+ async function compressImage(file) {
379
+ return new Promise((resolve, reject) => {
380
+ const reader = new FileReader();
381
+ reader.onload = function(event) {
382
+ const img = new Image();
383
+ img.src = event.target.result;
384
+
385
+ img.onload = function() {
386
+ const canvas = document.createElement('canvas');
387
+ const ctx = canvas.getContext('2d');
388
+
389
+ // Calculate the new dimensions to resize the image while maintaining aspect ratio
390
+ const maxWidth = 1000;
391
+ const maxHeight = 1000;
392
+ let width = img.width;
393
+ let height = img.height;
394
+
395
+ if (width > height) {
396
+ if (width > maxWidth) {
397
+ height *= maxWidth / width;
398
+ width = maxWidth;
399
+ }
400
+ } else {
401
+ if (height > maxHeight) {
402
+ width *= maxHeight / height;
403
+ height = maxHeight;
404
+ }
405
+ }
406
+
407
+ // Set the canvas dimensions
408
+ canvas.width = width;
409
+ canvas.height = height;
410
+
411
+ // Draw the image on the canvas with the new dimensions
412
+ ctx.drawImage(img, 0, 0, width, height);
413
+
414
+ // Convert canvas content to a blob
415
+ canvas.toBlob((blob) => {
416
+ resolve(blob);
417
+ }, 'image/jpeg', 1); // Adjust quality as needed (0.7 is 70% quality)
418
+ }
419
+ }
420
 
421
+ // Read the file as data URL
422
+ reader.readAsDataURL(file);
423
+ });
424
+ }
425
+ function downloadResultImage() {
426
+ const resultImage = document.getElementById('resultContainer').querySelector('img');
427
+ const link = document.createElement('a');
428
+ link.href = resultImage.src;
429
+ link.download = 'result_image.png';
430
+ document.body.appendChild(link);
431
+ link.click();
432
+ document.body.removeChild(link);
433
+ }
434
 
435
+ </script>
436
  </body>
437
  </html>
438
+
439
+