da03 commited on
Commit
a899811
·
1 Parent(s): 04846cf
Files changed (2) hide show
  1. main.py +2 -1
  2. static/index.html +70 -0
main.py CHANGED
@@ -628,7 +628,8 @@ def log_interaction(client_id, data, generated_frame=None, is_end_of_session=Fal
628
  "is_left_click": data.get("is_left_click"),
629
  "is_right_click": data.get("is_right_click"),
630
  "keys_down": data.get("keys_down", []),
631
- "keys_up": data.get("keys_up", [])
 
632
  }
633
  else:
634
  # For EOS/reset records, just include minimal info
 
628
  "is_left_click": data.get("is_left_click"),
629
  "is_right_click": data.get("is_right_click"),
630
  "keys_down": data.get("keys_down", []),
631
+ "keys_up": data.get("keys_up", []),
632
+ "is_auto_input": data.get("is_auto_input", False)
633
  }
634
  else:
635
  # For EOS/reset records, just include minimal info
static/index.html CHANGED
@@ -109,6 +109,11 @@
109
  <input class="form-check-input" type="checkbox" role="switch" id="useRnnToggle">
110
  <label class="form-check-label" for="useRnnToggle">Use RNN</label>
111
  </div>
 
 
 
 
 
112
  </div>
113
  </div>
114
 
@@ -124,6 +129,7 @@
124
  <li>Use your keyboard to type within the simulated environment</li>
125
  <li>Adjust sampling steps to control quality/speed tradeoff</li>
126
  <li>Toggle "Use RNN" to switch between RNN and diffusion mode</li>
 
127
  </ul>
128
  </div>
129
  </div>
@@ -165,6 +171,9 @@
165
  isConnected = true;
166
  reconnectAttempts = 0;
167
 
 
 
 
168
  // Request current settings from server to sync UI
