Orr Zohar commited on
Commit
1fbdd31
1 Parent(s): 3cbc2a8

fix slider

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import math
2
- import random
3
  import gradio as gr
4
  import os
5
  import json
@@ -71,18 +70,21 @@ def get_col(example, dataset_name):
71
  return inputs_left, text_inputs_right
72
 
73
  with demo:
74
- gr.Markdown("# Slide to iterate videos")
75
-
76
  with gr.Column():
77
  dataset_dropdown = gr.Dropdown(choices=list(json_files.keys()), label="Select Dataset", value="Kinetics700")
78
- slider = gr.Slider(minimum=0, maximum=math.ceil(500 / batch_size), step=1, label='Page') # Assuming 500 samples per dataset
 
 
 
 
 
 
 
 
79
  with gr.Row():
80
  index = slider.value
81
- dataset = dataset_dropdown.value
82
  start_index = 0 * batch_size
83
  end_index = start_index + batch_size
84
- with open(json_files[dataset], 'r') as f:
85
- data = json.load(f)
86
  all_examples = data[start_index:end_index]
87
  all_inputs_left_right = []
88
  for example_idx, example in enumerate(all_examples):
@@ -93,4 +95,4 @@ with demo:
93
  slider.change(func, inputs=[slider, dataset_dropdown], outputs=all_inputs_left_right)
94
  dataset_dropdown.change(func, inputs=[slider, dataset_dropdown], outputs=all_inputs_left_right)
95
 
96
- demo.launch()
 
1
  import math
 
2
  import gradio as gr
3
  import os
4
  import json
 
70
  return inputs_left, text_inputs_right
71
 
72
  with demo:
 
 
73
  with gr.Column():
74
  dataset_dropdown = gr.Dropdown(choices=list(json_files.keys()), label="Select Dataset", value="Kinetics700")
75
+
76
+ # Load the selected dataset to determine the number of samples
77
+ dataset = dataset_dropdown.value
78
+ with open(json_files[dataset], 'r') as f:
79
+ data = json.load(f)
80
+ num_samples = len(data)
81
+
82
+ slider = gr.Slider(minimum=0, maximum=math.floor(num_samples / batch_size) - 1, step=1, label='Page')
83
+
84
  with gr.Row():
85
  index = slider.value
 
86
  start_index = 0 * batch_size
87
  end_index = start_index + batch_size
 
 
88
  all_examples = data[start_index:end_index]
89
  all_inputs_left_right = []
90
  for example_idx, example in enumerate(all_examples):
 
95
  slider.change(func, inputs=[slider, dataset_dropdown], outputs=all_inputs_left_right)
96
  dataset_dropdown.change(func, inputs=[slider, dataset_dropdown], outputs=all_inputs_left_right)
97
 
98
+ demo.launch()