Spaces:
Runtime error
Runtime error
Update app.py
Browse files49 unmodified lines50515253545556575859606129 unmodified lines9192939495969798991001011021031041051 unmodified line10710810911011111211317 unmodified lines1311321331341351361371381391401411421431 unmodified line14514614714814915015115215315415515615715815916016116216316416516616716816917017117217349 unmodified linesreturn " ".join(command)def cleanup_previous_files(jsonl_file=None):for file in glob.glob("*.json") + glob.glob("*.log") + glob.glob("*.jsonl"):try:if jsonl_file is not None and file == jsonl_file:continueos.remove(file)except Exception as e:print(f"Error during cleanup of {file}: {e}")29 unmodified linesdef stream_logs(command, jsonl_file=None):global is_runninglocal_filename = Noneif jsonl_file is not None:local_filename = os.path.basename(jsonl_file.name)if is_running:yield "A command is already running. Please wait for it to finish.\n"returncleanup_previous_files(local_filename)yield "Cleaned up previous files.\n"log_content = []1 unmodified linelog_content.append(log_line)yield "".join(log_content)with gr.Blocks() as demo:gr.Markdown("# BigCodeBench Evaluator")17 unmodified linescommand_output = gr.Textbox(label="Command", value=default_command, interactive=False)with gr.Row():submit_btn = gr.Button("Run Evaluation")download_btn = gr.DownloadButton(label="Download Result", visible=False)log_output = gr.Textbox(label="Execution Logs", lines=20)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,1 unmodified line]for component in input_components:component.change(update_command, inputs=input_components, outputs=command_output)def start_evaluation(command, jsonl_file):for log in stream_logs(command, jsonl_file):yield log, gr.update(), gr.update()result_file = find_result_file()if result_file:print(f"Result file: {result_file}")return (gr.update(label="Evaluation completed. Result file found."),gr.Button(visible=False),gr.DownloadButton(label="Download Result", value=result_file, visible=True))else:return (gr.update(label="Evaluation completed. No result file found."),gr.Button("Run Evaluation", visible=True),gr.DownloadButton(visible=False))submit_btn.click(start_evaluation,inputs=[command_output, jsonl_file],outputs=[log_output, submit_btn, download_btn])if __name__ == "__main__":demo.queue(max_size=300).launch(server_name="0.0.0.0", server_port=7860)scheduler = BackgroundScheduler()scheduler.add_job(restart_space, "interval", hours=3) # restarted every 3h as backup in case automatic updates are not workingscheduler.start()49 unmodified lines50515253545556575859606129 unmodified lines9192939495969798991001011021 unmodified line10410510610710810917 unmodified lines1271281291301311321331341351 unmodified line13713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616749 unmodified linesreturn " ".join(command)def cleanup_previous_files(jsonl_file):file_list = ['Dockerfile', 'app.py', 'README.md', os.path.basename(jsonl_file.name), "__pycache__"]for file in glob.glob("*"):try:if file not in file_list:os.remove(file)except Exception as e:print(f"Error during cleanup of {file}: {e}")29 unmodified linesdef stream_logs(command, jsonl_file=None):global is_runningif is_running:yield "A command is already running. Please wait for it to finish.\n"returncleanup_previous_files(jsonl_file)yield "Cleaned up previous files.\n"log_content = []1 unmodified linelog_content.append(log_line)yield "".join(log_content)with gr.Blocks() as demo:gr.Markdown("# BigCodeBench Evaluator")17 unmodified linescommand_output = gr.Textbox(label="Command", value=default_command, interactive=False)with gr.Row():submit_btn = gr.Button("Run Evaluation")download_btn = gr.DownloadButton(label="Download Result")log_output = gr.Textbox(label="Execution Logs", lines=20)input_components = [jsonl_file, split, subset, save_pass_rate, parallel,min_time_limit, max_as_limit, max_data_limit, max_stack_limit,1 unmodified line]for component in input_components:component.change(generate_command, inputs=input_components, outputs=command_output)def start_evaluation(command, jsonl_file, subset, split):extra = subset + "_" if subset != "full" else ""result_path = os.path.basename(jsonl_file.name).replace(".jsonl", f"_{extra}eval_results.json")with open(result_path, "w") as f:f.write("")for log in stream_logs(command, jsonl_file):yield log, gr.update(value=result_path, label=result_path), gr.update()result_file = find_result_file()if result_file:return gr.update(label="Evaluation completed. Result file found."), gr.update(value=result_file)# gr.Button(visible=False)#,# gr.DownloadButton(label="Download Result", value=result_file, visible=True))else:return gr.update(label="Evaluation completed. No result file found."), gr.update(value=result_path)# gr.Button("Run Evaluation", visible=True),# gr.DownloadButton(visible=False))submit_btn.click(start_evaluation,inputs=[command_output, jsonl_file, subset, split],outputs=[log_output, download_btn])if __name__ == "__main__":demo.queue(max_size=300).launch(share=True, server_name="0.0.0.0", server_port=7860)scheduler = BackgroundScheduler()
app.py+25-31