Spaces:
Sleeping
Sleeping
Update app.py
Browse files2 unmodified lines345667815 unmodified lines2425262829302728293031363738394032333435364237383940414243444517 unmodified lines63646566676667685 unmodified lines7475767980818283777879808189909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311328283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241331341351361371381391251261421272 unmodified linesimport sysimport osimport threadingimport time
class Logger: def __init__(self, filename):15 unmodified lineslog_file = "bigcodebench_output.log"sys.stdout = Logger(log_file)
default_command = "bigcodebench.evaluate"is_running = False
def generate_command( jsonl_file, split, subset, save_pass_rate, parallel, min_time_limit, max_as_limit, max_data_limit, max_stack_limit, check_gt_only, no_gt): command = [default_command] if jsonl_file is not None: samples = os.path.basename(jsonl_file.name) command.extend(["--samples", samples]) if jsonl_file is None: return "Please upload a JSONL file"
samples = os.path.basename(jsonl_file.name) command.extend(["--split", split, "--subset", subset]) command = [ "bigcodebench.evaluate", "--split", split, "--subset", subset, "--samples", samples ] if save_pass_rate: command.append("--save_pass_rate")17 unmodified lines return " ".join(command)
def run_bigcodebench(command): global is_running is_running = True print(f"Executing command: {command}") process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)5 unmodified lines if process.returncode != 0: print(f"Error: Command exited with status {process.returncode}") 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/*" subprocess.run(cleanup_command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) is_running = False
def read_logs(): with open(log_file, "r") as f: return f.read()
def run(): with gr.Blocks() as demo: gr.Markdown("# BigCodeBench Evaluation App") with gr.Row(): jsonl_file = gr.File(label="Upload JSONL file", file_types=[".jsonl"]) split = gr.Dropdown(choices=["complete", "instruct"], label="Split", value="complete") subset = gr.Dropdown(choices=["full", "hard"], label="Subset", value="full") with gr.Row(): save_pass_rate = gr.Checkbox(label="Save Pass Rate") parallel = gr.Number(label="Parallel (optional)", precision=0) min_time_limit = gr.Number(label="Min Time Limit", value=1, precision=1) max_as_limit = gr.Number(label="Max AS Limit", value=128*1024, precision=0) with gr.Row(): max_data_limit = gr.Number(label="Max Data Limit", value=4*1024, precision=0) max_stack_limit = gr.Number(label="Max Stack Limit", value=5, precision=0) check_gt_only = gr.Checkbox(label="Check GT Only") no_gt = gr.Checkbox(label="No GT") command_output = gr.Textbox(label="Command", lines=2, value=default_command, interactive=False) submit_btn = gr.Button("Run Evaluation") log_output = gr.Textbox(label="Execution Logs", lines=10) def update_command(*args): return generate_command(*args) input_components = [ jsonl_file, split, subset, save_pass_rate, parallel, min_time_limit, max_as_limit, max_data_limit, max_stack_limit, check_gt_only, no_gt ] for component in input_components: component.change(update_command, inputs=input_components, outputs=command_output) def on_submit(command): global is_running if is_running: return "A command is already running. Please wait for it to finish." def run_and_update(): run_bigcodebench(command)with gr.Blocks() as demo: gr.Markdown("# BigCodeBench Evaluation App") with gr.Row(): jsonl_file = gr.File(label="Upload JSONL file", file_types=[".jsonl"]) split = gr.Dropdown(choices=["complete", "instruct"], label="Split", value="complete") subset = gr.Dropdown(choices=["full", "hard"], label="Subset", value="full") with gr.Row(): save_pass_rate = gr.Checkbox(label="Save Pass Rate") parallel = gr.Number(label="Parallel (optional)", precision=0) min_time_limit = gr.Number(label="Min Time Limit", value=1, precision=1) max_as_limit = gr.Number(label="Max AS Limit", value=128*1024, precision=0) with gr.Row(): max_data_limit = gr.Number(label="Max Data Limit", value=4*1024, precision=0) max_stack_limit = gr.Number(label="Max Stack Limit", value=5, precision=0) check_gt_only = gr.Checkbox(label="Check GT Only") no_gt = gr.Checkbox(label="No GT") command_output = gr.Textbox(label="Command", lines=2) submit_btn = gr.Button("Run Evaluation") log_output = gr.Textbox(label="Execution Logs", lines=10) def update_command(*args): return generate_command(*args) input_components = [ jsonl_file, split, subset, save_pass_rate, parallel, min_time_limit, max_as_limit, max_data_limit, max_stack_limit, check_gt_only, no_gt ] for component in input_components: component.change(update_command, inputs=input_components, outputs=command_output) def on_submit(command): threading.Thread(target=run_bigcodebench, args=(command,), daemon=True).start() return "Evaluation started. Please wait for the logs to update..." submit_btn.click(on_submit, inputs=[command_output], outputs=[log_output]) demo.load(read_logs, None, log_output, every=1) return read_logs() return gr.update(value="Evaluation started. Please wait for the logs to update..."), gr.update(value=run_and_update) submit_btn.click(on_submit, inputs=[command_output], outputs=[log_output, log_output])
demo.launch(server_name="0.0.0.0", server_port=7860)
if __name__ == "__main__": run() demo.queue().launch()app.py+54-69