169
  socket.send(JSON.stringify({
170
  type: "get_settings"
@@ -176,6 +185,7 @@
176
  socket.onclose = function(event) {
177
  console.log("WebSocket connection closed. Attempting to reconnect...");
178
  isConnected = false;
 
179
  clearInterval(heartbeatInterval);
180
  scheduleReconnection();
181
  };
@@ -245,9 +255,53 @@
245
  let lastSentTime = 0;
246
  const SEND_INTERVAL = 10; // Send updates every 50ms
247
 
 
 
 
 
 
 
248
  // Track currently pressed keys
249
  const pressedKeys = new Set();
250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  function sendInputState(x, y, isLeftClick = false, isRightClick = false) {
252
  const currentTime = Date.now();
253
  if (isConnected && (isLeftClick || isRightClick || !lastSentPosition || currentTime - lastSentTime >= SEND_INTERVAL)) {
@@ -263,6 +317,9 @@
263
  lastSentPosition = { x, y };
264
  lastSentTime = currentTime;
265
 
 
 
 
266
  //if (isLeftClick || isRightClick) {
267
  // isProcessing = true; // Block further inputs until response
268
  //}
@@ -347,6 +404,7 @@
347
  "keys_down": Array.from(pressedKeys),
348
  "keys_up": [event.key],
349
  }));
 
350
  } catch (error) {
351
  console.error("Error sending key up event:", error);
352
  }
@@ -354,6 +412,7 @@
354
 
355
  // Graceful disconnection
356
  window.addEventListener('beforeunload', function (e) {
 
357
  if (isConnected) {
358
  try {
359
  //socket.send(JSON.stringify({ type: "disconnect" }));
@@ -411,6 +470,17 @@
411
  console.error("WebSocket not connected, cannot update USE_RNN");
412
  }
413
  });
 
 
 
 
 
 
 
 
 
 
 
414
  </script>
415
 
416
  <!-- Bootstrap JS (optional) -->
 
109
  <input class="form-check-input" type="checkbox" role="switch" id="useRnnToggle">
110
  <label class="form-check-label" for="useRnnToggle">Use RNN</label>
111
  </div>
112
+
113
+ <div class="form-check form-switch">
114
+ <input class="form-check-input" type="checkbox" role="switch" id="autoInputToggle" checked>
115
+ <label class="form-check-label" for="autoInputToggle">Auto Input</label>
116
+ </div>
117
  </div>
118
  </div>
119
 
 
129
  <li>Use your keyboard to type within the simulated environment</li>
130
  <li>Adjust sampling steps to control quality/speed tradeoff</li>
131
  <li>Toggle "Use RNN" to switch between RNN and diffusion mode</li>
132
+ <li>Toggle "Auto Input" to enable/disable automatic frame generation during idle periods</li>
133
  </ul>
134
  </div>
135
  </div>
 
171
  isConnected = true;
172
  reconnectAttempts = 0;
173
 
174
+ // Start auto-input mechanism
175
+ startAutoInput();
176
+
177
  // Request current settings from server to sync UI
178
  socket.send(JSON.stringify({
179
  type: "get_settings"
 
185
  socket.onclose = function(event) {
186
  console.log("WebSocket connection closed. Attempting to reconnect...");
187
  isConnected = false;
188
+ stopAutoInput(); // Stop auto-input when connection is lost
189
  clearInterval(heartbeatInterval);
190
  scheduleReconnection();
191
  };
 
255
  let lastSentTime = 0;
256
  const SEND_INTERVAL = 10; // Send updates every 50ms
257
 
258
+ // Auto-input mechanism
259
+ let lastUserInputTime = 0;
260
+ let autoInputInterval = null;
261
+ const AUTO_INPUT_DELAY = 1000; // Send auto-input after 1 second of no user input
262
+ let autoInputEnabled = true; // Default to enabled
263
+
264
  // Track currently pressed keys
265
  const pressedKeys = new Set();
266
 
267
+ function startAutoInput() {
268
+ if (autoInputInterval) {
269
+ clearInterval(autoInputInterval);
270
+ }
271
+
272
+ autoInputInterval = setInterval(() => {
273
+ const currentTime = Date.now();
274
+ if (autoInputEnabled && currentTime - lastUserInputTime >= AUTO_INPUT_DELAY && lastSentPosition && isConnected) {
275
+ console.log("Sending auto-input (no user activity for 1 second)");
276
+ try {
277
+ socket.send(JSON.stringify({
278
+ "x": lastSentPosition.x,
279
+ "y": lastSentPosition.y,
280
+ "is_left_click": false,
281
+ "is_right_click": false,
282
+ "keys_down": [],
283
+ "keys_up": [],
284
+ "is_auto_input": true // Flag to identify auto-generated inputs
285
+ }));
286
+ updateLastUserInputTime();
287
+ } catch (error) {
288
+ console.error("Error sending auto-input:", error);
289
+ }
290
+ }
291
+ }, 100); // Check every 100ms
292
+ }
293
+
294
+ function stopAutoInput() {
295
+ if (autoInputInterval) {
296
+ clearInterval(autoInputInterval);
297
+ autoInputInterval = null;
298
+ }
299
+ }
300
+
301
+ function updateLastUserInputTime() {
302
+ lastUserInputTime = Date.now();
303
+ }
304
+
305
  function sendInputState(x, y, isLeftClick = false, isRightClick = false) {
306
  const currentTime = Date.now();
307
  if (isConnected && (isLeftClick || isRightClick || !lastSentPosition || currentTime - lastSentTime >= SEND_INTERVAL)) {
 
317
  lastSentPosition = { x, y };
318
  lastSentTime = currentTime;
319
 
320
+ // Update last user input time for auto-input mechanism
321
+ updateLastUserInputTime();
322
+
323
  //if (isLeftClick || isRightClick) {
324
  // isProcessing = true; // Block further inputs until response
325
  //}
 
404
  "keys_down": Array.from(pressedKeys),
405
  "keys_up": [event.key],
406
  }));
407
+ updateLastUserInputTime(); // Update for auto-input mechanism
408
  } catch (error) {
409
  console.error("Error sending key up event:", error);
410
  }
 
412
 
413
  // Graceful disconnection
414
  window.addEventListener('beforeunload', function (e) {
415
+ stopAutoInput(); // Clean up auto-input interval
416
  if (isConnected) {
417
  try {
418
  //socket.send(JSON.stringify({ type: "disconnect" }));
 
470
  console.error("WebSocket not connected, cannot update USE_RNN");
471
  }
472
  });
473
+
474
+ // Add event listener for the auto-input toggle
475
+ document.getElementById('autoInputToggle').addEventListener('change', function() {
476
+ autoInputEnabled = this.checked;
477
+ console.log(`Auto-input ${autoInputEnabled ? 'enabled' : 'disabled'}`);
478
+
479
+ if (autoInputEnabled) {
480
+ // Reset the timer when enabling
481
+ updateLastUserInputTime();
482
+ }
483
+ });
484
  </script>
485
 
486
  <!-- Bootstrap JS (optional) -->