Ashrafb commited on
Commit
0e1c0be
1 Parent(s): 1ba0b41

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +37 -29
static/index.html CHANGED
@@ -448,47 +448,55 @@
448
 
449
 
450
 
451
- async function sendInputs() {
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
- resultContainer.innerHTML = `<p style="color: white;">Please enter a prompt before sending.</p>`;
 
463
  return;
464
  }
465
 
466
- // Clear the result container
467
- resultContainer.innerHTML = "";
468
-
469
- // Display loading spinner
470
  const loadingSpinner = document.getElementById('loadingSpinner');
471
- showSpinner('loadingSpinner');
472
- try {
473
- const response = await fetch(`/send_inputs?inputs=${encodeURIComponent(inputs)}&noise_level=${noiseLevel}&is_negative=${isNegative}&steps=${steps}&cfg_scale=${cfgScale}&seed=${seed}`);
 
 
 
 
474
 
475
- if (!response.ok) {
476
- throw new Error('Network response was not ok');
477
- }
478
 
479
- const data = await response.json();
 
480
 
481
- // Hide loading spinner
482
- hideSpinner('loadingSpinner');
 
483
 
484
- // Display the result image
485
- const resultImage = document.getElementById('resultContainer');
486
- resultImage.innerHTML = `<img src="${data.image_url}" alt="Generated Image">`;
487
- } catch (error) {
488
- console.error('Error:', error);
489
- resultContainer.innerHTML = `<p style="color: white;">Oops! Something went wrong. Please try again later.</p>`;
 
 
 
 
 
 
 
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