From: Carl Worth Date: Thu, 8 Dec 2022 00:57:18 +0000 (-0800) Subject: Timeout on image generation after 60 seconds X-Git-Url: https://git.cworth.org/git?p=zombocom-ai;a=commitdiff_plain;h=700362e55b2b60329b4d4cdd138865203093e720 Timeout on image generation after 60 seconds If the image doesn't come back, just hide the spinner and bring back the form so they can try again. --- diff --git a/index.html b/index.html index f88dd5b..d055878 100644 --- a/index.html +++ b/index.html @@ -115,6 +115,7 @@ mute.addEventListener("click", () => { const safety= document.querySelector("#safety"); const spinner = document.querySelector("#spinner"); + var spinner_timeout; comment_form.addEventListener('submit', function(e) { e.preventDefault(); @@ -142,19 +143,25 @@ mute.addEventListener("click", () => { images.prepend(figure); }); + function hide_spinner() { + zombo_form.style.display = "grid"; + spinner.style.display = "none"; + } + zombo_form.addEventListener('submit', function(e) { e.preventDefault(); /* Hide the form and show spinner while generation is happening. */ zombo_form.style.display = "none"; spinner.style.display = "block"; + spinner_timeout = setTimeout(hide_spinner, 60000); socket.emit('generate', {"prompt": prompt.value, "code": code.value}); prompt.value = ''; }); socket.on('generation-done', () => { /* Re-display the form and hide spinner now that generation is over. */ - zombo_form.style.display = "grid"; - spinner.style.display = "none"; + cancelTimeout(spinner_timeout); + hide_spinner(); }); // TODO: Dynamically generate many different prompts here