Spaces:
Sleeping
Sleeping
databoysu commited on
Commit ·
e5add8c
1
Parent(s): b45a9cb
UI reset
Browse files30 unmodified lines31323334353637249 unmodified lines28728828929029129229312 unmodified lines3063073083093103111 unmodified line3133143153163173183193203213223233243253263273283293303313323333343353363373383398 unmodified lines34834935035135235335435535635735835936036136236336436536622 unmodified lines38939039139239339439535 unmodified lines4314324334344354364374384394409 unmodified lines4504514524534544554564574584594604614624634644653 unmodified lines46947047147247347447521 unmodified lines4974984995005015025039 unmodified lines5135145155165175185195205215225235245255265275285299 unmodified lines5395405415425435445455465475487 unmodified lines55655755855956056156256310 unmodified lines57457557657757830 unmodified linesROOT_DIR = Path(__file__).resolve().parentINFERENCE_PATH = ROOT_DIR / "inference.py"BACKEND_HOST = "127.0.0.1"BACKEND_PORT = 8000GRADIO_HOST = "0.0.0.0"GRADIO_PORT = 7860249 unmodified linesdef sync_tasks(selected, grid_name):# Depending on which grid was clicked, clear the others and fetch codeif grid_name == "easy":easy_val = selectedmed_val = None12 unmodified linescode_content = _code_from_task_name(selected)hud_content = _update_hud_badge(selected, diff)return (selected,1 unmodified linegr.update(value=med_val),gr.update(value=hard_val),hud_content,code_content)def validate_and_start(token):if not token or not token.strip():# Empty token: halt execution, render alert, push an error state earlyreturn (gr.update(elem_classes=["token-alert"]),gr.update(value="ERROR: Token Required"),False)# Valid tokenreturn (gr.update(elem_classes=[]),gr.update(value="RUNNING...", elem_id="execute-btn-running", interactive=False),True)def _reset_run_state(task_name):return (_code_from_task_name(task_name),_terminal_html([("c-muted", "Boot sequence initialized...")]),"<div style='text-align: center; color: var(--text-dim); padding: 20px;'>Running...</div>")8 unmodified linessuccess_score_threshold: float,show_thought: bool,proceed: bool) -> Generator[tuple[str, str, str, dict], None, None]:if not proceed:# User didn't pass auth checkyield (gr.skip(), gr.skip(), gr.skip(), gr.update(value="Run Debugging Agent", interactive=True))returncode_view = _code_from_task_name(task_name)terminal_lines: list[tuple[str, str]] = []terminal_lines.append(("c-muted", "Agent initialized... infiltrating target."))result_html = "<div style='text-align: center; color: var(--text-dim); padding: 20px;'>Awaiting end...</div>"yield code_view, _terminal_html(terminal_lines), result_html, gr.update()cmd = [sys.executable, str(INFERENCE_PATH)]if show_thought:22 unmodified linesended_streams: set[str] = set()thought_mode = Falseactive_task_name = task_namewhile True:try:35 unmodified linesend_match = END_RE.match(line)if start_match:active_task_name = start_match.group("task").strip()task_preview = _code_from_task_name(active_task_name)if "Waiting for selection" not in task_preview:code_view = task_previewterminal_lines.append(("c-start", line))elif step_match:err = step_match.group("error")9 unmodified linesresult_html = _large_metric_html(success, score_value, final_steps, rewards_raw or 'none')if success:solved = _solution_from_task_name(active_task_name)if solved:code_view = solvedelse:terminal_lines.append(("c-muted", line))if len(terminal_lines) > 500:terminal_lines = terminal_lines[-500:]yield code_view, _terminal_html(terminal_lines), result_html, gr.update()return_code = process.wait(timeout=2)if return_code != 0:3 unmodified linesif len(terminal_lines) > 500:terminal_lines = terminal_lines[-500:]yield code_view, _terminal_html(terminal_lines), result_html, gr.update(value="Run Debugging Agent", elem_id="execute-btn", interactive=True)with gr.Blocks(title="TraceFix-RL") as demo:21 unmodified lineswith gr.Accordion("Engine Parameters", open=False):model_name = gr.Textbox(label="Model Name", value=os.getenv("MODEL_NAME", "openai/gpt-oss-20b"))api_base_url = gr.Textbox(label="API Base URL", value=os.getenv("API_BASE_URL", "https://router.huggingface.co/v1"))env_base_url = gr.Textbox(label="Env Base URL", value=os.getenv("ENV_BASE_URL", f"http://{BACKEND_HOST}:{BACKEND_PORT}"))max_steps = gr.Number(label="Max Steps", value=int(os.getenv("MAX_STEPS", "50")), precision=0)success_score_threshold = gr.Number(label="Success Score Threshold",9 unmodified lineshard_radio = gr.Radio(choices=HARD_CHOICES, label="Hard Targets", elem_id="hard-radio")hud_badge = gr.HTML(_update_hud_badge("", ""))run_button = gr.Button("Run Debugging Agent", elem_id="execute-btn", variant="primary")# Sync tasks correctlyeasy_radio.change(lambda x: sync_tasks(x, "easy"), inputs=[easy_radio], outputs=[selected_task_state, easy_radio, medium_radio, hard_radio, hud_badge, code_view] if 'code_view' in locals() else None)medium_radio.change(lambda x: sync_tasks(x, "medium"), inputs=[medium_radio], outputs=[selected_task_state, easy_radio, medium_radio, hard_radio, hud_badge, code_view] if 'code_view' in locals() else None)hard_radio.change(lambda x: sync_tasks(x, "hard"), inputs=[hard_radio], outputs=[selected_task_state, easy_radio, medium_radio, hard_radio, hud_badge, code_view] if 'code_view' in locals() else None)with gr.Row(equal_height=True):with gr.Column(scale=1, elem_classes=["panel", "code-panel"]):gr.HTML("<div class='panel-title'>Sandbox Source Code</div>")code_view = gr.Code(language="python",interactive=False,9 unmodified lineswith gr.Row(elem_classes=["panel"]):result_block = gr.HTML("<div style='text-align: center; color: var(--text-dim); padding: 20px;'>Awaiting Execution</div>")# Due to 'code_view' not being defined above when change was defined, we must re-bind the change events to include code_view.easy_radio.change(lambda x: sync_tasks(x, "easy"), inputs=[easy_radio], outputs=[selected_task_state, easy_radio, medium_radio, hard_radio, hud_badge, code_view])medium_radio.change(lambda x: sync_tasks(x, "medium"), inputs=[medium_radio], outputs=[selected_task_state, easy_radio, medium_radio, hard_radio, hud_badge, code_view])hard_radio.change(lambda x: sync_tasks(x, "hard"), inputs=[hard_radio], outputs=[selected_task_state, easy_radio, medium_radio, hard_radio, hud_badge, code_view])# Run Sequencerun_state = gr.State(value=True)7 unmodified linesreset_step = validate_step.then(_reset_run_state,inputs=[selected_task_state],outputs=[code_view, terminal, result_block],queue=False,)10 unmodified linesshow_thought,run_state],outputs=[code_view, terminal, result_block, run_button],)30 unmodified lines31323334353637249 unmodified lines28728828929029129212 unmodified lines3053063073083093103111 unmodified line3133143153163173183193203213223233243253263273283293303313323333343353363378 unmodified lines34634734834935035135235335435535635735835936036136222 unmodified lines38538638738838939039139239335 unmodified lines4294304314324334349 unmodified lines4444454464474484494504514524534544554564574584594603 unmodified lines46446546646746846947047147247347447547621 unmodified lines4984995005015025035049 unmodified lines5145155165175185195205215225235249 unmodified lines5345355365375385395405415427 unmodified lines55055155255355455555655710 unmodified lines56856957057157230 unmodified linesROOT_DIR = Path(__file__).resolve().parentINFERENCE_PATH = ROOT_DIR / "inference.py"BACKEND_HOST = "127.0.0.1"BACKEND_PORT = 7860GRADIO_HOST = "0.0.0.0"GRADIO_PORT = 7860249 unmodified linesdef sync_tasks(selected, grid_name):if grid_name == "easy":easy_val = selectedmed_val = None12 unmodified linescode_content = _code_from_task_name(selected)hud_content = _update_hud_badge(selected, diff)title_content = "<div class='panel-title'>Target Source Code (Buggy)</div>"return (selected,1 unmodified linegr.update(value=med_val),gr.update(value=hard_val),hud_content,title_content,code_content)def validate_and_start(token):if not token or not token.strip():return (gr.update(elem_classes=["token-alert"]),gr.update(value="ERROR: Token Required"),False)return (gr.update(elem_classes=[]),gr.update(value="RUNNING...", elem_id="execute-btn-running", interactive=False),True)def _reset_run_state():return (_terminal_html([("c-muted", "Boot sequence initialized...")]),"<div style='text-align: center; color: var(--text-dim); padding: 20px;'>Running...</div>")8 unmodified linessuccess_score_threshold: float,show_thought: bool,proceed: bool) -> Generator[tuple[Any, str, str, dict, Any], None, None]:if not proceed:yield (gr.skip(), gr.skip(), gr.skip(), gr.update(value="INITIATE TRACE RESOLUTION", interactive=True), gr.skip())returnterminal_lines: list[tuple[str, str]] = []terminal_lines.append(("c-muted", "Agent initialized... infiltrating target."))result_html = "<div style='text-align: center; color: var(--text-dim); padding: 20px;'>Awaiting end...</div>"yield gr.skip(), _terminal_html(terminal_lines), result_html, gr.update(), gr.skip()cmd = [sys.executable, str(INFERENCE_PATH)]if show_thought:22 unmodified linesended_streams: set[str] = set()thought_mode = Falsefinal_success = Falsefinal_solved_code = Nonewhile True:try:35 unmodified linesend_match = END_RE.match(line)if start_match:terminal_lines.append(("c-start", line))elif step_match:err = step_match.group("error")9 unmodified linesresult_html = _large_metric_html(success, score_value, final_steps, rewards_raw or 'none')if success:final_success = Truesolved = _solution_from_task_name(task_name)if solved:final_solved_code = solvedelse:terminal_lines.append(("c-muted", line))if len(terminal_lines) > 500:terminal_lines = terminal_lines[-500:]yield gr.skip(), _terminal_html(terminal_lines), result_html, gr.update(), gr.skip()return_code = process.wait(timeout=2)if return_code != 0:3 unmodified linesif len(terminal_lines) > 500:terminal_lines = terminal_lines[-500:]code_update = gr.skip()title_update = gr.skip()if final_success and final_solved_code is not None:code_update = final_solved_codetitle_update = "<div class='panel-title'>Target Source Code (Resolved)</div>"yield code_update, _terminal_html(terminal_lines), result_html, gr.update(value="INITIATE TRACE RESOLUTION", elem_id="execute-btn", interactive=True), title_updatewith gr.Blocks(title="TraceFix-RL") as demo:21 unmodified lineswith gr.Accordion("Engine Parameters", open=False):model_name = gr.Textbox(label="Model Name", value=os.getenv("MODEL_NAME", "openai/gpt-oss-20b"))api_base_url = gr.Textbox(label="API Base URL", value=os.getenv("API_BASE_URL", "https://router.huggingface.co/v1"))env_base_url = gr.Textbox(label="Env Base URL", value=os.getenv("ENV_BASE_URL", f"http://127.0.0.1:{BACKEND_PORT}"))max_steps = gr.Number(label="Max Steps", value=int(os.getenv("MAX_STEPS", "50")), precision=0)success_score_threshold = gr.Number(label="Success Score Threshold",9 unmodified lineshard_radio = gr.Radio(choices=HARD_CHOICES, label="Hard Targets", elem_id="hard-radio")hud_badge = gr.HTML(_update_hud_badge("", ""))run_button = gr.Button("INITIATE TRACE RESOLUTION", elem_id="execute-btn", variant="primary")with gr.Row(equal_height=True):with gr.Column(scale=1, elem_classes=["panel", "code-panel"]):code_panel_title = gr.HTML("<div class='panel-title'>Target Source Code (Buggy)</div>")code_view = gr.Code(language="python",interactive=False,9 unmodified lineswith gr.Row(elem_classes=["panel"]):result_block = gr.HTML("<div style='text-align: center; color: var(--text-dim); padding: 20px;'>Awaiting Execution</div>")easy_radio.change(lambda x: sync_tasks(x, "easy"), inputs=[easy_radio], outputs=[selected_task_state, easy_radio, medium_radio, hard_radio, hud_badge, code_panel_title, code_view])medium_radio.change(lambda x: sync_tasks(x, "medium"), inputs=[medium_radio], outputs=[selected_task_state, easy_radio, medium_radio, hard_radio, hud_badge, code_panel_title, code_view])hard_radio.change(lambda x: sync_tasks(x, "hard"), inputs=[hard_radio], outputs=[selected_task_state, easy_radio, medium_radio, hard_radio, hud_badge, code_panel_title, code_view])# Run Sequencerun_state = gr.State(value=True)7 unmodified linesreset_step = validate_step.then(_reset_run_state,inputs=[],outputs=[terminal, result_block],queue=False,)10 unmodified linesshow_thought,run_state],outputs=[code_view, terminal, result_block, run_button, code_panel_title],)
vision_ui.py+30-36