Ashrafb commited on
Commit
e89342c
·
verified ·
1 Parent(s): 61b6cd2

Update AB/index.html

Browse files
Files changed (1) hide show
  1. AB/index.html +91 -58
AB/index.html CHANGED
@@ -40,7 +40,7 @@ button[type="button"]:hover {
40
 
41
  /* Style for upload buttons */
42
  input[type="file"] {
43
- display: block ; /* Hide the default file input */
44
  }
45
 
46
  .uploadButton {
@@ -219,32 +219,30 @@ h1 {
219
  </style>
220
  </head>
221
  <body>
222
- <h1>Aiconvert.online</h1>
223
- <form id="uploadForm" action="/upload/" method="post" enctype="multipart/form-data">
224
- <label for="sourceFile" class="uploadLabel">Choose image</label>
225
- <input type="file" id="image_file" name="image_file" accept="image/*" required onchange="previewImage(event, 'sourceImage')"><br>
226
- <div id="sourceImageContainer">
227
- <img id="sourceImage">
228
- </div><br>
229
- <label for="top">Top:</label>
230
- <input type="number" id="top" name="top" required><br>
231
-
232
- <label for="bottom">Bottom:</label>
233
- <input type="number" id="bottom" name="bottom" required><br>
234
-
235
- <label for="left">Left:</label>
236
- <input type="number" id="left" name="left" required><br>
237
-
238
- <label for="right">Right:</label>
239
- <input type="number" id="right" name="right" required><br>
240
-
241
- <button type="button" onclick="uploadFile()">Generate</button>
242
  </form>
243
  <div id="resultImage">
244
- <!-- Add the result image container and loading spinner here -->
 
 
 
 
 
 
 
 
 
 
245
  </div>
246
  <script>
247
- function previewImage(event, imageId) {
248
  const fileInput = event.target;
249
  const file = fileInput.files[0];
250
  const reader = new FileReader();
@@ -257,44 +255,79 @@ h1 {
257
  reader.readAsDataURL(file);
258
  }
259
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  async function uploadFile() {
261
- const image_fileInput = document.getElementById('image_file');
262
- const top = document.getElementById('top').value;
263
- const bottom = document.getElementById('bottom').value;
264
- const left = document.getElementById('left').value;
265
- const right = document.getElementById('right').value;
266
- const formData = new FormData();
267
-
268
- // Append the uploaded image and other form data
269
- formData.append('image_file', image_fileInput.files[0]);
270
- formData.append('top', top);
271
- formData.append('bottom', bottom);
272
- formData.append('left', left);
273
- formData.append('right', right);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
 
275
- try {
276
- const response = await fetch('/upload/', {
277
- method: 'POST',
278
- body: formData
279
- });
280
-
281
- if (response.ok) {
282
- // If successful response, display the result image
283
- const resultImageContainer = document.getElementById('resultImage');
284
- const resultData = await response.json();
285
- const resultImage = new Image();
286
- resultImage.src = 'data:image/jpeg;base64,' + resultData.result_image;
287
- resultImageContainer.innerHTML = '';
288
- resultImageContainer.appendChild(resultImage);
289
- } else {
290
- // If server error, display the error message
291
- const errorMessage = await response.text();
292
- console.error('Error:', errorMessage);
293
- }
294
- } catch (error) {
295
- console.error('Error:', error);
296
- }
297
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  </script>
299
  </body>
300
  </html>
 
40
 
41
  /* Style for upload buttons */
42
  input[type="file"] {
43
+ display: none; /* Hide the default file input */
44
  }
45
 
46
  .uploadButton {
 
219
  </style>
220
  </head>
221
  <body>
222
+ <h1>Aiconvert.online </h1>
223
+ <form id="uploadForm" action="/upload/" method="post" enctype="multipart/form-data">
224
+ <label for="sourceFile" class="uploadLabel">Choose image </label>
225
+ <input type="file" id="sourceFile" name="source_file" accept="image/*" required onchange="previewImage(event, 'sourceImage')"><br>
226
+ <div id="sourceImageContainer">
227
+ <img id="sourceImage">
228
+ </div><br>
229
+ <button type="button" onclick="uploadFile()">Generate </button> <!-- Changed to type="button" and added onclick handler -->
 
 
 
 
 
 
 
 
 
 
 
 
230
  </form>
231
  <div id="resultImage">
232
+ <div id="estimatedTime" style="display: none;">Estimated time: 120s</div>
233
+ <div id="loadingSpinner" style="display: none;">
234
+ <!-- Replace this with your loading spinner HTML/CSS -->
235
+ </div>
236
+ <div id="resultContainer">
237
+
238
+
239
+
240
+
241
+ <a id="download-link" href="#" download="colorized_image.jpg" style="display:none;">Download Colorized Image</a>
242
+ </div>
243
  </div>
244
  <script>
245
+ function previewImage(event, imageId) {
246
  const fileInput = event.target;
247
  const file = fileInput.files[0];
248
  const reader = new FileReader();
 
255
  reader.readAsDataURL(file);
256
  }
257
 
258
+
259
+ function displayColorizedImage(blob) {
260
+ const url = URL.createObjectURL(blob);
261
+ const resultContainer = document.getElementById('resultContainer');
262
+ resultContainer.innerHTML = `<img src="${url}" alt="Colorized Image" width="400">`;
263
+ const downloadLink = document.getElementById('download-link');
264
+ downloadLink.href = url;
265
+ downloadLink.style.display = 'block';
266
+ }
267
+
268
+
269
+
270
  async function uploadFile() {
271
+ const sourceFileInput = document.getElementById('sourceFile');
272
+ const resultContainer = document.getElementById('resultContainer');
273
+
274
+
275
+
276
+ // Check if both source and destination file inputs are empty
277
+ if (!sourceFileInput.files[0] ) {
278
+ // Update the result container with the error message
279
+ resultContainer.innerHTML = "<p>Please upload an image.</p>";
280
+ return;
281
+ }
282
+
283
+ // Clear the result container if both images are uploaded
284
+ resultContainer.innerHTML = "";
285
+
286
+ const formData = new FormData();
287
+ const fileInput = document.querySelector('input[type="file"]');
288
+ formData.append('file', fileInput.files[0]);
289
+
290
+ try {
291
+ // Display loading spinner
292
+ const loadingSpinner = document.getElementById('loadingSpinner');
293
+ loadingSpinner.style.display = 'block';
294
+ const estimatedTime = document.getElementById('estimatedTime');
295
+ estimatedTime.style.display = 'block';
296
+
297
+ const response = await fetch('/upload/', {
298
+ method: 'POST',
299
+ body: formData
300
+ });
301
+ if (response.ok) {
302
+ // If successful response, display the result image
303
+ const blob = await response.blob();
304
 
305
+ displayColorizedImage(blob);
306
+
307
+
308
+ } else {
309
+ // If server error, display the error message
310
+ const errorMessage = await response.text();
311
+ resultContainer.innerHTML = `<p>Oops! Something went wrong. Please try again later. </p>`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
312
  }
313
+ // Hide loading spinner after result (or error message) is displayed
314
+ loadingSpinner.style.display = 'none';
315
+ estimatedTime.style.display = 'none';
316
+ } catch (error) {
317
+ console.error('Error swapping faces:', error);
318
+ // Hide loading spinner if there's an error
319
+ const loadingSpinner = document.getElementById('loadingSpinner');
320
+ loadingSpinner.style.display = 'none';
321
+ estimatedTime.style.display = 'none';
322
+ }
323
+ }
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
  </script>
332
  </body>
333
  </html>