Raffael-Kultyshev commited on
Commit
31d34eb
·
1 Parent(s): eb39aa1

Add error handling for data loading and plot generation

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -251,7 +251,11 @@ def format_instruction_html(text: str) -> str:
251
 
252
  def build_interface():
253
  """Build Gradio interface."""
254
- metadata, end_effector, hands_2d = load_data()
 
 
 
 
255
 
256
  total_frames = len(metadata.get('poses', []))
257
  fps = metadata.get('fps', 60)
@@ -262,13 +266,23 @@ def build_interface():
262
 
263
  video_path = get_data_dir() / "video.mp4"
264
 
265
- # Build data for left hand
266
- left_timestamps, left_state = build_state_dataframe(metadata, end_effector, "left")
267
- left_figs = {metric: build_plot_html(left_timestamps, left_state, metric) for metric in METRIC_LABELS.keys()}
 
 
 
 
 
 
268
 
269
  # Build data for right hand
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
 
273
  stats_html = f"""
274
  <div class="stats-card">
 
251
 
252
  def build_interface():
253
  """Build Gradio interface."""
254
+ try:
255
+ metadata, end_effector, hands_2d = load_data()
256
+ except Exception as e:
257
+ print(f"Error loading data: {e}")
258
+ metadata, end_effector, hands_2d = {}, {}, {}
259
 
260
  total_frames = len(metadata.get('poses', []))
261
  fps = metadata.get('fps', 60)
 
266
 
267
  video_path = get_data_dir() / "video.mp4"
268
 
269
+ # Build data for left hand (lazy - only if needed)
270
+ left_figs = {}
271
+ right_figs = {}
272
+ try:
273
+ left_timestamps, left_state = build_state_dataframe(metadata, end_effector, "left")
274
+ left_figs = {metric: build_plot_html(left_timestamps, left_state, metric) for metric in METRIC_LABELS.keys()}
275
+ except Exception as e:
276
+ print(f"Error building left plots: {e}")
277
+ left_figs = {metric: "<p>Plot unavailable</p>" for metric in METRIC_LABELS.keys()}
278
 
279
  # Build data for right hand
280
+ try:
281
+ right_timestamps, right_state = build_state_dataframe(metadata, end_effector, "right")
282
+ right_figs = {metric: build_plot_html(right_timestamps, right_state, metric) for metric in METRIC_LABELS.keys()}
283
+ except Exception as e:
284
+ print(f"Error building right plots: {e}")
285
+ right_figs = {metric: "<p>Plot unavailable</p>" for metric in METRIC_LABELS.keys()}
286
 
287
  stats_html = f"""
288
  <div class="stats-card">