AryaWu commited on
Commit
c3d4a7e
·
verified ·
1 Parent(s): 0eb0876

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -3
app.py CHANGED
@@ -9,6 +9,7 @@ Eventually add filters based on headers
9
  """
10
  HEADERS = ["__index_level_0__", "problem", "username", "entrypoint", "tests_passed", "total_tests"]
11
  DATATYPES = ["number", "str", "str", "str", "number", "number"]
 
12
  SUCCESS_HEADERS = ["is_success", "first_attempt","is_first_success", "last_attempt", "is_last_success"]
13
  SUCCESS_DATATYPES = ["bool"]*5
14
 
@@ -90,7 +91,22 @@ def filter_by(
90
 
91
  dataset = gr.State(ds)
92
  return [dataset, *update_components(ds, 0, *components_to_update)]
93
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  def main(args):
95
  ds = load_dataset(args.dataset, split=args.split)
96
  ds = ds.to_pandas()
@@ -122,10 +138,14 @@ def main(args):
122
  interactive=False,
123
  )
124
 
125
- prompt = gr.Code("__prompt__", language="python", label="Prompt")
 
 
 
126
  submitted_text = gr.Textbox("__submitted_text__", type="text", label="Submitted Text")
127
  completion = gr.Code("__completion__", language="python", label="Completion")
128
 
 
129
  with gr.Row():
130
  assertions = gr.Code("__assertions__", language="python", label="Assertions")
131
  prints = gr.Code("__prints__", language="python", label="Prints")
@@ -149,6 +169,10 @@ def main(args):
149
  # change example on slider change
150
  components = [slider, header_data, success_data, prompt, submitted_text, completion, assertions, prints, code_err, code_output]
151
  slider.input(fn=update_components, inputs=[dataset, *components], outputs=components)
 
 
 
 
152
  # log
153
  callback.setup(components, "flagged_data_points")
154
  flagbtn.click(lambda *args: callback.flag(list(args)), components, flagout,
@@ -175,7 +199,7 @@ def main(args):
175
  filter_btn.click(fn=partial(filter_by, args.dataset, args.split), inputs=[*success_boxes, problem_box, student_box, *components],
176
  outputs=[dataset, *components])
177
 
178
- demo.launch(share=True)
179
 
180
  if __name__ == "__main__":
181
  parser = argparse.ArgumentParser()
@@ -184,3 +208,4 @@ if __name__ == "__main__":
184
  parser.add_argument("--share", action="store_true")
185
  args = parser.parse_args()
186
  main(args)
 
 
9
  """
10
  HEADERS = ["__index_level_0__", "problem", "username", "entrypoint", "tests_passed", "total_tests"]
11
  DATATYPES = ["number", "str", "str", "str", "number", "number"]
12
+
13
  SUCCESS_HEADERS = ["is_success", "first_attempt","is_first_success", "last_attempt", "is_last_success"]
14
  SUCCESS_DATATYPES = ["bool"]*5
15
 
 
91
 
92
  dataset = gr.State(ds)
93
  return [dataset, *update_components(ds, 0, *components_to_update)]
94
+
95
+ def next_example(ds, *components):
96
+ slider_value = components[0]
97
+ print(slider_value)
98
+ # Adjust slider value within bounds (min 0, max len(ds)-1)
99
+ new_slider_value = int(slider_value)+1 if slider_value < len(ds)-1 else len(ds)-1
100
+ lesscomponents = components[1:]
101
+ return update_components(ds, new_slider_value, *lesscomponents)
102
+
103
+ def prev_example(ds, *components):
104
+ slider_value = components[0]
105
+ # Adjust slider value within bounds (min 0, max len(ds)-1)
106
+ new_slider_value = int(slider_value)-1 if slider_value > 0 else 0
107
+ lesscomponents = components[1:]
108
+ return update_components(ds, new_slider_value, *lesscomponents)
109
+
110
  def main(args):
111
  ds = load_dataset(args.dataset, split=args.split)
112
  ds = ds.to_pandas()
 
138
  interactive=False,
139
  )
140
 
141
+ prompt = gr.Code("__prompt__", language="python", label="Prompt")
142
+ with gr.Row():
143
+ prev_btn = gr.Button("Previous")
144
+ next_btn = gr.Button("Next")
145
  submitted_text = gr.Textbox("__submitted_text__", type="text", label="Submitted Text")
146
  completion = gr.Code("__completion__", language="python", label="Completion")
147
 
148
+
149
  with gr.Row():
150
  assertions = gr.Code("__assertions__", language="python", label="Assertions")
151
  prints = gr.Code("__prints__", language="python", label="Prints")
 
169
  # change example on slider change
170
  components = [slider, header_data, success_data, prompt, submitted_text, completion, assertions, prints, code_err, code_output]
171
  slider.input(fn=update_components, inputs=[dataset, *components], outputs=components)
172
+
173
+ prev_btn.click(fn=prev_example, inputs=[dataset, *components], outputs=components)
174
+ next_btn.click(fn=next_example, inputs=[dataset, *components], outputs=components)
175
+
176
  # log
177
  callback.setup(components, "flagged_data_points")
178
  flagbtn.click(lambda *args: callback.flag(list(args)), components, flagout,
 
199
  filter_btn.click(fn=partial(filter_by, args.dataset, args.split), inputs=[*success_boxes, problem_box, student_box, *components],
200
  outputs=[dataset, *components])
201
 
202
+ demo.launch(share=args.share)
203
 
204
  if __name__ == "__main__":
205
  parser = argparse.ArgumentParser()
 
208
  parser.add_argument("--share", action="store_true")
209
  args = parser.parse_args()
210
  main(args)
211
+