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

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +34 -36
static/index.html CHANGED
@@ -448,52 +448,55 @@
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
 
@@ -503,11 +506,6 @@
503
 
504
 
505
 
506
-
507
-
508
-
509
-
510
-
511
  function toggleAdvancedOptions() {
512
  const advancedOptions = document.getElementById("advanced-options");
513
  if (advancedOptions.style.display === "none") {
 
448
 
449
 
450
 
451
+
452
+
 
 
 
 
 
453
 
 
 
454
 
455
+
456
+ async function sendInputs() {
457
+ const inputs = document.getElementById("inputs").value;
458
  const noiseLevel = document.getElementById("noise_level").value;
459
  const isNegative = document.getElementById("is_negative").value;
460
  const steps = document.getElementById("steps").value;
461
  const cfgScale = document.getElementById("cfg_scale").value;
462
  const seed = document.getElementById("seed").value;
463
 
464
+ // Check if the input field is empty
465
+ if (!inputs) {
466
+ document.getElementById('resultContainer').innerHTML = `<p style="color: white;">Please enter a prompt before sending.</p>`;
467
+ return;
468
+ }
469
 
470
  try {
471
+ // Clear the result container
472
+ document.getElementById('resultContainer').innerHTML = "";
473
 
474
+ // Display loading spinner
475
+ const loadingSpinner = document.getElementById('loadingSpinner');
476
+ loadingSpinner.style.display = 'block';
477
 
478
+ // Fetch data from the server
479
+ const response = await fetch(`/send_inputs?inputs=${encodeURIComponent(inputs)}&noise_level=${noiseLevel}&is_negative=${isNegative}&steps=${steps}&cfg_scale=${cfgScale}&seed=${seed}`);
480
+
481
+ // Check if the response is successful
482
+ if (response.ok) {
483
+ const resultContainer = document.getElementById('resultContainer');
484
+ const data = await response.json();
485
+ const img = document.createElement('img');
486
+ img.style.maxWidth = '100%'; // Adjust this value as needed
487
+ img.style.maxHeight = '100%'; // Adjust this value as needed
488
+ img.src = 'data:image/jpeg;base64,' + data.image_base64;
489
+ resultContainer.appendChild(img);
490
+ } else {
491
+ document.getElementById('resultContainer').innerHTML = `<p style="color: white;">Oops! Something went wrong. Please try again later.</p>`;
492
  }
 
 
493
  } catch (error) {
494
  console.error('Error:', error);
495
+ document.getElementById('resultContainer').innerHTML = `<p style="color: white;">Oops! Something went wrong. Please try again later.</p>`;
496
+ } finally {
497
+ // Hide loading spinner regardless of success or failure
498
+ const loadingSpinner = document.getElementById('loadingSpinner');
499
+ loadingSpinner.style.display = 'none';
500
  }
501
  }
502
 
 
506
 
507
 
508
 
 
 
 
 
 
509
  function toggleAdvancedOptions() {
510
  const advancedOptions = document.getElementById("advanced-options");
511
  if (advancedOptions.style.display === "none") {