Ashrafb commited on
Commit
84996cc
·
verified ·
1 Parent(s): cc0b0fb

Create index3.html

Browse files
Files changed (1) hide show
  1. static/index3.html +370 -0
static/index3.html ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="ai-tool-container">
2
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.11/katex.min.css">
3
+ <link href="https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@100&display=swap" rel="stylesheet">
4
+ <h3>Aiconvert.online </h3>
5
+ <form id="uploadForm" action="/upload/" method="post" enctype="multipart/form-data">
6
+ <label for="sourceFile" id="uploadLabel">Choose image </label>
7
+ <input type="file" id="sourceFile" name="source_file" accept="image/*" required onchange="previewImage(event, 'sourceImage')"><br>
8
+ <div id="sourceImageContainer">
9
+ <img id="sourceImage"src="https://aiconvert.online/wp-content/uploads/2024/07/Source-Image.jpg" width="200" height="100" alt="uploaded Image">
10
+ </div><br>
11
+ <button type="button" onclick="uploadFile()">Generate </button> <!-- Changed to type="button" and added onclick handler -->
12
+ </form>
13
+ <div id="resultImage">
14
+ <div id="loadingSpinner" style="display: none;">
15
+ <!-- Replace this with your loading spinner HTML/CSS -->
16
+ </div>
17
+ <div id="resultContainer"></div>
18
+ </div>
19
+ <button id="downloadButton" style="display: block ;" onclick="downloadResultImage()">Download </button>
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+ <script>
28
+ function previewImage(event) {
29
+ const file = event.target.files[0];
30
+ const imagePreview = document.getElementById('sourceImageContainer');
31
+ imagePreview.innerHTML = `<img src="${URL.createObjectURL(file)}" alt="Uploaded Image" style="max-width: 300px; max-height: 300px;">`;
32
+ }
33
+
34
+ async function uploadFile() {
35
+ const sourceFileInput = document.getElementById('sourceFile');
36
+ const resultContainer = document.getElementById('resultContainer');
37
+
38
+
39
+
40
+ // Check if both source and destination file inputs are empty
41
+ if (!sourceFileInput.files[0] ) {
42
+ // Update the result container with the error message
43
+ resultContainer.innerHTML = "<p>Please upload an image.</p>";
44
+ return;
45
+ }
46
+
47
+ // Clear the result container if both images are uploaded
48
+ resultContainer.innerHTML = "";
49
+ const compressedFile = await compressImage(sourceFile.files[0]);
50
+ const formData = new FormData();
51
+ formData.append('file', compressedFile);
52
+
53
+
54
+ try {
55
+ // Display loading spinner
56
+ const loadingSpinner = document.getElementById('loadingSpinner');
57
+ loadingSpinner.style.display = 'block';
58
+
59
+ const response = await fetch('https://ashrafb-itsdockertest.hf.space/upload/', {
60
+ method: 'POST',
61
+ body: formData
62
+ });
63
+ if (response.ok) {
64
+ // If successful response, display the result image
65
+ const data = await response.json();
66
+ const sketchImage = document.createElement('img');
67
+ sketchImage.style.maxWidth = '100%'; // Adjust this value as needed
68
+ sketchImage.style.maxHeight = '100%'; // Adjust this value as needed
69
+ sketchImage.src = data.sketch_image_base64;
70
+ resultContainer.appendChild(sketchImage);
71
+
72
+ } else {
73
+ // If server error, display the error message
74
+ const errorMessage = await response.text();
75
+ resultContainer.innerHTML = `<p>Oops! Something went wrong. Please try again later. </p>`;
76
+ }
77
+ // Hide loading spinner after result (or error message) is displayed
78
+ loadingSpinner.style.display = 'none';
79
+ } catch (error) {
80
+ console.error('Error swapping faces:', error);
81
+ // Hide loading spinner if there's an error
82
+ const loadingSpinner = document.getElementById('loadingSpinner');
83
+ loadingSpinner.style.display = 'none';
84
+ }
85
+ }
86
+
87
+ async function compressImage(file) {
88
+ return new Promise((resolve, reject) => {
89
+ const reader = new FileReader();
90
+ reader.onload = function(event) {
91
+ const img = new Image();
92
+ img.src = event.target.result;
93
+
94
+ img.onload = function() {
95
+ const canvas = document.createElement('canvas');
96
+ const ctx = canvas.getContext('2d');
97
+
98
+ // Calculate the new dimensions to resize the image while maintaining aspect ratio
99
+ const maxWidth = 1000;
100
+ const maxHeight = 1000;
101
+ let width = img.width;
102
+ let height = img.height;
103
+
104
+ if (width > height) {
105
+ if (width > maxWidth) {
106
+ height *= maxWidth / width;
107
+ width = maxWidth;
108
+ }
109
+ } else {
110
+ if (height > maxHeight) {
111
+ width *= maxHeight / height;
112
+ height = maxHeight;
113
+ }
114
+ }
115
+
116
+ // Set the canvas dimensions
117
+ canvas.width = width;
118
+ canvas.height = height;
119
+
120
+ // Draw the image on the canvas with the new dimensions
121
+ ctx.drawImage(img, 0, 0, width, height);
122
+
123
+ // Convert canvas content to a blob
124
+ canvas.toBlob((blob) => {
125
+ resolve(blob);
126
+ }, 'image/jpeg', 1); // Adjust quality as needed (0.7 is 70% quality)
127
+ }
128
+ }
129
+
130
+ // Read the file as data URL
131
+ reader.readAsDataURL(file);
132
+ });
133
+ }
134
+
135
+ function downloadResultImage() {
136
+ const resultImage = document.getElementById('resultContainer').querySelector('img');
137
+ const link = document.createElement('a');
138
+ link.href = resultImage.src;
139
+ link.download = 'result_image.png';
140
+ document.body.appendChild(link);
141
+ link.click();
142
+ document.body.removeChild(link);
143
+ }
144
+
145
+
146
+ </script>
147
+
148
+
149
+ <style>
150
+ .ai-tool-container {
151
+ background-color: #121212;
152
+ color: #FFFFFF;
153
+ direction: ltr; /* Explicitly set direction to LTR */
154
+ }
155
+
156
+
157
+
158
+
159
+
160
+ /* Dark mode for face number inputs */
161
+ .ai-tool-container input[type="number"] {
162
+ background-color: #333333;
163
+ color: #FFFFFF;
164
+ border: 1px solid #555555;
165
+ }
166
+
167
+ /* Dark mode for swap button */
168
+ .ai-tool-container button[type="button"] {
169
+ background-color: #1E7E34;
170
+ }
171
+
172
+ /* Dark mode hover effect for swap button */
173
+ .ai-tool-container button[type="button"]:hover {
174
+ background-color: #2E9E44;
175
+ }
176
+
177
+ /* Style for upload buttons */
178
+ .ai-tool-container input[type="file"] {
179
+ display: none; /* Hide the default file input */
180
+ }
181
+
182
+
183
+
184
+ /* Style for file input labels */
185
+ .ai-tool-container #uploadForm {
186
+ display: flex;
187
+ flex-direction: column;
188
+ align-items: center;
189
+ }
190
+
191
+ .ai-tool-container #uploadLabel {
192
+ padding: 10px 20px;
193
+ background-color: #8b0000;
194
+ color: white;
195
+ border-radius: 5px;
196
+ cursor: pointer;
197
+ display: inline-block;
198
+ }
199
+
200
+
201
+
202
+ /* Style for face number inputs */
203
+ .ai-tool-container input[type="number"] {
204
+ padding: 8px;
205
+ Width :50px;
206
+ border: 1px solid #ccc;
207
+ border-radius: 4px;
208
+ box-sizing: border-box;
209
+ margin-top: 5px;
210
+ font-size: 16px;
211
+ }
212
+
213
+ /* Style for labels */
214
+ .ai-tool-container label {
215
+ font-weight: bold;
216
+ }
217
+
218
+ /* Optional: Increase space between elements */
219
+ .ai-tool-container form > * {
220
+ margin-bottom: 10px;
221
+ }
222
+ /* Style for the swap button */
223
+ .ai-tool-container button[type="button"] {
224
+ background-image: linear-gradient(
225
+ 45deg,
226
+ hsl(240deg 75% 29%) 0%,
227
+ hsl(254deg 78% 28%) 6%,
228
+ hsl(264deg 82% 27%) 13%,
229
+ hsl(272deg 87% 26%) 19%,
230
+ hsl(278deg 93% 25%) 25%,
231
+ hsl(284deg 98% 24%) 31%,
232
+ hsl(289deg 100% 23%) 37%,
233
+ hsl(294deg 100% 23%) 44%,
234
+ hsl(299deg 100% 22%) 50%,
235
+ hsl(303deg 100% 23%) 56%,
236
+ hsl(307deg 100% 24%) 63%,
237
+ hsl(311deg 100% 25%) 69%,
238
+ hsl(313deg 100% 26%) 75%,
239
+ hsl(316deg 95% 28%) 81%,
240
+ hsl(320deg 88% 30%) 87%,
241
+ hsl(323deg 81% 32%) 94%,
242
+ hsl(326deg 75% 33%) 100%
243
+ );
244
+ border: none;
245
+ color: white;
246
+ padding: 10px 20px;
247
+ text-align: center;
248
+ text-decoration: none;
249
+ display: inline-block;
250
+ font-size: 16px;
251
+ margin-top: 10px;
252
+ cursor: pointer;
253
+ border-radius: 5px;
254
+ display: block; /* Change display property to block */
255
+ margin: 0 auto;
256
+ Width :200px;
257
+ }
258
+
259
+ /* Hover effect for the swap button */
260
+ .ai-tool-container button[type="button"]:hover {
261
+ background-color: #45a049;
262
+ }
263
+ .ai-tool-container h3 {
264
+ text-align: center;
265
+ margin-bottom: 20px;
266
+ font-family: 'Barlow Condensed';
267
+ color: pink;
268
+ font-size: 24px; /* Adjust the font size as needed */
269
+ }
270
+
271
+
272
+
273
+
274
+ .ai-tool-container #resultImage {
275
+ border: 2px solid blue;
276
+ width: 269px;
277
+ height: 300px;
278
+ display: flex;
279
+ flex-direction: column;
280
+ overflow-y: scroll;
281
+ margin: auto;
282
+ margin-top: 30px;
283
+ padding-bottom: 7px;
284
+ gap: 14px;
285
+ background: linear-gradient(black , black) padding-box,
286
+ linear-gradient(to right, red, blue) border-box;
287
+ border-radius: 20px;
288
+ border: 2.5px solid transparent;
289
+ }
290
+
291
+ .ai-tool-container #sourceImageContainer, #destinationImageContainer {
292
+ border: 2px solid blue;
293
+ width: 200px;
294
+ height: 200px;
295
+ display: flex;
296
+ flex-direction: column;
297
+ overflow-y: scroll;
298
+ margin: auto;
299
+ margin-top: 30px;
300
+ padding-bottom: 7px;
301
+ gap: 100px;
302
+ background: linear-gradient(black , black) padding-box,
303
+ linear-gradient(to right, red, blue) border-box;
304
+ border-radius: 20px;
305
+ border: 2.5px solid transparent;
306
+ }
307
+
308
+ .ai-tool-container #sourceImage, #destinationImage {
309
+ max-width: 100%;
310
+ height: auto;
311
+ display: block;
312
+ margin: auto;
313
+ }
314
+
315
+ .ai-tool-container #loadingSpinner {
316
+ border: 5px solid rgba(255, 255, 255, 0.3);
317
+ border-radius: 50%;
318
+ border-top: 5px solid #ffffff;
319
+ width: 20px;
320
+ height: 20px;
321
+ animation: spin 2s linear infinite;
322
+ position: relative;
323
+ top: 50%;
324
+ left: 50%;
325
+ transform: translate(-50%, -50%);
326
+ display: none; /* Initially hide the loading spinner */
327
+ }
328
+
329
+ @keyframes spin {
330
+ 0% { transform: rotate(0deg); }
331
+ 100% { transform: rotate(360deg); }
332
+ }
333
+ .ai-tool-container #downloadButton{
334
+
335
+ background-image: linear-gradient(
336
+ 45deg,
337
+ hsl(240deg 75% 29%) 0%,
338
+ hsl(254deg 78% 28%) 6%,
339
+ hsl(264deg 82% 27%) 13%,
340
+ hsl(272deg 87% 26%) 19%,
341
+ hsl(278deg 93% 25%) 25%,
342
+ hsl(284deg 98% 24%) 31%,
343
+ hsl(289deg 100% 23%) 37%,
344
+ hsl(294deg 100% 23%) 44%,
345
+ hsl(299deg 100% 22%) 50%,
346
+ hsl(303deg 100% 23%) 56%,
347
+ hsl(307deg 100% 24%) 63%,
348
+ hsl(311deg 100% 25%) 69%,
349
+ hsl(313deg 100% 26%) 75%,
350
+ hsl(316deg 95% 28%) 81%,
351
+ hsl(320deg 88% 30%) 87%,
352
+ hsl(323deg 81% 32%) 94%,
353
+ hsl(326deg 75% 33%) 100%
354
+ );
355
+ border: none;
356
+ color: white;
357
+ padding: 10px 20px;
358
+ text-align: center;
359
+ text-decoration: none;
360
+ display: inline-block;
361
+ font-size: 16px;
362
+ margin-top: 10px;
363
+ cursor: pointer;
364
+ border-radius: 5px;
365
+ display: block; /* Change display property to block */
366
+ margin: 0 auto;
367
+ Width :200px;
368
+ }
369
+ </style>
370
+ </div>