da03 commited on
Commit
eb2c07e
·
1 Parent(s): fcc268a
Files changed (1) hide show
  1. main.py +11 -1
main.py CHANGED
@@ -141,7 +141,13 @@ def process_frame(
141
 
142
  return sample_latent, sample_img, hidden_states, timing
143
 
144
-
 
 
 
 
 
 
145
  # Serve the index.html file at the root URL
146
  @app.get("/")
147
  async def get():
@@ -185,6 +191,10 @@ async def websocket_endpoint(websocket: WebSocket):
185
  inputs = prepare_model_inputs(previous_frame, hidden_states, x, y, is_right_click, is_left_click, list(keys_down), stoi, itos, frame_num)
186
  previous_frame, sample_img, hidden_states, timing_info = process_frame(model, inputs)
187
  timing_info['full_frame'] = time.perf_counter() - start_frame
 
 
 
 
188
  img = Image.fromarray(sample_img)
189
  buffered = io.BytesIO()
190
  img.save(buffered, format="PNG")
 
141
 
142
  return sample_latent, sample_img, hidden_states, timing
143
 
144
+ def print_timing_stats(timing_info: Dict[str, float], frame_num: int):
145
+ """Print timing statistics for a frame."""
146
+ print(f"\nFrame {frame_num} timing (seconds):")
147
+ for key, value in timing_info.items():
148
+ print(f" {key.title()}: {value:.4f}")
149
+ print(f" FPS: {1.0/timing_info['total']:.2f}")
150
+
151
  # Serve the index.html file at the root URL
152
  @app.get("/")
153
  async def get():
 
191
  inputs = prepare_model_inputs(previous_frame, hidden_states, x, y, is_right_click, is_left_click, list(keys_down), stoi, itos, frame_num)
192
  previous_frame, sample_img, hidden_states, timing_info = process_frame(model, inputs)
193
  timing_info['full_frame'] = time.perf_counter() - start_frame
194
+
195
+ # Use the provided function to print timing statistics
196
+ print_timing_stats(timing_info, frame_num)
197
+
198
  img = Image.fromarray(sample_img)
199
  buffered = io.BytesIO()
200
  img.save(buffered, format="PNG")