Update static/index.html
Browse files- static/index.html +37 -29
static/index.html
CHANGED
@@ -448,47 +448,55 @@
|
|
448 |
|
449 |
|
450 |
|
451 |
-
|
452 |
const inputs = document.getElementById("inputs").value;
|
453 |
-
const noiseLevel = document.getElementById("noise_level").value;
|
454 |
-
const isNegative = document.getElementById("is_negative").value;
|
455 |
-
const steps = document.getElementById("steps").value;
|
456 |
-
const cfgScale = document.getElementById("cfg_scale").value;
|
457 |
-
const seed = document.getElementById("seed").value;
|
458 |
-
const resultContainer = document.getElementById("resultContainer");
|
459 |
-
|
460 |
-
// Check if the input field is empty
|
461 |
if (!inputs) {
|
462 |
-
|
|
|
463 |
return;
|
464 |
}
|
465 |
|
466 |
-
// Clear the result container
|
467 |
-
resultContainer.innerHTML = "";
|
468 |
-
|
469 |
-
// Display loading spinner
|
470 |
const loadingSpinner = document.getElementById('loadingSpinner');
|
471 |
-
|
472 |
-
|
473 |
-
|
|
|
|
|
|
|
|
|
474 |
|
475 |
-
|
476 |
-
throw new Error('Network response was not ok');
|
477 |
-
}
|
478 |
|
479 |
-
|
|
|
480 |
|
481 |
-
|
482 |
-
|
|
|
483 |
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
490 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
491 |
}
|
|
|
|
|
492 |
|
493 |
|
494 |
|
|
|
448 |
|
449 |
|
450 |
|
451 |
+
async function sendInputs() {
|
452 |
const inputs = document.getElementById("inputs").value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
453 |
if (!inputs) {
|
454 |
+
const imageBox = document.getElementById("resultContainer");
|
455 |
+
imageBox.innerHTML = "<p>Please enter a prompt before sending.</p>";
|
456 |
return;
|
457 |
}
|
458 |
|
|
|
|
|
|
|
|
|
459 |
const loadingSpinner = document.getElementById('loadingSpinner');
|
460 |
+
loadingSpinner.style.display = 'block';
|
461 |
+
|
462 |
+
const noiseLevel = document.getElementById("noise_level").value;
|
463 |
+
const isNegative = document.getElementById("is_negative").value;
|
464 |
+
const steps = document.getElementById("steps").value;
|
465 |
+
const cfgScale = document.getElementById("cfg_scale").value;
|
466 |
+
const seed = document.getElementById("seed").value;
|
467 |
|
468 |
+
const resultContainer = document.getElementById("resultContainer");
|
|
|
|
|
469 |
|
470 |
+
try {
|
471 |
+
const response = await fetch(`/send_inputs?inputs=${encodeURIComponent(inputs)}&noise_level=${noiseLevel}&is_negative=${isNegative}&steps=${steps}&cfg_scale=${cfgScale}&seed=${seed}`);
|
472 |
|
473 |
+
if (!response.ok) {
|
474 |
+
throw new Error('Network response was not ok');
|
475 |
+
}
|
476 |
|
477 |
+
const data = await response.json();
|
478 |
+
|
479 |
+
const img = new Image();
|
480 |
+
img.onload = () => {
|
481 |
+
loadingSpinner.style.display = 'none'; // Hide the loading spinner after the image is loaded
|
482 |
+
};
|
483 |
+
img.src = 'data:image/jpeg;base64,' + data.image_base64;
|
484 |
+
const maxWidth = 200;
|
485 |
+
const maxHeight = 200;
|
486 |
+
if (img.width > maxWidth || img.height > maxHeight) {
|
487 |
+
const ratio = Math.min(maxWidth / img.width, maxHeight / img.height);
|
488 |
+
img.width *= ratio;
|
489 |
+
img.height *= ratio;
|
490 |
}
|
491 |
+
resultContainer.innerHTML = ""; // Clear previous content
|
492 |
+
resultContainer.appendChild(img); // Append new image
|
493 |
+
} catch (error) {
|
494 |
+
console.error('Error:', error);
|
495 |
+
resultContainer.innerHTML = "<p>An error occurred. Please try again later.</p>";
|
496 |
+
loadingSpinner.style.display = 'none'; // Hide the loading spinner on error
|
497 |
}
|
498 |
+
}
|
499 |
+
|
500 |
|
501 |
|
502 |
|