| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| <title>Real-Time Face Swap</title> |
| <style> |
| body { |
| font-family: Arial, sans-serif; |
| background: #f9f9f9; |
| text-align: center; |
| padding: 20px; |
| } |
| h1 { |
| margin-bottom: 20px; |
| } |
| form { |
| display: inline-block; |
| background: white; |
| padding: 20px; |
| border-radius: 8px; |
| box-shadow: 0 0 10px rgba(0,0,0,0.1); |
| } |
| label { |
| display: block; |
| margin-top: 10px; |
| font-weight: bold; |
| } |
| input[type="file"] { |
| margin-top: 5px; |
| } |
| button { |
| margin-top: 15px; |
| padding: 10px 20px; |
| font-size: 16px; |
| cursor: pointer; |
| background: #007bff; |
| color: white; |
| border: none; |
| border-radius: 4px; |
| } |
| button:disabled { |
| background: #aaa; |
| cursor: not-allowed; |
| } |
| #result { |
| margin-top: 30px; |
| } |
| #result img { |
| max-width: 300px; |
| border-radius: 8px; |
| box-shadow: 0 0 8px rgba(0,0,0,0.1); |
| } |
| #status { |
| margin-top: 10px; |
| font-style: italic; |
| color: #555; |
| } |
| </style> |
| </head> |
| <body> |
| <h1>Real-Time Face Swap</h1> |
|
|
| <form id="uploadForm"> |
| <label for="source">Source Image:</label> |
| <input type="file" name="source" id="source" accept="image/*" required /> |
|
|
| <label for="target">Target Image:</label> |
| <input type="file" name="target" id="target" accept="image/*" required /> |
|
|
| <button type="submit" id="swapBtn">Swap Faces</button> |
| </form> |
|
|
| <div id="status"></div> |
| <div id="result"></div> |
|
|
| <script> |
| const form = document.getElementById('uploadForm'); |
| const statusDiv = document.getElementById('status'); |
| const resultDiv = document.getElementById('result'); |
| const swapBtn = document.getElementById('swapBtn'); |
| |
| form.addEventListener('submit', async (e) => { |
| e.preventDefault(); |
| |
| |
| swapBtn.disabled = true; |
| statusDiv.textContent = 'Processing...'; |
| resultDiv.innerHTML = ''; |
| |
| const formData = new FormData(); |
| formData.append('source', document.getElementById('source').files[0]); |
| formData.append('target', document.getElementById('target').files[0]); |
| |
| try { |
| const response = await fetch('/swap', { |
| method: 'POST', |
| body: formData |
| }); |
| |
| if (!response.ok) { |
| const err = await response.json(); |
| statusDiv.textContent = 'Error: ' + (err.error || response.statusText); |
| swapBtn.disabled = false; |
| return; |
| } |
| |
| const blob = await response.blob(); |
| const imgURL = URL.createObjectURL(blob); |
| |
| statusDiv.textContent = ''; |
| resultDiv.innerHTML = '<h3>Result:</h3><img src="' + imgURL + '" alt="Swapped Image" />'; |
| } catch (err) { |
| statusDiv.textContent = 'Error: ' + err.message; |
| } finally { |
| swapBtn.disabled = false; |
| } |
| }); |
| </script> |
| </body> |
| </html> |