Spaces:
Running
Running
File size: 9,995 Bytes
63a4bcf cecb6ce 63a4bcf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Virtual Try-On</title>
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
// Handle the popup window
function openPopup() {
document.getElementById("popup").style.display = "block";
document.getElementById("emailInput").style.display = "block";
document.getElementById("submitBtn").style.display = "block";
document.getElementById("popupMessage").innerText = "Get a free trial key sent to your email";
}
function closePopup() {
document.getElementById("popup").style.display = "none";
document.getElementById("emailInput").value = "";
document.getElementById("popupMessage").innerText = "Get a free trial key sent to your email";
}
// Handle email submission
function submitEmail() {
const emailInput = document.getElementById("emailInput").value;
fetch("/send_key", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email: emailInput })
})
.then(response => response.json())
.then(data => {
document.getElementById("popupMessage").innerText = data.message;
document.getElementById("emailInput").style.display = "none";
document.getElementById("submitBtn").style.display = "none";
})
.catch(err => alert("Error: " + err));
}
// Handle drag-and-drop and previews
function enableImagePreview(boxId, inputId, previewId, textId, removeButtonId) {
const box = document.getElementById(boxId);
const input = document.getElementById(inputId);
const preview = document.getElementById(previewId);
const text = document.getElementById(textId);
box.addEventListener("dragover", (e) => {
e.preventDefault();
box.classList.add("drag-over");
});
box.addEventListener("dragleave", () => box.classList.remove("drag-over"));
box.addEventListener("drop", (e) => {
e.preventDefault();
box.classList.remove("drag-over");
const file = e.dataTransfer.files[0];
input.files = e.dataTransfer.files;
showPreview(file, preview, text, removeButtonId);
});
input.addEventListener("change", () => {
if (input.files.length > 0) {
showPreview(input.files[0], preview, text, removeButtonId);
}
});
}
function showPreview(file, previewElement, textElement, removeButton) {
const reader = new FileReader();
reader.onload = (e) => {
previewElement.src = e.target.result;
previewElement.style.display = "block";
textElement.style.display = "none";
document.getElementById(removeButton).style.display = "flex";
};
reader.readAsDataURL(file);
}
function removeImage(inputId, previewId, textId, removeButtonId) {
const input = document.getElementById(inputId);
const preview = document.getElementById(previewId);
const text = document.getElementById(textId);
const removeButton = document.getElementById(removeButtonId);
input.value = ""; // Clear the file input
preview.src = ""; // Clear the preview image
preview.style.display = "none";
text.style.display = "block";
removeButton.style.display = "none";
}
// Submit form with AJAX
function submitForm(event) {
event.preventDefault();
const formData = new FormData(document.getElementById("imageForm"));
document.getElementById("outputImage").style.display = "none";
const spinner = document.getElementById("spinner");
spinner.style.display = "block"; // Unhide the spinner
// Get the key input value and add it to the form data
const keyInput = document.querySelector('.key-input').value;
formData.append('key', keyInput);
fetch("/process", {
method: "POST",
body: formData
})
.then(response => response.json())
.then(data => {
if (data.output_image) {
spinner.style.display = "none";
document.getElementById("outputImage").src = data.output_image;
document.getElementById("outputImage").style.display = "block";
} else if (data.error) {
alert(data.error);
}
})
.catch(err => {
spinner.style.display = "none"; // Hide the spinner on error
alert("Error: " + err);
})
.finally(() => {
spinner.style.display = "none"; // Ensure spinner hides after completion
});
}
window.onload = () => {
enableImagePreview("box1", "input1", "preview1", "text1", "remove1");
enableImagePreview("box2", "input2", "preview2", "text2", "remove2");
document.getElementById("imageForm").addEventListener("submit", submitForm);
};
</script>
</head>
<body>
<div class="container">
<!-- Title -->
<h1 class="title">Virtual Try-On</h1>
<p> Reach out to <a href="mailto:[email protected]">[email protected]</a> for inquiries. </p>
<!-- Key Input -->
<div class="key-container">
<input type="text" class="key-input" placeholder="Input your key here">
</div>
<button type="button" class="get-key-btn" onclick="openPopup()">Get a free key</button>
<!-- Form -->
<form id="imageForm">
<div class="input-container">
<div class="box-wrapper">
<p>Person</p>
<div class="drag-drop-box" id="box1">
<p id="text1">Person/Model Image</p>
<input type="file" id="input1" name="image1" accept="image/*" required>
<img id="preview1" class="preview" style="display: none;">
<span class="remove-btn" id="remove1" style="display: none;" onclick="removeImage('input1', 'preview1', 'text1', 'remove1')">Γ</span>
</div>
</div>
<!-- Input Box 2 -->
<div class="box-wrapper">
<p>Garment</p>
<div class="drag-drop-box" id="box2">
<p id="text2">Garment Image</p>
<input type="file" id="input2" name="image2" accept="image/*" required>
<img id="preview2" class="preview" style="display: none;">
<span class="remove-btn" id="remove2" style="display: none;" onclick="removeImage('input2', 'preview2', 'text2', 'remove2')">Γ</span>
</div>
</div>
<!-- Output Container -->
<div class="box-wrapper">
<p>Result</p>
<div class="output-container">
<div class="output-box">
<img id="spinner" src="{{ url_for('static', filename='spinner.gif') }}" style="display: none;" alt="Loading...">
<img id="outputImage" style="display: none;" alt="Output Image">
</div>
<!-- Generate Button -->
<button type="submit" class="generate-btn">Generate (~20 sec)</button>
</div>
</div>
</div>
</form>
<div class="image-container">
<img src="https://huggingface.co/spaces/tonyassi/Virtual-Try-On-Pro/resolve/main/examples/kim1.jpg" alt="Image 1">
<img src="https://huggingface.co/spaces/tonyassi/Virtual-Try-On-Pro/resolve/main/examples/kim2.jpg" alt="Image 2">
<img src="https://huggingface.co/spaces/tonyassi/Virtual-Try-On-Pro-Dev/resolve/main/examples/kim3.jpg" alt="Image 3">
</div>
<div class="image-container">
<img src="https://huggingface.co/spaces/tonyassi/Virtual-Try-On-Pro/resolve/main/examples/meg1.jpg" alt="Image 1">
<img src="https://huggingface.co/spaces/tonyassi/Virtual-Try-On-Pro/resolve/main/examples/meg2.jpg" alt="Image 2">
<img src="https://huggingface.co/spaces/tonyassi/Virtual-Try-On-Pro/resolve/main/examples/meg3.jpg" alt="Image 3">
</div>
<div class="image-container">
<img src="https://huggingface.co/spaces/tonyassi/Virtual-Try-On-Pro/resolve/main/examples/bella1.jpg" alt="Image 1">
<img src="https://huggingface.co/spaces/tonyassi/Virtual-Try-On-Pro/resolve/main/examples/bella2.jpg" alt="Image 2">
<img src="https://huggingface.co/spaces/tonyassi/Virtual-Try-On-Pro/resolve/main/examples/bella3.jpg" alt="Image 3">
</div>
</div>
<!-- Popup Window -->
<div id="popup" class="popup">
<div class="popup-content">
<span class="close-btn" onclick="closePopup()">Γ</span>
<p id="popupMessage">Get a free trial key sent to your gmail</p>
<input type="email" id="emailInput" class="popup-input" placeholder="Email">
<button id="submitBtn" type="button" class="submit-btn" onclick="submitEmail()">Submit</button>
</div>
</div>
</body>
</html>
|