Spaces:
Runtime error
Runtime error
da03
commited on
Commit
·
facfd46
1
Parent(s):
4c59739
- main.py +19 -1
- static/index.html +25 -0
main.py
CHANGED
|
@@ -29,7 +29,6 @@ NUM_MAX_FRAMES = 1
|
|
| 29 |
SCREEN_WIDTH = 512
|
| 30 |
SCREEN_HEIGHT = 384
|
| 31 |
NUM_SAMPLING_STEPS = 32
|
| 32 |
-
USE_RNN = True
|
| 33 |
USE_RNN = False
|
| 34 |
|
| 35 |
MODEL_NAME = "yuntian-deng/computer-model-ss005-cont-lr2e5-384k"
|
|
@@ -313,6 +312,19 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
| 313 |
# Send confirmation to client
|
| 314 |
await websocket.send_json({"type": "steps_updated", "steps": steps})
|
| 315 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
async def process_input(data):
|
| 317 |
nonlocal previous_frame, hidden_states, keys_down, frame_num, frame_count, is_processing
|
| 318 |
|
|
@@ -475,6 +487,12 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
| 475 |
await update_sampling_steps(data.get("steps", 32))
|
| 476 |
continue
|
| 477 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
# Add the input to our queue
|
| 479 |
await input_queue.put(data)
|
| 480 |
print(f"[{receive_time:.3f}] Received input. Queue size now: {input_queue.qsize()}")
|
|
|
|
| 29 |
SCREEN_WIDTH = 512
|
| 30 |
SCREEN_HEIGHT = 384
|
| 31 |
NUM_SAMPLING_STEPS = 32
|
|
|
|
| 32 |
USE_RNN = False
|
| 33 |
|
| 34 |
MODEL_NAME = "yuntian-deng/computer-model-ss005-cont-lr2e5-384k"
|
|
|
|
| 312 |
# Send confirmation to client
|
| 313 |
await websocket.send_json({"type": "steps_updated", "steps": steps})
|
| 314 |
|
| 315 |
+
# Add a function to update USE_RNN setting
|
| 316 |
+
async def update_use_rnn(use_rnn):
|
| 317 |
+
global USE_RNN
|
| 318 |
+
|
| 319 |
+
# Update the global variable
|
| 320 |
+
old_setting = USE_RNN
|
| 321 |
+
USE_RNN = use_rnn
|
| 322 |
+
|
| 323 |
+
print(f"[{time.perf_counter():.3f}] Updated USE_RNN from {old_setting} to {use_rnn}")
|
| 324 |
+
|
| 325 |
+
# Send confirmation to client
|
| 326 |
+
await websocket.send_json({"type": "rnn_updated", "use_rnn": use_rnn})
|
| 327 |
+
|
| 328 |
async def process_input(data):
|
| 329 |
nonlocal previous_frame, hidden_states, keys_down, frame_num, frame_count, is_processing
|
| 330 |
|
|
|
|
| 487 |
await update_sampling_steps(data.get("steps", 32))
|
| 488 |
continue
|
| 489 |
|
| 490 |
+
# Handle USE_RNN update
|
| 491 |
+
if data.get("type") == "update_use_rnn":
|
| 492 |
+
print(f"[{receive_time:.3f}] Received request to update USE_RNN")
|
| 493 |
+
await update_use_rnn(data.get("use_rnn", False))
|
| 494 |
+
continue
|
| 495 |
+
|
| 496 |
# Add the input to our queue
|
| 497 |
await input_queue.put(data)
|
| 498 |
print(f"[{receive_time:.3f}] Received input. Queue size now: {input_queue.qsize()}")
|
static/index.html
CHANGED
|
@@ -104,6 +104,11 @@
|
|
| 104 |
<input type="number" id="samplingSteps" class="form-control" min="1" max="100" value="32">
|
| 105 |
<button id="updateStepsButton" class="btn btn-secondary control-button">Update</button>
|
| 106 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
</div>
|
| 108 |
</div>
|
| 109 |
|
|
@@ -118,6 +123,7 @@
|
|
| 118 |
<li>Right-click to perform context menu actions</li>
|
| 119 |
<li>Use your keyboard to type within the simulated environment</li>
|
| 120 |
<li>Adjust sampling steps to control quality/speed tradeoff</li>
|
|
|
|
| 121 |
</ul>
|
| 122 |
</div>
|
| 123 |
</div>
|
|
@@ -188,6 +194,10 @@
|
|
| 188 |
console.log("Simulation reset confirmed by server");
|
| 189 |
// Clear the canvas and reset to initial state
|
| 190 |
drawInitialCanvas();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
}
|
| 192 |
};
|
| 193 |
}
|
|
@@ -375,6 +385,21 @@
|
|
| 375 |
console.error("WebSocket not connected, cannot update steps");
|
| 376 |
}
|
| 377 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
</script>
|
| 379 |
|
| 380 |
<!-- Bootstrap JS (optional) -->
|
|
|
|
| 104 |
<input type="number" id="samplingSteps" class="form-control" min="1" max="100" value="32">
|
| 105 |
<button id="updateStepsButton" class="btn btn-secondary control-button">Update</button>
|
| 106 |
</div>
|
| 107 |
+
|
| 108 |
+
<div class="form-check form-switch">
|
| 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 |
|
|
|
|
| 123 |
<li>Right-click to perform context menu actions</li>
|
| 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>
|
|
|
|
| 194 |
console.log("Simulation reset confirmed by server");
|
| 195 |
// Clear the canvas and reset to initial state
|
| 196 |
drawInitialCanvas();
|
| 197 |
+
} else if (data.type === "rnn_updated") {
|
| 198 |
+
console.log(`USE_RNN setting updated to: ${data.use_rnn}`);
|
| 199 |
+
// Update the toggle to match the server state
|
| 200 |
+
document.getElementById('useRnnToggle').checked = data.use_rnn;
|
| 201 |
}
|
| 202 |
};
|
| 203 |
}
|
|
|
|
| 385 |
console.error("WebSocket not connected, cannot update steps");
|
| 386 |
}
|
| 387 |
});
|
| 388 |
+
|
| 389 |
+
// Add event listener for the USE_RNN toggle
|
| 390 |
+
document.getElementById('useRnnToggle').addEventListener('change', function() {
|
| 391 |
+
const useRnn = this.checked;
|
| 392 |
+
|
| 393 |
+
if (socket && socket.readyState === WebSocket.OPEN) {
|
| 394 |
+
console.log(`Sending update to set USE_RNN to ${useRnn}`);
|
| 395 |
+
socket.send(JSON.stringify({
|
| 396 |
+
type: "update_use_rnn",
|
| 397 |
+
use_rnn: useRnn
|
| 398 |
+
}));
|
| 399 |
+
} else {
|
| 400 |
+
console.error("WebSocket not connected, cannot update USE_RNN");
|
| 401 |
+
}
|
| 402 |
+
});
|
| 403 |
</script>
|
| 404 |
|
| 405 |
<!-- Bootstrap JS (optional) -->
|