This commit is contained in:
hailin 2025-07-08 13:50:53 +08:00
parent 7484f13400
commit 81b6f023f8
1 changed files with 8 additions and 3 deletions

View File

@ -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],