Ashrafb commited on
Commit
5e1f803
·
verified ·
1 Parent(s): 0148de7

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +85 -79
static/index.html CHANGED
@@ -2,108 +2,114 @@
2
  <html>
3
  <head>
4
  <title>Face Swapper App</title>
5
- <style >
6
- #resultImage {
7
- border: 2px solid blue;
8
- width: 330px;
9
- height: 330px;
10
- display: flex;
11
- flex-direction: column;
12
- overflow-y: scroll;
13
- margin: auto;
14
- margin-top: 30px;
15
- padding-bottom: 7px;
16
- gap: 14px;
17
- background: linear-gradient(white , white) padding-box,
18
- linear-gradient(to right, red, blue) border-box;
19
- border-radius: 20px;
20
- border: 2.5px solid transparent;
21
- }
22
- #resultContainer img {
23
- max-width: 100%;
24
-
25
- height: auto;
26
- display: block;
27
- margin: auto;
28
- }
29
 
30
-
31
- #loadingSpinner {
32
- border: 3px solid rgba(255, 255, 255, 0.3);
33
- border-radius: 50%;
34
- border-top: 8px solid pink;
35
- width: 40px;
36
- height: 40px;
37
- animation: spin 2s linear infinite;
38
- position: relative;
39
- top: 50%;
40
- left: 50%;
41
- transform: translate(-50%, -50%);
42
- }
43
 
44
- @keyframes spin {
45
- 0% { transform: rotate(0deg); }
46
- 100% { transform: rotate(360deg); }
47
- }
48
- </style>
49
  </head>
50
  <body>
51
  <h1>Face Swapper App</h1>
52
  <form id="swapForm" action="/swap_faces/" method="post" enctype="multipart/form-data">
53
  <h2>Upload Source Image</h2>
54
- <input type="file" name="source_file" accept="image/*" required><br>
55
  <label>Source Face Position:</label>
56
  <input type="number" name="source_face_index" min="1" required><br>
57
  <h2>Upload Destination Image</h2>
58
- <input type="file" name="destination_file" accept="image/*" required><br>
59
  <label>Destination Face Position:</label>
60
  <input type="number" name="destination_face_index" min="1" required><br>
61
- <button type="button" onclick="swapFaces()">Swap Faces</button> <!-- Changed to type="button" and added onclick handler -->
62
  </form>
63
  <div id="resultImage">
64
- <div id="loadingSpinner" style="display: none;">
65
- <!-- Replace this with your loading spinner HTML/CSS -->
66
- </div>
67
- <div id="resultContainer">
68
-
69
- </div>
70
  </div>
71
- <!-- Placeholder for the result image -->
72
 
73
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  async function swapFaces() {
75
- const form = document.getElementById('swapForm');
76
- const formData = new FormData(form);
77
 
78
- try {
79
- // Display loading spinner
80
- const loadingSpinner = document.getElementById('loadingSpinner');
81
- loadingSpinner.style.display = 'block';
82
 
83
- // Remove previous result image
84
- const resultContainer = document.getElementById('resultContainer');
85
- resultContainer.innerHTML = '';
86
 
87
- const response = await fetch('/swap_faces/', {
88
- method: 'POST',
89
- body: formData
90
- });
91
- const blob = await response.blob();
92
- const imageUrl = URL.createObjectURL(blob);
93
-
94
- // Display the result image
95
- resultContainer.innerHTML = `<img src="${imageUrl}" alt="Result Image" style="max-width: 100%;">`;
96
 
97
- // Hide loading spinner after result image is displayed
98
- loadingSpinner.style.display = 'none';
99
- } catch (error) {
100
- console.error('Error swapping faces:', error);
101
- // Hide loading spinner if there's an error
102
- const loadingSpinner = document.getElementById('loadingSpinner');
103
- loadingSpinner.style.display = 'none';
104
- }
105
- }
106
 
 
 
 
 
 
 
 
 
 
107
  </script>
108
  </body>
109
  </html>
 
2
  <html>
3
  <head>
4
  <title>Face Swapper App</title>
