Raffael-Kultyshev commited on
Commit
053e850
·
1 Parent(s): f85c4b8

Add error handling in build_interface

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -242,11 +242,15 @@ def format_instruction_html(text: str) -> str:
242
 
243
  def build_interface():
244
  """Build Gradio interface."""
245
- metadata, end_effector, hands_2d = load_data()
 
 
 
 
246
 
247
  total_frames = len(metadata.get('poses', []))
248
  fps = metadata.get('fps', 60)
249
- hand_detection_rate = len(hands_2d) / max(1, total_frames) * 100
250
 
251
  left_poses = sum(1 for f in end_effector.values() if f and isinstance(f, dict) and f.get('left_hand'))
252
  right_poses = sum(1 for f in end_effector.values() if f and isinstance(f, dict) and f.get('right_hand'))
@@ -254,12 +258,20 @@ def build_interface():
254
  video_path = DATA_DIR / "video.mp4"
255
 
256
  # Build data for left hand
257
- left_timestamps, left_state = build_state_dataframe(metadata, end_effector, "left")
258
- left_figs = {metric: build_plot_html(left_timestamps, left_state, metric) for metric in METRIC_LABELS.keys()}
 
 
 
 
259
 
260
  # Build data for right hand
261
- right_timestamps, right_state = build_state_dataframe(metadata, end_effector, "right")
262
- right_figs = {metric: build_plot_html(right_timestamps, right_state, metric) for metric in METRIC_LABELS.keys()}
 
 
 
 
263
 
264
  stats_html = f"""
265
  <div class="stats-card">
 
242
 
243
  def build_interface():
244
  """Build Gradio interface."""
245
+ try:
246
+ metadata, end_effector, hands_2d = load_data()
247
+ except Exception as e:
248
+ print(f"Error loading data: {e}")
249
+ metadata, end_effector, hands_2d = {}, {}, {}
250
 
251
  total_frames = len(metadata.get('poses', []))
252
  fps = metadata.get('fps', 60)
253
+ hand_detection_rate = len(hands_2d) / max(1, total_frames) * 100 if total_frames > 0 else 0
254
 
255
  left_poses = sum(1 for f in end_effector.values() if f and isinstance(f, dict) and f.get('left_hand'))
256
  right_poses = sum(1 for f in end_effector.values() if f and isinstance(f, dict) and f.get('right_hand'))
 
258
  video_path = DATA_DIR / "video.mp4"
259
 
260
  # Build data for left hand
261
+ try:
262
+ left_timestamps, left_state = build_state_dataframe(metadata, end_effector, "left")
263
+ left_figs = {metric: build_plot_html(left_timestamps, left_state, metric) for metric in METRIC_LABELS.keys()}
264
+ except Exception as e:
265
+ print(f"Error building left hand plots: {e}")
266
+ left_figs = {metric: "<p>Plot unavailable</p>" for metric in METRIC_LABELS.keys()}
267
 
268
  # Build data for right hand
269
+ try:
270
+ right_timestamps, right_state = build_state_dataframe(metadata, end_effector, "right")
271
+ right_figs = {metric: build_plot_html(right_timestamps, right_state, metric) for metric in METRIC_LABELS.keys()}
272
+ except Exception as e:
273
+ print(f"Error building right hand plots: {e}")
274
+ right_figs = {metric: "<p>Plot unavailable</p>" for metric in METRIC_LABELS.keys()}
275
 
276
  stats_html = f"""
277
  <div class="stats-card">