]> git.cworth.org Git - zombocom-ai/commitdiff
Timeout on image generation after 60 seconds
authorCarl Worth <cworth@cworth.org>
Thu, 8 Dec 2022 00:57:18 +0000 (16:57 -0800)
committerCarl Worth <cworth@cworth.org>
Thu, 8 Dec 2022 00:59:11 +0000 (16:59 -0800)
If the image doesn't come back, just hide the spinner and bring back
the form so they can try again.

index.html

index f88dd5bf6d15a320fec0cb3daa78773863a62d85..d055878d9cf0339d9bcf62bf55489a59314e4e9a 100644 (file)
@@ -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