Spaces:
Runtime error
Runtime error
Terry Zhuo commited on
Commit ·
c19490f
1
Parent(s): b31403f
update
Browse files11235 unmodified lines910111314151213141520212216171848 unmodified lines67686977707172733 unmodified lines77787987808182838492858687888 unmodified lines97989910710810911011111211310010110229 unmodified lines13213313414915015115215315415515615715815916016116216316416516613513613736 unmodified lines174175176209210211212213214215216217218219220221177178from fastapi import FastAPIimport gradio as grimport subprocessimport sys5 unmodified linesimport shutilfrom pathlib import Pathfrom apscheduler.schedulers.background import BackgroundSchedulerimport signalimport uvicorn
default_command = "bigcodebench.evaluate"is_running = Falselock = threading.Lock()process = None
app = FastAPI()
def generate_command( jsonl_file, split, subset, parallel,48 unmodified lines return None
def run_bigcodebench(command): global is_running, process global is_running with lock: if is_running: yield "A command is already running. Please wait for it to finish.\n"3 unmodified lines try: yield f"Executing command: {command}\n" process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, preexec_fn=os.setsid) process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) for line in process.stdout: yield line process.wait() # process.wait() if process.returncode != 0: yield f"Error: Command exited with status {process.returncode}\n"8 unmodified lines finally: with lock: is_running = False process = None
def kill_process(): global process if process: os.killpg(os.getpgid(process.pid), signal.SIGTERM) process = None
def stream_logs(command, jsonl_file=None): global is_running29 unmodified lines check_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 closing gr.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 lines inputs=[command_output, jsonl_file, subset, split], outputs=[log_output, download_btn])
@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)demo.queue(max_size=300).launch(share=True, server_name="0.0.0.0", server_port=7860)scheduler = BackgroundScheduler()app.py+4-48