terryyz commited on
Commit
828190b
1 Parent(s): 3459dd9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -57
app.py CHANGED
@@ -3,6 +3,7 @@ import subprocess
3
  import sys
4
  import os
5
  import threading
 
6
 
7
  class Logger:
8
  def __init__(self, filename):
@@ -24,22 +25,21 @@ class Logger:
24
  log_file = "bigcodebench_output.log"
25
  sys.stdout = Logger(log_file)
26
 
 
 
 
27
  def generate_command(
28
  jsonl_file, split, subset, save_pass_rate, parallel,
29
  min_time_limit, max_as_limit, max_data_limit, max_stack_limit,
30
  check_gt_only, no_gt
31
  ):
32
- if jsonl_file is None:
33
- return "Please upload a JSONL file"
34
-
35
- samples = os.path.basename(jsonl_file.name)
36
 
37
- command = [
38
- "bigcodebench.evaluate",
39
- "--split", split,
40
- "--subset", subset,
41
- "--samples", samples
42
- ]
43
 
44
  if save_pass_rate:
45
  command.append("--save_pass_rate")
@@ -63,6 +63,8 @@ def generate_command(
63
  return " ".join(command)
64
 
65
  def run_bigcodebench(command):
 
 
66
  print(f"Executing command: {command}")
67
 
68
  process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
@@ -74,57 +76,62 @@ def run_bigcodebench(command):
74
 
75
  if process.returncode != 0:
76
  print(f"Error: Command exited with status {process.returncode}")
 
 
 
 
 
77
 
78
  def read_logs():
79
  with open(log_file, "r") as f:
80
  return f.read()
81
 
82
- def run():
83
- with gr.Blocks() as demo:
84
- gr.Markdown("# BigCodeBench Evaluation App")
85
-
86
- with gr.Row():
87
- jsonl_file = gr.File(label="Upload JSONL file", file_types=[".jsonl"])
88
- split = gr.Dropdown(choices=["complete", "instruct"], label="Split", value="complete")
89
- subset = gr.Dropdown(choices=["full", "hard"], label="Subset", value="full")
90
-
91
- with gr.Row():
92
- save_pass_rate = gr.Checkbox(label="Save Pass Rate")
93
- parallel = gr.Number(label="Parallel (optional)", precision=0)
94
- min_time_limit = gr.Number(label="Min Time Limit", value=1, precision=1)
95
- max_as_limit = gr.Number(label="Max AS Limit", value=128*1024, precision=0)
96
-
97
- with gr.Row():
98
- max_data_limit = gr.Number(label="Max Data Limit", value=4*1024, precision=0)
99
- max_stack_limit = gr.Number(label="Max Stack Limit", value=5, precision=0)
100
- check_gt_only = gr.Checkbox(label="Check GT Only")
101
- no_gt = gr.Checkbox(label="No GT")
102
-
103
- command_output = gr.Textbox(label="Command", lines=2)
104
- submit_btn = gr.Button("Run Evaluation")
105
- log_output = gr.Textbox(label="Execution Logs", lines=10)
106
-
107
- def update_command(*args):
108
- return generate_command(*args)
109
-
110
- input_components = [
111
- jsonl_file, split, subset, save_pass_rate, parallel,
112
- min_time_limit, max_as_limit, max_data_limit, max_stack_limit,
113
- check_gt_only, no_gt
114
- ]
115
-
116
- for component in input_components:
117
- component.change(update_command, inputs=input_components, outputs=command_output)
118
-
119
- def on_submit(command):
120
- threading.Thread(target=run_bigcodebench, args=(command,), daemon=True).start()
121
- return "Evaluation started. Please wait for the logs to update..."
122
-
123
- submit_btn.click(on_submit, inputs=[command_output], outputs=[log_output])
124
-
125
- demo.load(read_logs, None, log_output, every=1)
126
-
127
- demo.queue().launch()
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  if __name__ == "__main__":
130
- run()
 
3
  import sys
4
  import os
5
  import threading
6
+ import time
7
 
8
  class Logger:
9
  def __init__(self, filename):
 
25
  log_file = "bigcodebench_output.log"
26
  sys.stdout = Logger(log_file)
27
 
28
+ default_command = "bigcodebench.evaluate"
29
+ is_running = False
30
+
31
  def generate_command(
32
  jsonl_file, split, subset, save_pass_rate, parallel,
33
  min_time_limit, max_as_limit, max_data_limit, max_stack_limit,
34
  check_gt_only, no_gt
35
  ):
36
+ command = [default_command]
 
 
 
37
 
38
+ if jsonl_file is not None:
39
+ samples = os.path.basename(jsonl_file.name)
40
+ command.extend(["--samples", samples])
41
+
42
+ command.extend(["--split", split, "--subset", subset])
 
43
 
44
  if save_pass_rate:
45
  command.append("--save_pass_rate")
 
63
  return " ".join(command)
64
 
65
  def run_bigcodebench(command):
66
+ global is_running
67
+ is_running = True
68
  print(f"Executing command: {command}")
69
 
70
  process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
 
76
 
77
  if process.returncode != 0:
78
  print(f"Error: Command exited with status {process.returncode}")
79
+
80
+ cleanup_command = "pids=$(ps -u $(id -u) -o pid,comm | grep 'bigcodebench' | awk '{print $1}'); if [ -n \"$pids\" ]; then echo $pids | xargs -r kill; fi; rm -rf /tmp/*"
81
+ subprocess.run(cleanup_command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
82
+
83
+ is_running = False
84
 
85
  def read_logs():
86
  with open(log_file, "r") as f:
87
  return f.read()
88
 
89
+ with gr.Blocks() as demo:
90
+ gr.Markdown("# BigCodeBench Evaluation App")
91
+
92
+ with gr.Row():
93
+ jsonl_file = gr.File(label="Upload JSONL file", file_types=[".jsonl"])
94
+ split = gr.Dropdown(choices=["complete", "instruct"], label="Split", value="complete")
95
+ subset = gr.Dropdown(choices=["full", "hard"], label="Subset", value="full")
96
+
97
+ with gr.Row():
98
+ save_pass_rate = gr.Checkbox(label="Save Pass Rate")
99
+ parallel = gr.Number(label="Parallel (optional)", precision=0)
100
+ min_time_limit = gr.Number(label="Min Time Limit", value=1, precision=1)
101
+ max_as_limit = gr.Number(label="Max AS Limit", value=128*1024, precision=0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
+ with gr.Row():
104
+ max_data_limit = gr.Number(label="Max Data Limit", value=4*1024, precision=0)
105
+ max_stack_limit = gr.Number(label="Max Stack Limit", value=5, precision=0)
106
+ check_gt_only = gr.Checkbox(label="Check GT Only")
107
+ no_gt = gr.Checkbox(label="No GT")
108
+
109
+ command_output = gr.Textbox(label="Command", lines=2, value=default_command, interactive=False)
110
+ submit_btn = gr.Button("Run Evaluation")
111
+ log_output = gr.Textbox(label="Execution Logs", lines=10)
112
+
113
+ def update_command(*args):
114
+ return generate_command(*args)
115
+
116
+ input_components = [
117
+ jsonl_file, split, subset, save_pass_rate, parallel,
118
+ min_time_limit, max_as_limit, max_data_limit, max_stack_limit,
119
+ check_gt_only, no_gt
120
+ ]
121
+
122
+ for component in input_components:
123
+ component.change(update_command, inputs=input_components, outputs=command_output)
124
+
125
+ def on_submit(command):
126
+ global is_running
127
+ if is_running:
128
+ return "A command is already running. Please wait for it to finish."
129
+ threading.Thread(target=run_bigcodebench, args=(command,), daemon=True).start()
130
+ return "Evaluation started. Please wait for the logs to update..."
131
+
132
+ submit_btn.click(on_submit, inputs=[command_output], outputs=[log_output])
133
+
134
+ demo.load(read_logs, None, log_output, every=1)
135
+
136
  if __name__ == "__main__":
137
+ demo.queue().launch()