Spaces:
Runtime error
Runtime error
da03
commited on
Commit
·
9766588
1
Parent(s):
274b099
- main.py +26 -1
- static/index.html +53 -2
main.py
CHANGED
@@ -166,7 +166,7 @@ def _process_frame_sync(model, inputs):
|
|
166 |
# UNet sampling
|
167 |
start = time.perf_counter()
|
168 |
use_rnn = False
|
169 |
-
print (f"use_rnn: {use_rnn}")
|
170 |
if use_rnn:
|
171 |
sample_latent = output_from_rnn[:, :16]
|
172 |
else:
|
@@ -259,6 +259,25 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
259 |
# Send confirmation to client
|
260 |
await websocket.send_json({"type": "reset_confirmed"})
|
261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
async def process_input(data):
|
263 |
nonlocal previous_frame, hidden_states, keys_down, frame_num, frame_count, is_processing
|
264 |
|
@@ -407,6 +426,12 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
407 |
await reset_simulation()
|
408 |
continue
|
409 |
|
|
|
|
|
|
|
|
|
|
|
|
|
410 |
# Add the input to our queue
|
411 |
await input_queue.put(data)
|
412 |
print(f"[{receive_time:.3f}] Received input. Queue size now: {input_queue.qsize()}")
|
|
|
166 |
# UNet sampling
|
167 |
start = time.perf_counter()
|
168 |
use_rnn = False
|
169 |
+
print (f"use_rnn: {use_rnn}, NUM_SAMPLING_STEPS: {NUM_SAMPLING_STEPS}")
|
170 |
if use_rnn:
|
171 |
sample_latent = output_from_rnn[:, :16]
|
172 |
else:
|
|
|
259 |
# Send confirmation to client
|
260 |
await websocket.send_json({"type": "reset_confirmed"})
|
261 |
|
262 |
+
# Add a function to update sampling steps
|
263 |
+
async def update_sampling_steps(steps):
|
264 |
+
global NUM_SAMPLING_STEPS
|
265 |
+
|
266 |
+
# Validate the input
|
267 |
+
if steps < 1:
|
268 |
+
print(f"[{time.perf_counter():.3f}] Invalid sampling steps value: {steps}")
|
269 |
+
await websocket.send_json({"type": "error", "message": "Invalid sampling steps value"})
|
270 |
+
return
|
271 |
+
|
272 |
+
# Update the global variable
|
273 |
+
old_steps = NUM_SAMPLING_STEPS
|
274 |
+
NUM_SAMPLING_STEPS = steps
|
275 |
+
|
276 |
+
print(f"[{time.perf_counter():.3f}] Updated NUM_SAMPLING_STEPS from {old_steps} to {steps}")
|
277 |
+
|
278 |
+
# Send confirmation to client
|
279 |
+
await websocket.send_json({"type": "steps_updated", "steps": steps})
|
280 |
+
|
281 |
async def process_input(data):
|
282 |
nonlocal previous_frame, hidden_states, keys_down, frame_num, frame_count, is_processing
|
283 |
|
|
|
426 |
await reset_simulation()
|
427 |
continue
|
428 |
|
429 |
+
# Handle sampling steps update
|
430 |
+
if data.get("type") == "update_sampling_steps":
|
431 |
+
print(f"[{receive_time:.3f}] Received request to update sampling steps")
|
432 |
+
await update_sampling_steps(data.get("steps", 32))
|
433 |
+
continue
|
434 |
+
|
435 |
# Add the input to our queue
|
436 |
await input_queue.put(data)
|
437 |
print(f"[{receive_time:.3f}] Received input. Queue size now: {input_queue.qsize()}")
|
static/index.html
CHANGED
@@ -9,13 +9,43 @@
|
|
9 |
#displayCanvas {
|
10 |
cursor: none;
|
11 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
</style>
|
13 |
</head>
|
14 |
<body>
|
15 |
<canvas id="displayCanvas" width="512" height="384"></canvas>
|
16 |
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
<script>
|
21 |
const canvas = document.getElementById('displayCanvas');
|
@@ -230,6 +260,27 @@
|
|
230 |
console.error("WebSocket not connected, cannot reset");
|
231 |
}
|
232 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
</script>
|
234 |
</body>
|
235 |
</html>
|
|
|
9 |
#displayCanvas {
|
10 |
cursor: none;
|
11 |
}
|
12 |
+
|
13 |
+
/* Add some styling for the controls */
|
14 |
+
.controls {
|
15 |
+
margin-top: 10px;
|
16 |
+
display: flex;
|
17 |
+
gap: 10px;
|
18 |
+
align-items: center;
|
19 |
+
}
|
20 |
+
|
21 |
+
.control-button {
|
22 |
+
padding: 5px 10px;
|
23 |
+
cursor: pointer;
|
24 |
+
}
|
25 |
+
|
26 |
+
.step-control {
|
27 |
+
display: flex;
|
28 |
+
align-items: center;
|
29 |
+
gap: 5px;
|
30 |
+
}
|
31 |
+
|
32 |
+
#samplingSteps {
|
33 |
+
width: 60px;
|
34 |
+
}
|
35 |
</style>
|
36 |
</head>
|
37 |
<body>
|
38 |
<canvas id="displayCanvas" width="512" height="384"></canvas>
|
39 |
|
40 |
+
<div class="controls">
|
41 |
+
<button id="resetButton" class="control-button">Reset Simulation</button>
|
42 |
+
|
43 |
+
<div class="step-control">
|
44 |
+
<label for="samplingSteps">Sampling Steps:</label>
|
45 |
+
<input type="number" id="samplingSteps" min="1" max="100" value="32">
|
46 |
+
<button id="updateStepsButton" class="control-button">Update</button>
|
47 |
+
</div>
|
48 |
+
</div>
|
49 |
|
50 |
<script>
|
51 |
const canvas = document.getElementById('displayCanvas');
|
|
|
260 |
console.error("WebSocket not connected, cannot reset");
|
261 |
}
|
262 |
});
|
263 |
+
|
264 |
+
// Add event listener for updating sampling steps
|
265 |
+
document.getElementById('updateStepsButton').addEventListener('click', function() {
|
266 |
+
const stepsInput = document.getElementById('samplingSteps');
|
267 |
+
const newSteps = parseInt(stepsInput.value, 10);
|
268 |
+
|
269 |
+
if (isNaN(newSteps) || newSteps < 1) {
|
270 |
+
alert("Please enter a valid number of steps (minimum 1)");
|
271 |
+
return;
|
272 |
+
}
|
273 |
+
|
274 |
+
if (socket && socket.readyState === WebSocket.OPEN) {
|
275 |
+
console.log(`Sending update to set sampling steps to ${newSteps}`);
|
276 |
+
socket.send(JSON.stringify({
|
277 |
+
type: "update_sampling_steps",
|
278 |
+
steps: newSteps
|
279 |
+
}));
|
280 |
+
} else {
|
281 |
+
console.error("WebSocket not connected, cannot update steps");
|
282 |
+
}
|
283 |
+
});
|
284 |
</script>
|
285 |
</body>
|
286 |
</html>
|