Ashrafb commited on
Commit
9f298f6
·
verified ·
1 Parent(s): ca676d0

Create index3.html

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