terryyz commited on
Commit
45b26c3
1 Parent(s): 865ee9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -69
app.py CHANGED
@@ -3,7 +3,6 @@ import subprocess
3
  import sys
4
  import os
5
  import threading
6
- import time
7
 
8
  class Logger:
9
  def __init__(self, filename):
@@ -25,21 +24,22 @@ class Logger:
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,8 +63,6 @@ def generate_command(
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,67 +74,54 @@ def run_bigcodebench(command):
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
- def run():
90
- with gr.Blocks() as demo:
91
- gr.Markdown("# BigCodeBench Evaluation App")
92
-
93
- with gr.Row():
94
- jsonl_file = gr.File(label="Upload JSONL file", file_types=[".jsonl"])
95
- split = gr.Dropdown(choices=["complete", "instruct"], label="Split", value="complete")
96
- subset = gr.Dropdown(choices=["full", "hard"], label="Subset", value="full")
97
-
98
- with gr.Row():
99
- save_pass_rate = gr.Checkbox(label="Save Pass Rate")
100
- parallel = gr.Number(label="Parallel (optional)", precision=0)
101
- min_time_limit = gr.Number(label="Min Time Limit", value=1, precision=1)
102
- max_as_limit = gr.Number(label="Max AS Limit", value=128*1024, precision=0)
103
-
104
- with gr.Row():
105
- max_data_limit = gr.Number(label="Max Data Limit", value=4*1024, precision=0)
106
- max_stack_limit = gr.Number(label="Max Stack Limit", value=5, precision=0)
107
- check_gt_only = gr.Checkbox(label="Check GT Only")
108
- no_gt = gr.Checkbox(label="No GT")
109
-
110
- command_output = gr.Textbox(label="Command", lines=2, value=default_command, interactive=False)
111
- submit_btn = gr.Button("Run Evaluation")
112
- log_output = gr.Textbox(label="Execution Logs", lines=10)
113
-
114
- def update_command(*args):
115
- return generate_command(*args)
116
-
117
- input_components = [
118
- jsonl_file, split, subset, save_pass_rate, parallel,
119
- min_time_limit, max_as_limit, max_data_limit, max_stack_limit,
120
- check_gt_only, no_gt
121
- ]
122
-
123
- for component in input_components:
124
- component.change(update_command, inputs=input_components, outputs=command_output)
125
-
126
- def on_submit(command):
127
- global is_running
128
- if is_running:
129
- return "A command is already running. Please wait for it to finish."
130
-
131
- def run_and_update():
132
- run_bigcodebench(command)
133
- return read_logs()
134
-
135
- return gr.update(value="Evaluation started. Please wait for the logs to update..."), gr.update(value=run_and_update)
136
-
137
- submit_btn.click(on_submit, inputs=[command_output], outputs=[log_output, log_output])
138
-
139
- demo.launch(server_name="0.0.0.0", server_port=7860)
140
 
141
  if __name__ == "__main__":
142
- run()
 
3
  import sys
4
  import os
5
  import threading
 
6
 
7
  class Logger:
8
  def __init__(self, filename):
 
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
  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
 
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
+ with gr.Blocks() as demo:
83
+ gr.Markdown("# BigCodeBench Evaluation App")
84
+
85
+ with gr.Row():
86
+ jsonl_file = gr.File(label="Upload JSONL file", file_types=[".jsonl"])
87
+ split = gr.Dropdown(choices=["complete", "instruct"], label="Split", value="complete")
88
+ subset = gr.Dropdown(choices=["full", "hard"], label="Subset", value="full")
89
+
90
+ with gr.Row():
91
+ save_pass_rate = gr.Checkbox(label="Save Pass Rate")
92
+ parallel = gr.Number(label="Parallel (optional)", precision=0)
93
+ min_time_limit = gr.Number(label="Min Time Limit", value=1, precision=1)
94
+ max_as_limit = gr.Number(label="Max AS Limit", value=128*1024, precision=0)
95
+
96
+ with gr.Row():
97
+ max_data_limit = gr.Number(label="Max Data Limit", value=4*1024, precision=0)
98
+ max_stack_limit = gr.Number(label="Max Stack Limit", value=5, precision=0)
99
+ check_gt_only = gr.Checkbox(label="Check GT Only")
100
+ no_gt = gr.Checkbox(label="No GT")
101
+
102
+ command_output = gr.Textbox(label="Command", lines=2)
103
+ submit_btn = gr.Button("Run Evaluation")
104
+ log_output = gr.Textbox(label="Execution Logs", lines=10)
105
+
106
+ def update_command(*args):
107
+ return generate_command(*args)
108
+
109
+ input_components = [
110
+ jsonl_file, split, subset, save_pass_rate, parallel,
111
+ min_time_limit, max_as_limit, max_data_limit, max_stack_limit,
112
+ check_gt_only, no_gt
113
+ ]
114
+
115
+ for component in input_components:
116
+ component.change(update_command, inputs=input_components, outputs=command_output)
117
+
118
+ def on_submit(command):
119
+ threading.Thread(target=run_bigcodebench, args=(command,), daemon=True).start()
120
+ return "Evaluation started. Please wait for the logs to update..."
121
+
122
+ submit_btn.click(on_submit, inputs=[command_output], outputs=[log_output])
123
+
124
+ demo.load(read_logs, None, log_output, every=1)
 
 
 
 
 
 
 
 
125
 
126
  if __name__ == "__main__":
127
+ demo.queue().launch()