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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -68
app.py CHANGED
@@ -4,20 +4,19 @@ import argparse
4
  import pandas as pd
5
  from functools import partial
6
  import subprocess
7
- """
8
- 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
 
13
- SUCCESS_HEADERS = ["is_success", "first_attempt","is_first_success", "last_attempt", "is_last_success"]
14
- SUCCESS_DATATYPES = ["bool"]*5
 
 
 
 
15
 
16
  def capture_output(prompt, completion, prints):
17
  code = "\n".join([prompt, " "+" \n".join(completion.split("\n")), prints])
18
  outputs = subprocess.run(["python", "-c", code], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
19
  stderr = gr.Textbox(outputs.stderr.decode("utf-8").strip(), label="Code Errors", type="text")
20
- stdout = gr.Code(outputs.stdout.decode("utf-8").strip(), label="Code Ouputs", language="python")
21
  return stderr, stdout
22
 
23
  def update_components(
@@ -27,11 +26,7 @@ def update_components(
27
  success_data,
28
  prompt,
29
  submitted_text,
30
- completion,
31
  assertions,
32
- prints,
33
- code_err,
34
- code_output
35
  ):
36
  if isinstance(ds, gr.State):
37
  ds = ds.value
@@ -57,31 +52,20 @@ def update_components(
57
  row = row.iloc[0]
58
  prompt = gr.Code(row["prompt"], language="python", label="Prompt")
59
  submitted_text = gr.Textbox(row["submitted_text"], type="text", label="Submitted Text")
60
- completion = gr.Code(row["completion"], language="python", label="Completion")
61
  assertions = gr.Code(row["assertions"], language="python", label="Assertions")
62
- prints = gr.Code(row["prints"], language="python", label="Prints")
63
- code_err = gr.Textbox("__stderr__", label="Code Errors", type="text")
64
- code_output = gr.Code("__stdout__", language="python", label="Code Outputs")
65
  slider = gr.Slider(0, len(ds) - 1, step=1, label="Problem ID (click and arrow keys to navigate):", value=slider)
66
  return [slider, header_data, success_data, prompt, submitted_text,
67
- completion, assertions, prints, code_err, code_output]
68
 
69
  def filter_by(
70
  dataset_name,
71
  dataset_split,
72
- fs_box, ls_box, ff_box, lf_box, f_box, l_box, is_success_box,
73
  problem_box,
74
  student_box,
75
  slider,
76
  *components_to_update):
77
  ds = load_dataset(dataset_name, split=dataset_split)
78
- success_boxes = [fs_box, ls_box, ff_box, lf_box, f_box, l_box, is_success_box]
79
  ds = ds.to_pandas()
80
- labels = ["is_first_success","is_last_success","is_first_failure","is_last_failure",
81
- "first_attempt","last_attempt","is_success"]
82
- for label, box in zip(labels, success_boxes):
83
- if box:
84
- ds = ds[ds[label] == box]
85
 
86
  if problem_box != None:
87
  ds = ds[ds["problem"] == problem_box]
@@ -89,20 +73,16 @@ def filter_by(
89
  if student_box != None:
90
  ds = ds[ds["username"] == student_box]
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)
@@ -143,61 +123,31 @@ def main(args):
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")
152
-
153
- runbtn = gr.Button("Run this code")
154
-
155
- with gr.Column():
156
- with gr.Row():
157
- code_output = gr.Code("__stdout__", language="python", label="Code Outputs")
158
- code_err = gr.Textbox("__stderr__", label="Code Errors", type="text")
159
-
160
- gr.Markdown("**Logging**\n")
161
- with gr.Column():
162
- with gr.Row():
163
- flagbtn = gr.Button("Flag this example to log file")
164
- flagout = gr.Textbox(label="Num examples in logfile")
165
 
166
  # updates
167
- # run code
168
- runbtn.click(fn=capture_output, inputs=[prompt, completion, prints], outputs=[code_err,code_output])
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,
179
- preprocess=False, show_progress="full", trigger_mode="once")
180
-
181
  # add filtering options
182
  gr.Markdown("**Filtering (reload to clear all filters)**\n")
183
  with gr.Row():
184
  with gr.Column():
185
- fs_box = gr.Checkbox(label="is_first_success")
186
- ls_box = gr.Checkbox(label="is_last_success")
187
- with gr.Column():
188
- ff_box = gr.Checkbox(label="is_first_failure")
189
- lf_box = gr.Checkbox(label="is_last_failure")
190
- with gr.Column():
191
- f_box = gr.Checkbox(label="first_attempt")
192
- l_box = gr.Checkbox(label="last_attempt")
193
- is_success_box = gr.Checkbox(label="is_success")
194
- success_boxes = [fs_box, ls_box, ff_box, lf_box, f_box, l_box, is_success_box]
195
- problem_box = gr.Dropdown(label="problem", choices = problem_names)
196
- student_box = gr.Dropdown(label="username", choices = student_usernames)
197
  filter_btn = gr.Button("Filter")
198
 
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
 
@@ -207,5 +157,4 @@ if __name__ == "__main__":
207
  parser.add_argument("--split", type=str, default="test")
208
  parser.add_argument("--share", action="store_true")
209
  args = parser.parse_args()
210
- main(args)
211
-
 
4
  import pandas as pd
5
  from functools import partial
6
  import subprocess
 
 
 
 
 
7
 
8
+ # Headers and datatypes for the remaining columns
9
+ HEADERS = ["__index_level_0__", "problem", "username", "entrypoint", "submitted_text", "prompt", "subset"]
10
+ DATATYPES = ["number", "str", "str", "str", "str", "str", "str"]
11
+
12
+ SUCCESS_HEADERS = ["subset"]
13
+ SUCCESS_DATATYPES = ["str"]
14
 
15
  def capture_output(prompt, completion, prints):
16
  code = "\n".join([prompt, " "+" \n".join(completion.split("\n")), prints])
17
  outputs = subprocess.run(["python", "-c", code], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
18
  stderr = gr.Textbox(outputs.stderr.decode("utf-8").strip(), label="Code Errors", type="text")
19
+ stdout = gr.Code(outputs.stdout.decode("utf-8").strip(), label="Code Outputs", language="python")
20
  return stderr, stdout
21
 
22
  def update_components(
 
26
  success_data,
27
  prompt,
28
  submitted_text,
 
29
  assertions,
 
 
 
30
  ):
31
  if isinstance(ds, gr.State):
32
  ds = ds.value
 
52
  row = row.iloc[0]
53
  prompt = gr.Code(row["prompt"], language="python", label="Prompt")
54
  submitted_text = gr.Textbox(row["submitted_text"], type="text", label="Submitted Text")
 
55
  assertions = gr.Code(row["assertions"], language="python", label="Assertions")
 
 
 
56
  slider = gr.Slider(0, len(ds) - 1, step=1, label="Problem ID (click and arrow keys to navigate):", value=slider)
57
  return [slider, header_data, success_data, prompt, submitted_text,
58
+ assertions]
59
 
60
  def filter_by(
61
  dataset_name,
62
  dataset_split,
 
63
  problem_box,
64
  student_box,
65
  slider,
66
  *components_to_update):
67
  ds = load_dataset(dataset_name, split=dataset_split)
 
68
  ds = ds.to_pandas()
 
 
 
 
 
69
 
70
  if problem_box != None:
71
  ds = ds[ds["problem"] == problem_box]
 
73
  if student_box != None:
74
  ds = ds[ds["username"] == student_box]
75
 
76
+ return [ds, *update_components(ds, 0, *components_to_update)]
 
77
 
78
  def next_example(ds, *components):
79
  slider_value = components[0]
 
 
80
  new_slider_value = int(slider_value)+1 if slider_value < len(ds)-1 else len(ds)-1
81
  lesscomponents = components[1:]
82
  return update_components(ds, new_slider_value, *lesscomponents)
83
 
84
  def prev_example(ds, *components):
85
  slider_value = components[0]
 
86
  new_slider_value = int(slider_value)-1 if slider_value > 0 else 0
87
  lesscomponents = components[1:]
88
  return update_components(ds, new_slider_value, *lesscomponents)
 
123
  prev_btn = gr.Button("Previous")
124
  next_btn = gr.Button("Next")
125
  submitted_text = gr.Textbox("__submitted_text__", type="text", label="Submitted Text")
 
 
126
 
127
+
128
  with gr.Row():
129
  assertions = gr.Code("__assertions__", language="python", label="Assertions")
130
+
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
132
  # updates
 
 
133
  # change example on slider change
134
+ components = [slider, header_data, success_data, prompt, submitted_text, assertions]
135
  slider.input(fn=update_components, inputs=[dataset, *components], outputs=components)
136
 
137
  prev_btn.click(fn=prev_example, inputs=[dataset, *components], outputs=components)
138
  next_btn.click(fn=next_example, inputs=[dataset, *components], outputs=components)
139
 
 
 
 
 
 
140
  # add filtering options
141
  gr.Markdown("**Filtering (reload to clear all filters)**\n")
142
  with gr.Row():
143
  with gr.Column():
144
+ problem_box = gr.Dropdown(label="problem", choices=problem_names)
145
+ student_box = gr.Dropdown(label="username", choices=student_usernames)
 
 
 
 
 
 
 
 
 
 
146
  filter_btn = gr.Button("Filter")
147
 
148
+ filter_btn.click(fn=partial(filter_by, args.dataset, args.split), inputs=[problem_box, student_box, *components],
149
  outputs=[dataset, *components])
150
+
151
 
152
  demo.launch(share=args.share)
153
 
 
157
  parser.add_argument("--split", type=str, default="test")
158
  parser.add_argument("--share", action="store_true")
159
  args = parser.parse_args()
160
+ main(args)