diff --git a/gradio_ui.py b/gradio_ui.py index 09dd7c0..406d884 100644 --- a/gradio_ui.py +++ b/gradio_ui.py @@ -53,13 +53,16 @@ def stop_eval(): return "[Stopped by user]\n" return "[No active process]\n" -# 按钮行为切换函数:Run / Stop +# ✅ 修改后的 toggle_run,必须是 generator,不能 return,要 yield def toggle_run(inputs, native, other, outputs, api_url, api_token, is_running): if not is_running: - return run_eval(inputs, native, other, outputs, api_url, api_token), True, gr.update(value="Stop Evaluation") + # 运行任务并切换按钮为 Stop + yield from run_eval(inputs, native, other, outputs, api_url, api_token) + yield "", False, gr.update(value="Run Evaluation") # 运行结束后重置按钮 else: + # 用户点击 Stop,终止子进程 msg = stop_eval() - return msg, False, gr.update(value="Run Evaluation") + yield msg, False, gr.update(value="Run Evaluation") # 控制输入选项互斥逻辑 def enforce_input_exclusive_and_toggle_fields(selected): @@ -87,6 +90,7 @@ def enforce_input_exclusive_and_toggle_fields(selected): # 构建 Gradio 界面 with gr.Blocks(title="EvalScope 全功能界面") as demo: is_running = gr.State(value=False) # 当前运行状态 + with gr.Group(): with gr.Row(): input_choices = gr.CheckboxGroup( @@ -127,6 +131,7 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo: outputs=[input_choices, api_fields] ) + # ✅ 修改后的绑定,支持 Run / Stop 切换 run_button.click( fn=toggle_run, inputs=[input_choices, native_choices, other_choices, output_choices, api_url_input, api_token_input, is_running],