aliangdw commited on
Commit
51c7ccb
·
1 Parent(s): 38610d6
Files changed (1) hide show
  1. app.py +42 -15
app.py CHANGED
@@ -50,16 +50,14 @@ def visualize_trajectory(dataset, index):
50
  metadata = f"""
51
  ## Trajectory Information
52
 
53
- **Task:** {task}
54
 
55
- **Optimality:** {optimal}
56
 
57
- **Data Type:** {'🤖 Robot' if is_robot else '👤 Human'}
58
 
59
  **Source:** {data_source}
60
-
61
- **Frames:** {frames_info}
62
-
63
  **Trajectory ID:** {item.get('id', 'N/A')}
64
  """
65
 
@@ -116,13 +114,14 @@ with gr.Blocks(title="RFM Dataset Visualizer") as demo:
116
  prev_btn = gr.Button("⬅️ Previous", variant="secondary")
117
 
118
  with gr.Column(scale=2):
119
- # Slider for navigation
120
  slider = gr.Slider(
121
  minimum=0,
122
- maximum=100, # Will be updated when dataset loads
123
  step=1,
124
  value=0,
125
- label="Trajectory Index"
 
126
  )
127
 
128
  with gr.Column(scale=1):
@@ -141,7 +140,7 @@ with gr.Blocks(title="RFM Dataset Visualizer") as demo:
141
  if dataset is not None:
142
  max_index = len(dataset) - 1
143
  info = f"**Dataset Info:**\n- **Total Trajectories:** {len(dataset)}\n- **Features:** {list(dataset.features.keys())}"
144
- # Return the dataset length for slider configuration
145
  return dataset, status, info, 0, max_index
146
  else:
147
  return None, status, "", 0, 0
@@ -150,12 +149,14 @@ with gr.Blocks(title="RFM Dataset Visualizer") as demo:
150
  """Update the displayed trajectory."""
151
  if dataset is None:
152
  return None, "No dataset loaded", "No dataset loaded", None
153
- # Ensure index is within bounds
154
- if index >= len(dataset):
 
 
155
  index = len(dataset) - 1
156
  elif index < 0:
157
  index = 0
158
- return visualize_trajectory(dataset, index)
159
 
160
  def next_trajectory(dataset, current_idx):
161
  """Go to next trajectory."""
@@ -173,11 +174,33 @@ with gr.Blocks(title="RFM Dataset Visualizer") as demo:
173
  video, metadata, title, image = visualize_trajectory(dataset, prev_idx)
174
  return prev_idx, video, metadata, title, image
175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  # Connect the components
177
  load_btn.click(
178
  fn=load_dataset,
179
  inputs=[dataset_name_input, config_name_input],
180
- outputs=[current_dataset, status_output, dataset_info, current_index, slider]
 
 
 
 
181
  )
182
 
183
  slider.change(
@@ -213,7 +236,11 @@ with gr.Blocks(title="RFM Dataset Visualizer") as demo:
213
  # Load initial dataset
214
  demo.load(
215
  fn=lambda: load_dataset("aliangdw/rfm", "libero_10"),
216
- outputs=[current_dataset, status_output, dataset_info, current_index, slider]
 
 
 
 
217
  )
218
 
219
  # Launch the app
 
50
  metadata = f"""
51
  ## Trajectory Information
52
 
53
+ **Language Task:** {task}
54
 
55
+ **Optimal:** {optimal}
56
 
57
+ **Data Type:** {'Robot' if is_robot else 'Human'}
58
 
59
  **Source:** {data_source}
60
+
 
 
61
  **Trajectory ID:** {item.get('id', 'N/A')}
62
  """
63
 
 
114
  prev_btn = gr.Button("⬅️ Previous", variant="secondary")
115
 
116
  with gr.Column(scale=2):
117
+ # Slider for navigation with dynamic max
118
  slider = gr.Slider(
119
  minimum=0,
120
+ maximum=0,
121
  step=1,
122
  value=0,
123
+ label="Select a dataset first",
124
+ interactive=False
125
  )
126
 
127
  with gr.Column(scale=1):
 
140
  if dataset is not None:
141
  max_index = len(dataset) - 1
142
  info = f"**Dataset Info:**\n- **Total Trajectories:** {len(dataset)}\n- **Features:** {list(dataset.features.keys())}"
143
+ # Return the dataset length for number input configuration
144
  return dataset, status, info, 0, max_index
145
  else:
146
  return None, status, "", 0, 0
 
149
  """Update the displayed trajectory."""
150
  if dataset is None:
151
  return None, "No dataset loaded", "No dataset loaded", None
152
+ # Ensure index is within bounds and is a valid number
153
+ if index is None or not isinstance(index, (int, float)):
154
+ index = 0
155
+ elif index >= len(dataset):
156
  index = len(dataset) - 1
157
  elif index < 0:
158
  index = 0
159
+ return visualize_trajectory(dataset, int(index))
160
 
161
  def next_trajectory(dataset, current_idx):
162
  """Go to next trajectory."""
 
174
  video, metadata, title, image = visualize_trajectory(dataset, prev_idx)
175
  return prev_idx, video, metadata, title, image
176
 
177
+ def update_slider_range(dataset):
178
+ """Update the slider with new maximum value based on dataset length."""
179
+ if dataset is not None:
180
+ max_value = len(dataset) - 1
181
+ return gr.update(
182
+ maximum=max_value,
183
+ value=0, # Reset to beginning
184
+ label=f"Trajectory Index (0 to {max_value})",
185
+ interactive=True
186
+ )
187
+ else:
188
+ return gr.update(
189
+ maximum=0,
190
+ value=0,
191
+ label="Select a dataset first",
192
+ interactive=False
193
+ )
194
+
195
  # Connect the components
196
  load_btn.click(
197
  fn=load_dataset,
198
  inputs=[dataset_name_input, config_name_input],
199
+ outputs=[current_dataset, status_output, dataset_info, current_index]
200
+ ).then(
201
+ fn=update_slider_range,
202
+ inputs=current_dataset,
203
+ outputs=slider
204
  )
205
 
206
  slider.change(
 
236
  # Load initial dataset
237
  demo.load(
238
  fn=lambda: load_dataset("aliangdw/rfm", "libero_10"),
239
+ outputs=[current_dataset, status_output, dataset_info, current_index]
240
+ ).then(
241
+ fn=update_slider_range,
242
+ inputs=current_dataset,
243
+ outputs=slider
244
  )
245
 
246
  # Launch the app