Spaces:
Runtime error
Runtime error
Terry Zhuo commited on
Commit ·
4e93785
1
Parent(s): a437a30
update
Browse files1235 unmodified lines910111213141516171848 unmodified lines676869707172733 unmodified lines7778798081828384858687888 unmodified lines97989910010110229 unmodified lines13213313413513613736 unmodified lines174175176177178import gradio as grimport subprocessimport sys5 unmodified linesimport shutilfrom pathlib import Pathfrom apscheduler.schedulers.background import BackgroundSchedulerdefault_command = "bigcodebench.evaluate"is_running = Falselock = threading.Lock()def generate_command(jsonl_file, split, subset, parallel,48 unmodified linesreturn Nonedef run_bigcodebench(command):global is_runningwith lock:if is_running:yield "A command is already running. Please wait for it to finish.\n"3 unmodified linestry:yield f"Executing command: {command}\n"process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)for line in process.stdout:yield line# process.wait()if process.returncode != 0:yield f"Error: Command exited with status {process.returncode}\n"8 unmodified linesfinally:with lock:is_running = Falsedef stream_logs(command, jsonl_file=None):global is_running29 unmodified linescheck_gt_only = gr.Checkbox(label="Check GT Only")no_gt = gr.Checkbox(label="No GT")command_output = gr.Textbox(label="Command", value=default_command, interactive=False)with gr.Row():submit_btn = gr.Button("Run Evaluation")36 unmodified linesinputs=[command_output, jsonl_file, subset, split],outputs=[log_output, download_btn])demo.queue(max_size=300).launch(share=True, server_name="0.0.0.0", server_port=7860)scheduler = BackgroundScheduler()12345 unmodified lines1011121314151617181920212223242548 unmodified lines747576777879803 unmodified lines8485868788899091929394958 unmodified lines10410510610710810911011111211311411511629 unmodified lines14614714814915015115215315415515615715815916016116216316416516616716816936 unmodified lines206207208209210211212213214215216217218219220221222223224225226from fastapi import FastAPIimport gradio as grimport subprocessimport sys5 unmodified linesimport shutilfrom pathlib import Pathfrom apscheduler.schedulers.background import BackgroundSchedulerimport signalimport uvicorndefault_command = "bigcodebench.evaluate"is_running = Falselock = threading.Lock()process = Noneapp = FastAPI()def generate_command(jsonl_file, split, subset, parallel,48 unmodified linesreturn Nonedef run_bigcodebench(command):global is_running, processwith lock:if is_running:yield "A command is already running. Please wait for it to finish.\n"3 unmodified linestry:yield f"Executing command: {command}\n"process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, preexec_fn=os.setsid)for line in process.stdout:yield lineprocess.wait()if process.returncode != 0:yield f"Error: Command exited with status {process.returncode}\n"8 unmodified linesfinally:with lock:is_running = Falseprocess = Nonedef kill_process():global processif process:os.killpg(os.getpgid(process.pid), signal.SIGTERM)process = Nonedef stream_logs(command, jsonl_file=None):global is_running29 unmodified linescheck_gt_only = gr.Checkbox(label="Check GT Only")no_gt = gr.Checkbox(label="No GT")kill_process_btn = gr.Button("Kill Process", visible=False)kill_process_btn.click(kill_process)# Add this JavaScript to handle window closinggr.HTML("""<script>window.addEventListener('beforeunload', function (e) {fetch('/kill_process', {method: 'POST',headers: {'Content-Type': 'application/json',},body: JSON.stringify({}),});});</script>""")command_output = gr.Textbox(label="Command", value=default_command, interactive=False)with gr.Row():submit_btn = gr.Button("Run Evaluation")36 unmodified linesinputs=[command_output, jsonl_file, subset, split],outputs=[log_output, download_btn])@app.get("/")def read_main():return {"message": "This is your main app"}@app.post("/kill_process")async def api_kill_process():kill_process()return {"status": "success"}# demo.queue(max_size=300).launch(# share=True,# server_name="0.0.0.0",# server_port=7860,# additional_routes={"/kill_process": kill_process_api}# )app = gr.mount_gradio_app(app, demo, path="/gradio")uvicorn.run(app, host="0.0.0.0", port=7860)scheduler = BackgroundScheduler()
app.py+52-4