-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
359 lines (313 loc) · 10.6 KB
/
index.html
File metadata and controls
359 lines (313 loc) · 10.6 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Try-On Diffusion | Jay Tiwari</title>
<style>
/* Add styles for layout and user experience */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Press Start 2P', cursive;
color: #fff;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
background: url('/bgswp.gif');
background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
}
.container {
max-width: 600px;
margin: 20px auto;
border: 6px solid #000;
background: #333;
padding: 20px;
box-shadow: 8px 8px 0px #000;
text-align: center;
animation: fadeIn 1s ease-out;
background: url('/bgswapai.gif');
background-size: cover;
justify-content: center;
}
h3 {
font-size: 30px;
color: #333;
margin-bottom: 20px;
font-weight: 600;
letter-spacing: 0.5px;
}
p {
font-size: 16px;
color: #555;
margin-bottom: 20px;
font-weight: 500;
}
.upload-area {
width: 100%;
padding: 20px;
margin: 15px 0;
border: 2px dashed #000000;
border-radius: 10px;
background-color: transparent; /* Set background to transparent */
font-size: 16px;
text-align: center;
transition: 0.3s;
outline: none;
}
.upload-area:hover {
border-color: #0072ff;
}
.upload-area p {
margin-top: 10px;
}
input[type="file"] {
display: none;
}
button {
padding: 15px 25px;
background-color: #0072ff;
color: white;
border: none;
border-radius: 10px;
cursor: pointer;
font-size: 18px;
width: 100%;
transition: background-color 0.3s, transform 0.2s;
margin-top: 10px;
}
button:hover {
background-color: #005bb5;
transform: scale(1.05);
}
button:active {
background-color: #00448b;
}
.image-container {
margin-top: 30px;
display: flex;
justify-content: center;
align-items: center;
}
#output-image {
max-width: 100%;
max-height: 350px;
border-radius: 15px;
object-fit: contain;
display: none; /* Initially hidden until generated */
box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
}
.footer {
margin-top: 20px;
font-size: 14px;
color: #777;
}
.footer a {
color: #0072ff;
text-decoration: none;
font-weight: 500;
}
.footer a:hover {
text-decoration: underline;
}
#loading-text {
font-size: 18px;
color: #0072ff;
margin-top: 20px;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@media screen and (max-width: 480px) {
.container {
padding: 25px;
}
h3 {
font-size: 26px;
}
p {
font-size: 14px;
}
button {
font-size: 16px;
}
}
.transparent-90s-button {
display: inline-block;
font-family: 'Press Start 2P', cursive;
background: transparent; /* Make background transparent */
border: 3px solid #000; /* Black border */
padding: 10px 20px;
font-weight: bold;
font-size: 16px;
cursor: pointer;
text-decoration: none;
color: #000; /* Text color stays black */
box-shadow: 3px 3px 0px #000; /* Shadow for 3D effect */
transition: all 0.3s ease;
}
.transparent-90s-button:hover {
background-color: rgba(244, 67, 54, 0.1); /* Slight red translucent fill on hover */
color: #fff;
border-color: #fff;
box-shadow: 4px 4px 15px rgba(0, 0, 0, 0.2), -4px -4px 15px rgba(255, 255, 255, 0.3); /* Stronger shadow on hover */
}
.transparent-90s-button:active {
background-color: rgba(244, 67, 54, 0.2); /* Slightly stronger background on click */
box-shadow: inset 4px 4px 10px rgba(0, 0, 0, 0.2); /* Inset shadow for click effect */
}
</style>
</head>
<body>
<div class="container">
<h3>Virtual Try-On Diffusion</h3>
<p>Upload a model and a cloth image to generate a virtual try-on.</p>
<!-- Model Image Upload Area -->
<div class="upload-area" id="model-upload" ondrop="handleDrop(event, 'model')" ondragover="allowDrop(event)" onclick="document.getElementById('model-image').click()">
<input type="file" id="model-image" accept="image/*" onchange="previewImage(event, 'model')" />
<p>Drag & Drop Model Image or Click to Upload</p>
</div>
<!-- Cloth Image Upload Area -->
<div class="upload-area" id="cloth-upload" ondrop="handleDrop(event, 'cloth')" ondragover="allowDrop(event)" onclick="document.getElementById('cloth-image').click()">
<input type="file" id="cloth-image" accept="image/*" onchange="previewImage(event, 'cloth')" />
<p>Drag & Drop Cloth Image or Click to Upload</p>
</div>
<!-- Generate Button -->
<button id="generate-button" class="transparent-90s-button">Generate</button>
<!-- Reset Button -->
<button id="reset-button" class="transparent-90s-button">Reset</button>
<!-- Output Image -->
<div class="image-container">
<img id="output-image" src="" alt="Generated Try-On Image" />
<!-- Download Button -->
<a id="download-link" href="#" download="generated_image.png" style="display: none;">
<button id="download-button">Download Image</button>
</a>
</div>
<!-- Footer -->
<div class="footer">
<p>Powered by <a href="https://www.jaytiwari.in/" target="_blank">jaytiwari.in</a></p>
</div>
</div>
<script>
// Handle drag and drop
function allowDrop(event) {
event.preventDefault();
}
function handleDrop(event, type) {
event.preventDefault();
const file = event.dataTransfer.files[0];
if (file) {
if (type === 'model') {
document.getElementById('model-image').files = event.dataTransfer.files;
} else {
document.getElementById('cloth-image').files = event.dataTransfer.files;
}
previewImage({ target: { files: event.dataTransfer.files } }, type);
}
}
function previewImage(event, type) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
const img = new Image();
img.src = e.target.result;
if (type === 'model') {
img.onload = function() {
document.getElementById('model-upload').querySelector('p').textContent = "Model Image Uploaded";
};
} else {
img.onload = function() {
document.getElementById('cloth-upload').querySelector('p').textContent = "Cloth Image Uploaded";
};
}
};
reader.readAsDataURL(file);
}
// Listen for Generate Try-On Image button click
document.getElementById('generate-button').addEventListener('click', function(event) {
event.preventDefault(); // Prevent page reload explicitly
const modelImageInput = document.getElementById('model-image');
const clothImageInput = document.getElementById('cloth-image');
const outputImage = document.getElementById('output-image');
const downloadLink = document.getElementById('download-link');
// Check if both files are uploaded
if (modelImageInput.files.length === 0 || clothImageInput.files.length === 0) {
alert('Please upload both model and cloth images.');
return;
}
// Hide the output image during loading
outputImage.style.display = 'none';
// Add loading indicator
let loadingText = document.createElement('p');
loadingText.textContent = 'Generating image...';
loadingText.id = 'loading-text';
document.querySelector('.container').appendChild(loadingText);
// Prepare form data to send to Flask API
const formData = new FormData();
formData.append('model_image', modelImageInput.files[0]);
formData.append('cloth_image', clothImageInput.files[0]);
// Use fetch to send the request asynchronously
fetch('http://localhost:5000/generate-tryon', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
// Check the API response status
if (data.status === 'success') {
outputImage.src = `data:image/png;base64,${data.output_image}`;
outputImage.style.display = 'block'; // Show the image
downloadLink.href = `data:image/png;base64,${data.output_image}`; // Set download link
downloadLink.style.display = 'inline-block'; // Show the download button
} else {
alert('Error: ' + data.message);
}
// Remove loading text after the response is processed
document.getElementById('loading-text').remove();
})
.catch(error => {
// Handle any errors during the fetch request
alert('An error occurred: ' + error);
document.getElementById('loading-text').remove();
});
});
// Reset the page
document.getElementById('reset-button').addEventListener('click', function() {
// Reset the input fields for model and cloth image
document.getElementById('model-image').value = '';
document.getElementById('cloth-image').value = '';
// Reset the upload areas text
document.getElementById('model-upload').querySelector('p').textContent = 'Drag & Drop Model Image or Click to Upload';
document.getElementById('cloth-upload').querySelector('p').textContent = 'Drag & Drop Cloth Image or Click to Upload';
// Hide the output image and clear its source
const outputImage = document.getElementById('output-image');
outputImage.style.display = 'none';
outputImage.src = '';
// Hide the download button
document.getElementById('download-link').style.display = 'none';
// Remove any loading text that might still be visible
const loadingText = document.getElementById('loading-text');
if (loadingText) {
loadingText.remove();
}
});
</script>
</body>
</html>