aliangdw commited on
Commit
ccd9825
·
1 Parent(s): 390b4c9
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -20,7 +20,7 @@ def get_available_configs(dataset_name):
20
  print(f"Error getting configs: {e}")
21
  return []
22
 
23
- def visualize_trajectory(dataset, index):
24
  """
25
  Function to retrieve a trajectory and its metadata from the dataset.
26
  """
@@ -41,7 +41,11 @@ def visualize_trajectory(dataset, index):
41
 
42
  # Handle video file path (could be local path or HuggingFace Hub URL)
43
  if isinstance(frames_data, str):
44
- video_path = f"https://huggingface.co/datasets/aliangdw/rfm/resolve/main/{frames_data}"
 
 
 
 
45
  frames_info = f"Video file: {video_path}"
46
  else:
47
  return None, "Error: Invalid video path", "Error: Invalid video path", None
@@ -145,7 +149,7 @@ with gr.Blocks(title="RFM Dataset Visualizer") as demo:
145
  else:
146
  return None, status, "", 0, 0
147
 
148
- def update_trajectory(dataset, index):
149
  """Update the displayed trajectory."""
150
  if dataset is None:
151
  return None, "No dataset loaded", "No dataset loaded", None
@@ -156,22 +160,22 @@ with gr.Blocks(title="RFM Dataset Visualizer") as demo:
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."""
163
  if dataset is None:
164
  return current_idx, None, "No dataset loaded", "No dataset loaded", None
165
  next_idx = min(current_idx + 1, len(dataset) - 1)
166
- video, metadata, title, image = visualize_trajectory(dataset, next_idx)
167
  return next_idx, video, metadata, title, image
168
 
169
- def prev_trajectory(dataset, current_idx):
170
  """Go to previous trajectory."""
171
  if dataset is None:
172
  return current_idx, None, "No dataset loaded", "No dataset loaded", None
173
  prev_idx = max(current_idx - 1, 0)
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):
@@ -204,8 +208,8 @@ with gr.Blocks(title="RFM Dataset Visualizer") as demo:
204
  )
205
 
206
  slider.change(
207
- fn=lambda dataset, idx: update_trajectory(dataset, idx),
208
- inputs=[current_dataset, slider],
209
  outputs=[video_output, metadata_output, title_output, image_output]
210
  ).then(
211
  fn=lambda dataset, idx: idx if dataset is None or idx < len(dataset) else len(dataset) - 1,
@@ -214,8 +218,8 @@ with gr.Blocks(title="RFM Dataset Visualizer") as demo:
214
  )
215
 
216
  next_btn.click(
217
- fn=next_trajectory,
218
- inputs=[current_dataset, current_index],
219
  outputs=[current_index, video_output, metadata_output, title_output, image_output]
220
  ).then(
221
  fn=lambda idx: idx,
@@ -224,8 +228,8 @@ with gr.Blocks(title="RFM Dataset Visualizer") as demo:
224
  )
225
 
226
  prev_btn.click(
227
- fn=prev_trajectory,
228
- inputs=[current_dataset, current_index],
229
  outputs=[current_index, video_output, metadata_output, title_output, image_output]
230
  ).then(
231
  fn=lambda idx: idx,
 
20
  print(f"Error getting configs: {e}")
21
  return []
22
 
23
+ def visualize_trajectory(dataset, index, dataset_name=None):
24
  """
25
  Function to retrieve a trajectory and its metadata from the dataset.
26
  """
 
41
 
42
  # Handle video file path (could be local path or HuggingFace Hub URL)
43
  if isinstance(frames_data, str):
44
+ # Use dynamic dataset name if provided, otherwise fallback to default
45
+ if dataset_name:
46
+ video_path = f"https://huggingface.co/datasets/{dataset_name}/resolve/main/{frames_data}"
47
+ else:
48
+ video_path = f"https://huggingface.co/datasets/aliangdw/rfm/resolve/main/{frames_data}"
49
  frames_info = f"Video file: {video_path}"
50
  else:
51
  return None, "Error: Invalid video path", "Error: Invalid video path", None
 
149
  else:
150
  return None, status, "", 0, 0
151
 
152
+ def update_trajectory(dataset, index, dataset_name=None):
153
  """Update the displayed trajectory."""
154
  if dataset is None:
155
  return None, "No dataset loaded", "No dataset loaded", None
 
160
  index = len(dataset) - 1
161
  elif index < 0:
162
  index = 0
163
+ return visualize_trajectory(dataset, int(index), dataset_name)
164
 
165
+ def next_trajectory(dataset, current_idx, dataset_name=None):
166
  """Go to next trajectory."""
167
  if dataset is None:
168
  return current_idx, None, "No dataset loaded", "No dataset loaded", None
169
  next_idx = min(current_idx + 1, len(dataset) - 1)
170
+ video, metadata, title, image = visualize_trajectory(dataset, next_idx, dataset_name)
171
  return next_idx, video, metadata, title, image
172
 
173
+ def prev_trajectory(dataset, current_idx, dataset_name=None):
174
  """Go to previous trajectory."""
175
  if dataset is None:
176
  return current_idx, None, "No dataset loaded", "No dataset loaded", None
177
  prev_idx = max(current_idx - 1, 0)
178
+ video, metadata, title, image = visualize_trajectory(dataset, prev_idx, dataset_name)
179
  return prev_idx, video, metadata, title, image
180
 
181
  def update_slider_range(dataset):
 
208
  )
209
 
210
  slider.change(
211
+ fn=lambda dataset, idx, dataset_name: update_trajectory(dataset, idx, dataset_name),
212
+ inputs=[current_dataset, slider, dataset_name_input],
213
  outputs=[video_output, metadata_output, title_output, image_output]
214
  ).then(
215
  fn=lambda dataset, idx: idx if dataset is None or idx < len(dataset) else len(dataset) - 1,
 
218
  )
219
 
220
  next_btn.click(
221
+ fn=lambda dataset, idx, dataset_name: next_trajectory(dataset, idx, dataset_name),
222
+ inputs=[current_dataset, current_index, dataset_name_input],
223
  outputs=[current_index, video_output, metadata_output, title_output, image_output]
224
  ).then(
225
  fn=lambda idx: idx,
 
228
  )
229
 
230
  prev_btn.click(
231
+ fn=lambda dataset, idx, dataset_name: prev_trajectory(dataset, idx, dataset_name),
232
+ inputs=[current_dataset, current_index, dataset_name_input],
233
  outputs=[current_index, video_output, metadata_output, title_output, image_output]
234
  ).then(
235
  fn=lambda idx: idx,