Ashrafb commited on
Commit
d44a341
·
verified ·
1 Parent(s): 76f0c7c

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +45 -34
static/index.html CHANGED
@@ -268,43 +268,54 @@ h1 {
268
 
269
 
270
  async function swapFaces() {
271
- const form = document.getElementById('swapForm');
272
- const formData = new FormData(form);
273
-
274
- try {
275
- // Display loading spinner
276
- const loadingSpinner = document.getElementById('loadingSpinner');
277
- loadingSpinner.style.display = 'block';
278
-
279
- // Remove previous result image and message
280
- const resultContainer = document.getElementById('resultContainer');
281
- resultContainer.innerHTML = '';
282
-
283
- const response = await fetch('/swap_faces/', {
284
- method: 'POST',
285
- body: formData
286
- });
287
-
288
- if (response.ok) {
289
- // If successful response, display the result image
290
- const blob = await response.blob();
291
- const imageUrl = URL.createObjectURL(blob);
292
- resultContainer.innerHTML = `<img src="${imageUrl}" alt="Result Image" style="max-width: 100%;">`;
293
- } else {
294
- // If server error, display the error message
295
- const errorMessage = await response.text();
296
- resultContainer.innerHTML = `<p>Error: ${errorMessage}</p>`;
297
- }
298
 
299
- // Hide loading spinner after result (or error message) is displayed
300
- loadingSpinner.style.display = 'none';
301
- } catch (error) {
302
- console.error('Error swapping faces:', error);
303
- // Hide loading spinner if there's an error
304
- const loadingSpinner = document.getElementById('loadingSpinner');
305
- loadingSpinner.style.display = 'none';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306
  }
 
 
 
 
 
 
 
 
307
  }
 
 
308
 
309
 
310
 
 
268
 
269
 
270
  async function swapFaces() {
271
+ const sourceFileInput = document.getElementById('sourceFile');
272
+ const destinationFileInput = document.getElementById('destinationFile');
273
+ const resultContainer = document.getElementById('resultContainer');
274
+
275
+ // Check if both source and destination file inputs are empty
276
+ if (!sourceFileInput.files[0] || !destinationFileInput.files[0]) {
277
+ // Update the result container with the error message
278
+ resultContainer.innerHTML = "<p>Please upload both source and destination images.</p>";
279
+ return;
280
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
 
282
+ // Clear the result container if both images are uploaded
283
+ resultContainer.innerHTML = "";
284
+
285
+ const form = document.getElementById('swapForm');
286
+ const formData = new FormData(form);
287
+
288
+ try {
289
+ // Display loading spinner
290
+ const loadingSpinner = document.getElementById('loadingSpinner');
291
+ loadingSpinner.style.display = 'block';
292
+
293
+ const response = await fetch('/swap_faces/', {
294
+ method: 'POST',
295
+ body: formData
296
+ });
297
+
298
+ if (response.ok) {
299
+ // If successful response, display the result image
300
+ const blob = await response.blob();
301
+ const imageUrl = URL.createObjectURL(blob);
302
+ resultContainer.innerHTML = `<img src="${imageUrl}" alt="Result Image" style="max-width: 100%;">`;
303
+ } else {
304
+ // If server error, display the error message
305
+ const errorMessage = await response.text();
306
+ resultContainer.innerHTML = `<p>Error: ${errorMessage}</p>`;
307
  }
308
+
309
+ // Hide loading spinner after result (or error message) is displayed
310
+ loadingSpinner.style.display = 'none';
311
+ } catch (error) {
312
+ console.error('Error swapping faces:', error);
313
+ // Hide loading spinner if there's an error
314
+ const loadingSpinner = document.getElementById('loadingSpinner');
315
+ loadingSpinner.style.display = 'none';
316
  }
317
+ }
318
+
319
 
320
 
321