5
+ <style>
6
+ #resultImage {
7
+ border: 2px solid blue;
8
+ width: 330px;
9
+ height: 330px;
10
+ display: flex;
11
+ flex-direction: column;
12
+ overflow-y: scroll;
13
+ margin: auto;
14
+ margin-top: 30px;
15
+ padding-bottom: 7px;
16
+ gap: 14px;
17
+ background: linear-gradient(white , white) padding-box,
18
+ linear-gradient(to right, red, blue) border-box;
19
+ border-radius: 20px;
20
+ border: 2.5px solid transparent;
21
+ }
 
 
 
 
 
 
 
22
 
23
+ #loadingSpinner {
24
+ border: 3px solid rgba(255, 255, 255, 0.3);
25
+ border-radius: 50%;
26
+ border-top: 8px solid pink;
27
+ width: 40px;
28
+ height: 40px;
29
+ animation: spin 2s linear infinite;
30
+ position: relative;
31
+ top: 50%;
32
+ left: 50%;
33
+ transform: translate(-50%, -50%);
34
+ }
 
35
 
36
+ @keyframes spin {
37
+ 0% { transform: rotate(0deg); }
38
+ 100% { transform: rotate(360deg); }
39
+ }
40
+ </style>
41
  </head>
42
  <body>
43
  <h1>Face Swapper App</h1>
44
  <form id="swapForm" action="/swap_faces/" method="post" enctype="multipart/form-data">
45
  <h2>Upload Source Image</h2>
46
+ <input type="file" name="source_file" accept="image/*" required onchange="displayImage('source_image', this)"><br>
47
  <label>Source Face Position:</label>
48
  <input type="number" name="source_face_index" min="1" required><br>
49
  <h2>Upload Destination Image</h2>
50
+ <input type="file" name="destination_file" accept="image/*" required onchange="displayImage('destination_image', this)"><br>
51
  <label>Destination Face Position:</label>
52
  <input type="number" name="destination_face_index" min="1" required><br>
53
+ <button type="button" onclick="swapFaces()">Swap Faces</button>
54
  </form>
55
  <div id="resultImage">
56
+ <div id="loadingSpinner" style="display: none;"></div>
57
+ <div id="resultContainer"></div>
 
 
 
 
58
  </div>
 
59
 
60
  <script>
61
+ function displayImage(id, input) {
62
+ const file = input.files[0];
63
+ if (file) {
64
+ const reader = new FileReader();
65
+ reader.onload = function(e) {
66
+ const image = document.createElement('img');
67
+ image.src = e.target.result;
68
+ image.alt = id === 'source_image' ? 'Source Image' : 'Destination Image';
69
+ image.style.maxWidth = '100%';
70
+ const container = document.getElementById('resultContainer');
71
+ container.appendChild(image);
72
+ }
73
+ reader.readAsDataURL(file);
74
+ }
75
+ }
76
+
77
  async function swapFaces() {
78
+ const form = document.getElementById('swapForm');
79
+ const formData = new FormData(form);
80
 
81
+ try {
82
+ // Display loading spinner
83
+ const loadingSpinner = document.getElementById('loadingSpinner');
84
+ loadingSpinner.style.display = 'block';
85
 
86
+ // Remove previous result images
87
+ const resultContainer = document.getElementById('resultContainer');
88
+ resultContainer.innerHTML = '';
89
 
90
+ const response = await fetch('/swap_faces/', {
91
+ method: 'POST',
92
+ body: formData
93
+ });
94
+ const blob = await response.blob();
95
+ const imageUrl = URL.createObjectURL(blob);
 
 
 
96
 
97
+ // Display the result image
98
+ const resultImage = document.createElement('img');
99
+ resultImage.src = imageUrl;
100
+ resultImage.alt = 'Result Image';
101
+ resultImage.style.maxWidth = '100%';
102
+ resultContainer.appendChild(resultImage);
 
 
 
103
 
104
+ // Hide loading spinner after result image is displayed
105
+ loadingSpinner.style.display = 'none';
106
+ } catch (error) {
107
+ console.error('Error swapping faces:', error);
108
+ // Hide loading spinner if there's an error
109
+ const loadingSpinner = document.getElementById('loadingSpinner');
110
+ loadingSpinner.style.display = 'none';
111
+ }
112
+ }
113
  </script>
114
  </body>
115
  </html>