]> git.cworth.org Git - zombocom-ai/blobdiff - index.html
Timeout on image generation after 60 seconds
[zombocom-ai] / index.html
index 2abf186d03a0a521509603b773b881a8e6d0b2ad..d055878d9cf0339d9bcf62bf55489a59314e4e9a 100644 (file)
@@ -5,7 +5,7 @@
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <title>ZOMBO</title>
   <link href="/zombo.css" rel="stylesheet" type="text/css">
-  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
+  <meta name="viewport" content="width=device-width,initial-scale=1">
   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
   <meta name="HandheldFriendly" content="true">
 </head>
     </div>
 
     <p>
-      Welcome to Zombocom. You can do anything at Zombcom, anything at
+      Welcome to Zombocom. You can do anything at Zombocom, anything at
       all. The only limit is yourself!
     </p>
 
     <p>
+      <div id="spinner" align="center">
+        <div class="animate-flicker">
+          <p>
+            <img src="/pngwheel.png" class="rotate thefade">
+          </p>
+        </div>
+      </div>
+
       <form action="" id="zombo-form">
         <div class="form-row large">
           <label for="prompt">
-            What do you imagine?
+            What can you imagine?
           </label>
-          <input id="prompt" autocomplete="off" required />
+          <button id="safety" type="button">Safety prompt</button>
+          <textarea id="prompt" rows="4" width="100%" autocomplete="off" required></textarea>
         </div>
 
         <div class="form-row small left">
-          <label for="code">
-            Numeric code
-          </label>
-          <input id="code" autocomplete="off" placeholder="(Chosen randomly)" />
-        </div>
-
-        <div class="form-row small right">
-          <button id="safety" type="button">Safety prompt</button>
-          <script>
-            const prompt = document.querySelector("#prompt");
-            const safety= document.querySelector("#safety");
-            // TODO: Dynamically generate many different prompts here
-            safety.addEventListener("click", () => {
-                prompt.value = "Matte painting of a Samurai warrior";
-                return false;
-            })
-          </script>
+          <div class="labeled-row">
+            <label for="code">
+              Numeric code:
+            </label>
+            <input id="code" type="text" autocomplete="off" placeholder="(Leave blank for random)" />
+          </div>
         </div>
 
         <div class="form-row large">
-          <button type="submit">Make the infinite possible</button>
+          <button id="generate" type="submit">Make the infinite possible</button>
         </div>
       </form>
     </p>
 
-    <div align="center">
-      <div class="animate-flicker">
-        <p>
-          <img src="/pngwheel.png" class="rotate thefade">
-        </p>
-      </div>
+    <div id="images">
     </div>
 
+    <ul id="comments">
+    </ul>
+
+    <p>
+      <form action="" id="comment-form">
+        <input id="comment" type="text" style="width:100%" autocomplete="off" placeholder="Add a comment" />
+      </form>
+    </p>
+
     <audio loop="" src="/zombo_words.mp3" type="audio/mpeg"></audio>
     <button id="mute" class="fade volume">
       <div>🔊</div>
@@ -95,5 +97,79 @@ mute.addEventListener("click", () => {
     </button>
 
   </div>
+
+  <script src="/socket.io/socket.io.js"></script>
+  <script>
+    var socket = io();
+
+    const images = document.querySelector("#images");
+
+    const comments = document.querySelector("#comments");
+    const comment_form = document.querySelector("#comment-form");
+    const comment = document.querySelector("#comment");
+
+    const zombo_form = document.querySelector("#zombo-form");
+    const prompt = document.querySelector("#prompt");
+    const code = document.querySelector("#code");
+
+    const safety= document.querySelector("#safety");
+
+    const spinner = document.querySelector("#spinner");
+    var spinner_timeout;
+
+    comment_form.addEventListener('submit', function(e) {
+        e.preventDefault();
+        if (comment.value) {
+            socket.emit('comment', comment.value);
+            comment.value = '';
+        }
+    });
+
+    socket.on('comment', function(msg) {
+        var item = document.createElement('li');
+        item.textContent = msg;
+        comments.appendChild(item);
+    });
+
+    socket.on('image', (image) => {
+        const figure = document.createElement('figure');
+        const img = document.createElement('img');
+        img.src = image.filename;
+        const figcaption = document.createElement('figcaption');
+        const caption_text = document.createTextNode(`${image.prompt} (${image.code})`);
+        figcaption.appendChild(caption_text);
+        figure.appendChild(img);
+        figure.appendChild(figcaption);
+        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. */
+        cancelTimeout(spinner_timeout);
+        hide_spinner();
+    });
+
+    // TODO: Dynamically generate many different prompts here
+    safety.addEventListener("click", () => {
+        prompt.value = "Matte painting of a Samurai warrior";
+        return false;
+    });
+
+  </script>
 </body>
 </html>