Ashrafb commited on
Commit
28c18e0
·
verified ·
1 Parent(s): 07f0aab

Create Indexcompress.html

Browse files
Files changed (1) hide show
  1. static/Indexcompress.html +497 -0
static/Indexcompress.html ADDED
@@ -0,0 +1,497 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.11/katex.min.css">
7
+ <link href="https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@100&display=swap" rel="stylesheet">
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
9
+ <style>
10
+ body {
11
+ background-color: #121212;
12
+ color: #FFFFFF;
13
+ }
14
+
15
+ /* Dark mode for upload buttons */
16
+ #upload-form button[type="button"] {
17
+ background-color: #1E7E34;
18
+ }
19
+
20
+ /* Dark mode for file input labels */
21
+ #image-label {
22
+ background-color: #BF2C25;
23
+ }
24
+
25
+ /* Dark mode for face number inputs */
26
+ #best_max_flavors {
27
+ background-color: #333333;
28
+ color: #FFFFFF;
29
+ border: 1px solid #555555;
30
+ }
31
+
32
+ /* Dark mode for swap button */
33
+ button[type="button"] {
34
+ background-color: #1E7E34;
35
+ }
36
+
37
+ /* Dark mode hover effect for swap button */
38
+ button[type="button"]:hover {
39
+ background-color: #2E9E44;
40
+ }
41
+
42
+ /* Style for upload buttons */
43
+ input[type="file"] {
44
+ display: none; /* Hide the default file input */
45
+ }
46
+ #upload-form label[for="image"] {
47
+ padding: 10px 20px;
48
+ background-color: #f44336;
49
+ color: white;
50
+ border-radius: 5px;
51
+ cursor: pointer;
52
+ display: inline-block;
53
+ margin: 0 auto;
54
+ }
55
+ #image-label {
56
+ padding: 10px 20px;
57
+ background-color: #f44336;
58
+ color: white;
59
+ border-radius: 5px;
60
+ cursor: pointer;
61
+ display: inline-block;
62
+ margin: 0 auto;
63
+ }
64
+
65
+ .uploadButton {
66
+ background-color: #4CAF50;
67
+ border: none;
68
+ color: white;
69
+ padding: 10px 20px;
70
+ text-align: center;
71
+ text-decoration: none;
72
+ display: inline-block;
73
+ font-size: 16px;
74
+ margin-top: 10px;
75
+ cursor: pointer;
76
+ border-radius: 5px;
77
+ margin: auto;
78
+ margin: 0 auto;
79
+ }
80
+
81
+ /* Style for file input labels */
82
+ #upload-form {
83
+ display: flex;
84
+ flex-direction: column;
85
+ align-items: center;
86
+ }
87
+
88
+ #image-label {
89
+ padding: 10px 20px;
90
+ background-color: #f44336;
91
+ color: white;
92
+ border-radius: 5px;
93
+ cursor: pointer;
94
+ display: block;
95
+ margin: 0 auto;
96
+ }
97
+
98
+ #image-label input[type="file"] {
99
+ display: none;
100
+ }
101
+
102
+ /* Style for face number inputs */
103
+ #mode, #best_max_flavors {
104
+ padding: 8px;
105
+ border: 1px solid #ccc;
106
+ border-radius: 4px;
107
+ box-sizing: border-box;
108
+ margin-top: 5px;
109
+ font-size: 16px;
110
+ }
111
+
112
+ /* Style for labels */
113
+ label {
114
+ font-weight: bold;
115
+ }
116
+
117
+ /* Optional: Increase space between elements */
118
+ form > * {
119
+ margin-bottom: 10px;
120
+ }
121
+
122
+ /* Style for the swap button */
123
+ button {
124
+ background-image: linear-gradient(
125
+ 45deg,
126
+ hsl(240deg 75% 29%) 0%,
127
+ hsl(254deg 78% 28%) 6%,
128
+ hsl(264deg 82% 27%) 13%,
129
+ hsl(272deg 87% 26%) 19%,
130
+ hsl(278deg 93% 25%) 25%,
131
+ hsl(284deg 98% 24%) 31%,
132
+ hsl(289deg 100% 23%) 37%,
133
+ hsl(294deg 100% 23%) 44%,
134
+ hsl(299deg 100% 22%) 50%,
135
+ hsl(303deg 100% 23%) 56%,
136
+ hsl(307deg 100% 24%) 63%,
137
+ hsl(311deg 100% 25%) 69%,
138
+ hsl(313deg 100% 26%) 75%,
139
+ hsl(316deg 95% 28%) 81%,
140
+ hsl(320deg 88% 30%) 87%,
141
+ hsl(323deg 81% 32%) 94%,
142
+ hsl(326deg 75% 33%) 100%
143
+ );
144
+ border: none;
145
+ color: white;
146
+ padding: 10px 20px;
147
+ text-align: center;
148
+ text-decoration: none;
149
+ display: inline-block;
150
+ font-size: 16px;
151
+ margin-top: 10px;
152
+ cursor: pointer;
153
+ border-radius: 5px;
154
+ display: block;
155
+ margin: 0 auto;
156
+ width: 200px;
157
+ }
158
+
159
+ /* Hover effect for the button */
160
+ button:hover {
161
+ background-color: #45a049;
162
+ }
163
+
164
+ /* Style for file input */
165
+ #image {
166
+ display: none; /* Hide the default file input */
167
+ }
168
+
169
+ #image-label {
170
+ padding: 10px 20px;
171
+ background-color: #f44336;
172
+ color: white;
173
+ border-radius: 5px;
174
+ cursor: pointer;
175
+ display: inline-block;
176
+ margin: 0 auto;
177
+ }
178
+
179
+ #image-label input[type="file"] {
180
+ display: none;
181
+ }
182
+
183
+ h1 {
184
+ text-align: center;
185
+ margin-bottom: 20px;
186
+ font-family: 'Barlow Condensed';
187
+ color: pink;
188
+ font-size: 40px; /* Adjust the font size as needed */
189
+ }
190
+
191
+ h2 {
192
+ font-size: 24px; /* Adjust size as needed */
193
+ font-family: 'Barlow Condensed';
194
+ color: #FFFFFF; /* Text color */
195
+ margin-top: 20px; /* Top margin */
196
+ margin-bottom: 10px; /* Bottom margin */
197
+ }
198
+
199
+ select {
200
+ width: 150px; /* Adjust width as needed */
201
+ padding: 8px;
202
+ border: 1px solid #ccc;
203
+ border-radius: 4px;
204
+ background-color: #333333; /* Background color */
205
+ color: white; /* Text color */
206
+ font-size: 16px;
207
+ }
208
+
209
+ #best_max_flavors {
210
+ width: 60px;
211
+ }
212
+
213
+ /* Style for the scale number input */
214
+ input[type="number"]#best_max_flavors {
215
+ padding: 8px;
216
+ width: 50px;
217
+ border: 1px solid #ccc;
218
+ border-radius: 4px;
219
+ box-sizing: border-box;
220
+ margin-top: 5px;
221
+ font-size: 16px;
222
+ color: white; /* Set text color to white */
223
+ background-color: #333333; /* Set background color */
224
+ }
225
+
226
+ /* Optional: Adjust focus styling for the scale number input */
227
+ input[type="number"]#best_max_flavors:focus {
228
+ outline: none; /* Remove default outline */
229
+ border-color: #1E7E34; /* Change border color on focus */
230
+ }
231
+
232
+ #estimatedTime {
233
+ display: none;
234
+ text-align: center; /* Center align the text */
235
+ margin-top: 10px; /* Add margin to separate it from the spinner */
236
+ color: white; /* Set text color */
237
+ }
238
+
239
+ #results {
240
+ border: 2px solid blue;
241
+ width: 265px;
242
+ height: 300px;
243
+ display: flex;
244
+ flex-direction: column;
245
+ overflow-y: scroll;
246
+ margin: auto;
247
+ margin-top: 30px;
248
+ padding-bottom: 7px;
249
+ gap: 14px;
250
+ background: linear-gradient(black , black) padding-box,
251
+ linear-gradient(to right, red, blue) border-box;
252
+ border-radius: 20px;
253
+ border: 2.5px solid transparent;
254
+ }
255
+
256
+ #image-preview {
257
+ border: 2px solid blue;
258
+ width: 200px;
259
+ height: 200px;
260
+ display: flex;
261
+ flex-direction: column;
262
+ overflow-y: scroll;
263
+ margin: auto;
264
+ margin-top: 30px;
265
+ padding-bottom: 7px;
266
+ gap: 100px;
267
+ background: linear-gradient(black , black) padding-box,
268
+ linear-gradient(to right, red, blue) border-box;
269
+ border-radius: 20px;
270
+ border: 2.5px solid transparent;
271
+ }
272
+
273
+ #sourceImage {
274
+ max-width: 100%;
275
+ height: auto;
276
+ display: block;
277
+ margin: auto;
278
+ }
279
+
280
+ #loadingSpinner {
281
+ border: 3px solid rgba(255, 255, 255, 0.3);
282
+ border-radius: 50%;
283
+ border-top: 3px solid #ffffff;
284
+ width: 20px;
285
+ height: 20px;
286
+ animation: spin 2s linear infinite;
287
+ position: relative;
288
+ top: 50%;
289
+ left: 50%;
290
+ transform: translate(-50%, -50%);
291
+ display: none; /* Initially hide the loading spinner */
292
+ }
293
+
294
+ @keyframes spin {
295
+ 0% { transform: rotate(0deg); }
296
+ 100% { transform: rotate(360deg); }
297
+ }
298
+ #results {
299
+ position: relative; /* Set position to relative */
300
+ /* Your existing styles */
301
+ }
302
+
303
+ #copyIcon {
304
+ font-size: 24px; /* Adjust the font size as needed */
305
+ position: absolute;
306
+ bottom: 10px; /* Adjust the distance from the bottom */
307
+ left: 10px; /* Adjust the distance from the left */
308
+ cursor: pointer;
309
+ z-index: 1;
310
+ color: rgba(255, 255, 255, 0.7); /* Adjust the opacity value */
311
+ }
312
+ #resultContainer {
313
+ /* Include padding and border in the total height */
314
+ }
315
+
316
+ #resultContainer p {
317
+ font-size: 14px; /* Adjust the font size as needed */
318
+ text-align: center; /* Center text horizontally */
319
+ margin: 5px 0; /* Add margin for spacing between paragraphs */
320
+ line-height: 1.5; /* Adjust line height for better readability */
321
+ }
322
+
323
+
324
+ </style>
325
+
326
+ </head>
327
+ <body>
328
+ <h1>Aiconvert.online</h1>
329
+ <form id="upload-form" enctype="multipart/form-data">
330
+ <label for="image">Select image:</label>
331
+ <input type="file" id="image" accept="image/*" required onchange="previewImage(event)">
332
+ <div id="image-preview">
333
+
334
+ <img id="sourceImage">
335
+ </div><br>
336
+ <label for="mode">Select Mode</label>
337
+ <select id="mode" required>
338
+ <option value="best">Best Mode</option>
339
+ <option value="classic">Classic Mode</option>
340
+ <option value="fast" selected>Fast Mode</option>
341
+
342
+ </select><br>
343
+
344
+
345
+ <label for="best_max_flavors">Max Flavors:</label>
346
+ <input type="number" id="best_max_flavors" value="4" min="2" max="24">
347
+ <br>
348
+ <button type="button" onclick="uploadImage()">Generate Prompt </button>
349
+
350
+ </form>
351
+
352
+ <div id="results">
353
+ <div id="estimatedTime" style="display: none;">Estimated time: 90s</div>
354
+ <div id="loadingSpinner" style="display: none;"></div>
355
+ <i class="far fa-copy" id="copyIcon" onclick="copyTextToClipboard()"></i>
356
+ <div id="resultContainer">
357
+
358
+ </div>
359
+ </div>
360
+
361
+ <script>
362
+ function previewImage(event) {
363
+ const file = event.target.files[0];
364
+ const imagePreview = document.getElementById('image-preview');
365
+ imagePreview.innerHTML = `<img src="${URL.createObjectURL(file)}" alt="Uploaded Image" style="max-width: 300px; max-height: 300px;">`;
366
+ }
367
+
368
+ async function uploadImage() {
369
+ const fileInput = document.getElementById('image');
370
+ const versionInput = document.getElementById('mode');
371
+ const scaleInput = document.getElementById('best_max_flavors');
372
+
373
+ // Check if the file input is empty
374
+ if (!fileInput.files[0]) {
375
+ document.getElementById('resultContainer').innerHTML = `<p style="color: white ;">Please upload an image.</p>`;
376
+ return;
377
+ }
378
+
379
+ // Clear the result container
380
+ document.getElementById('resultContainer').innerHTML = "";
381
+ const compressedFile = await compressImage(fileInput.files[0]);
382
+ const formData = new FormData();
383
+ formData.append('file', compressedFile);
384
+ formData.append('mode', versionInput.value);
385
+ formData.append('best_max_flavors', scaleInput.value);
386
+
387
+ // Display loading spinner
388
+ const loadingSpinner = document.getElementById('loadingSpinner');
389
+ loadingSpinner.style.display = 'block';
390
+ const estimatedTime = document.getElementById('estimatedTime');
391
+ estimatedTime.style.display = 'block';
392
+
393
+ try {
394
+ const response = await fetch('https://ashrafb-cintdogfast.hf.space/inference/', {
395
+ method: 'POST',
396
+ body: formData
397
+ });
398
+
399
+ // Hide loading spinner
400
+ loadingSpinner.style.display = 'none';
401
+ estimatedTime.style.display = 'none';
402
+
403
+ if (response.ok) {
404
+ const resultContainer = document.getElementById('resultContainer');
405
+ const data = await response.json(); // Assuming the response is JSON
406
+ resultContainer.innerHTML = '<h2></h2>';
407
+ data.prompt_results.forEach(result => {
408
+ resultContainer.innerHTML += '<p>' + result + '</p>';
409
+ });
410
+ } else {
411
+ document.getElementById('resultContainer').innerHTML = `<p style="color: white;">Oops! Something went wrong. Please try again later.</p>`;
412
+ }
413
+ } catch (error) {
414
+ console.error('Error:', error);
415
+ document.getElementById('resultContainer').innerHTML = `<p style="color: white ;">Oops! Something went wrong. Please try again later.</p>`;
416
+ }
417
+ }
418
+ async function compressImage(file) {
419
+ return new Promise((resolve, reject) => {
420
+ const reader = new FileReader();
421
+ reader.onload = function(event) {
422
+ const img = new Image();
423
+ img.src = event.target.result;
424
+
425
+ img.onload = function() {
426
+ const canvas = document.createElement('canvas');
427
+ const ctx = canvas.getContext('2d');
428
+
429
+ // Calculate the new dimensions to resize the image while maintaining aspect ratio
430
+ const maxWidth = 1000;
431
+ const maxHeight = 1000;
432
+ let width = img.width;
433
+ let height = img.height;
434
+
435
+ if (width > height) {
436
+ if (width > maxWidth) {
437
+ height *= maxWidth / width;
438
+ width = maxWidth;
439
+ }
440
+ } else {
441
+ if (height > maxHeight) {
442
+ width *= maxHeight / height;
443
+ height = maxHeight;
444
+ }
445
+ }
446
+
447
+ // Set the canvas dimensions
448
+ canvas.width = width;
449
+ canvas.height = height;
450
+
451
+ // Draw the image on the canvas with the new dimensions
452
+ ctx.drawImage(img, 0, 0, width, height);
453
+
454
+ // Convert canvas content to a blob
455
+ canvas.toBlob((blob) => {
456
+ resolve(blob);
457
+ }, 'image/jpeg', 1); // Adjust quality as needed (0.7 is 70% quality)
458
+ }
459
+ }
460
+
461
+ // Read the file as data URL
462
+ reader.readAsDataURL(file);
463
+ });
464
+ }
465
+
466
+ function copyTextToClipboard() {
467
+ const resultContainer = document.getElementById('resultContainer');
468
+ const textToCopy = resultContainer.innerText;
469
+
470
+ // Create a temporary textarea element to copy the text
471
+ const textarea = document.createElement('textarea');
472
+ textarea.value = textToCopy;
473
+ document.body.appendChild(textarea);
474
+
475
+ // Select the text inside the textarea
476
+ textarea.select();
477
+ textarea.setSelectionRange(0, 99999); // For mobile devices
478
+
479
+ // Copy the selected text
480
+ document.execCommand('copy');
481
+
482
+ // Remove the temporary textarea
483
+ document.body.removeChild(textarea);
484
+
485
+ // Change the copy icon text to "Copied"
486
+ const copyIcon = document.getElementById('copyIcon');
487
+ copyIcon.textContent = ' # Copied' ;
488
+ copyIcon.style.fontSize = '14px';
489
+ // Revert the copy icon back to "Copy" after 1.5 seconds
490
+ setTimeout(() => {
491
+ copyIcon.textContent = '';
492
+ }, 1500);
493
+ }
494
+
495
+ </script>
496
+ </body>
497
+ </html>