Anthony Liang commited on
Commit
a326636
·
1 Parent(s): cc5bab9
Files changed (2) hide show
  1. app.py +3 -24
  2. eval_utils.py +19 -2
app.py CHANGED
@@ -368,9 +368,9 @@ def process_single_video(
368
 
369
  # Build payload and send to server
370
  files, sample_data = build_payload([progress_sample])
371
- # Add use_frame_steps flag to sample_data
372
- sample_data["use_frame_steps"] = use_frame_steps
373
- response = post_batch_npy(server_url, files, sample_data, timeout_s=120.0)
374
 
375
  # Process response
376
  outputs_progress = response.get("outputs_progress", {})
@@ -431,7 +431,6 @@ def process_two_videos(
431
  prediction_type: str = "preference",
432
  server_url: str = "",
433
  fps: float = 1.0,
434
- use_frame_steps: bool = False,
435
  ) -> Tuple[Optional[str], Optional[str], Optional[str]]:
436
  """Process two videos for preference, similarity, or progress prediction using eval server."""
437
  # Get server URL from state if not provided
@@ -529,8 +528,6 @@ def process_two_videos(
529
 
530
  # Build payload and send to server
531
  files, sample_data = build_payload([progress_sample_a, progress_sample_b])
532
- # Add use_frame_steps flag to sample_data
533
- sample_data["use_frame_steps"] = use_frame_steps
534
  response = post_batch_npy(server_url, files, sample_data, timeout_s=120.0)
535
 
536
  # Process response
@@ -1048,12 +1045,6 @@ with demo:
1048
  step=0.1,
1049
  info="Frames per second to extract from videos (higher = more frames)",
1050
  )
1051
- use_frame_steps_dual = gr.Checkbox(
1052
- label="Use Frame Steps",
1053
- value=False,
1054
- info="Process frames incrementally for progress predictions",
1055
- visible=False, # Only visible for progress mode
1056
- )
1057
  analyze_dual_btn = gr.Button("Compare Videos", variant="primary")
1058
 
1059
  gr.Markdown("---")
@@ -1121,17 +1112,6 @@ with demo:
1121
  current_dataset_a = gr.State(None)
1122
  current_dataset_b = gr.State(None)
1123
 
1124
- # Show/hide frame steps checkbox based on prediction type
1125
- def update_frame_steps_visibility(pred_type):
1126
- """Show frame steps checkbox only for progress mode."""
1127
- return gr.update(visible=(pred_type == "progress"))
1128
-
1129
- prediction_type.change(
1130
- fn=update_frame_steps_visibility,
1131
- inputs=[prediction_type],
1132
- outputs=[use_frame_steps_dual],
1133
- )
1134
-
1135
  # Helper functions for Video A
1136
  def update_config_choices_a(dataset_name):
1137
  """Update config choices for Video A when dataset changes."""
@@ -1521,7 +1501,6 @@ with demo:
1521
  prediction_type,
1522
  server_url_state,
1523
  fps_input_dual,
1524
- use_frame_steps_dual,
1525
  ],
1526
  outputs=[result_text, video_a_display, video_b_display],
1527
  api_name="process_two_videos",
 
368
 
369
  # Build payload and send to server
370
  files, sample_data = build_payload([progress_sample])
371
+ # Add use_frame_steps flag as extra form data
372
+ extra_data = {"use_frame_steps": use_frame_steps} if use_frame_steps else None
373
+ response = post_batch_npy(server_url, files, sample_data, timeout_s=120.0, extra_form_data=extra_data)
374
 
375
  # Process response
376
  outputs_progress = response.get("outputs_progress", {})
 
431
  prediction_type: str = "preference",
432
  server_url: str = "",
433
  fps: float = 1.0,
 
434
  ) -> Tuple[Optional[str], Optional[str], Optional[str]]:
435
  """Process two videos for preference, similarity, or progress prediction using eval server."""
436
  # Get server URL from state if not provided
 
528
 
529
  # Build payload and send to server
530
  files, sample_data = build_payload([progress_sample_a, progress_sample_b])
 
 
531
  response = post_batch_npy(server_url, files, sample_data, timeout_s=120.0)
532
 
533
  # Process response
 
1045
  step=0.1,
1046
  info="Frames per second to extract from videos (higher = more frames)",
1047
  )
 
 
 
 
 
 
1048
  analyze_dual_btn = gr.Button("Compare Videos", variant="primary")
1049
 
1050
  gr.Markdown("---")
 
1112
  current_dataset_a = gr.State(None)
1113
  current_dataset_b = gr.State(None)
1114
 
 
 
 
 
 
 
 
 
 
 
 
1115
  # Helper functions for Video A
1116
  def update_config_choices_a(dataset_name):
1117
  """Update config choices for Video A when dataset changes."""
 
1501
  prediction_type,
1502
  server_url_state,
1503
  fps_input_dual,
 
1504
  ],
1505
  outputs=[result_text, video_a_display, video_b_display],
1506
  api_name="process_two_videos",
eval_utils.py CHANGED
@@ -280,11 +280,28 @@ def post_batch(url: str, payload: dict[str, Any], timeout_s: float = 120.0) -> d
280
 
281
 
282
  def post_batch_npy(
283
- url: str, files: dict[str, Any], sample_data: list[dict[str, Any]], timeout_s: float = 120.0
 
 
 
 
284
  ) -> dict[str, Any]:
285
- """POST batch using .npy format for numpy arrays."""
 
 
 
 
 
 
 
 
286
  # Convert sample_data to form data
287
  data = {f"sample_{i}": json.dumps(sample) for i, sample in enumerate(sample_data)}
 
 
 
 
 
288
 
289
  # Send as multipart form data
290
  resp = requests.post(url.rstrip("/") + "/evaluate_batch_npy", files=files, data=data, timeout=timeout_s)
 
280
 
281
 
282
  def post_batch_npy(
283
+ url: str,
284
+ files: dict[str, Any],
285
+ sample_data: list[dict[str, Any]],
286
+ timeout_s: float = 120.0,
287
+ extra_form_data: Optional[dict[str, Any]] = None,
288
  ) -> dict[str, Any]:
289
+ """POST batch using .npy format for numpy arrays.
290
+
291
+ Args:
292
+ url: Server URL
293
+ files: Dict of numpy arrays converted to .npy format
294
+ sample_data: List of sample dictionaries
295
+ timeout_s: Request timeout in seconds
296
+ extra_form_data: Optional extra form data to include (e.g., use_frame_steps)
297
+ """
298
  # Convert sample_data to form data
299
  data = {f"sample_{i}": json.dumps(sample) for i, sample in enumerate(sample_data)}
300
+
301
+ # Add extra form data if provided
302
+ if extra_form_data:
303
+ for key, value in extra_form_data.items():
304
+ data[key] = json.dumps(value) if not isinstance(value, str) else value
305
 
306
  # Send as multipart form data
307
  resp = requests.post(url.rstrip("/") + "/evaluate_batch_npy", files=files, data=data, timeout=timeout_s)