This commit is contained in:
parent
3193ba42f9
commit
11b9bb2916
82
gradio_ui.py
82
gradio_ui.py
|
|
@ -104,10 +104,10 @@ def stop_eval():
|
|||
if current_process and current_process.poll() is None:
|
||||
try:
|
||||
pgid = os.getpgid(current_process.pid)
|
||||
os.killpg(pgid, signal.SIGINT) # ✅ 优雅终止
|
||||
os.killpg(pgid, signal.SIGINT)
|
||||
time.sleep(2)
|
||||
if current_process.poll() is None:
|
||||
os.killpg(pgid, signal.SIGKILL) # ❗ 强制终止
|
||||
os.killpg(pgid, signal.SIGKILL)
|
||||
return "[✅ 已发送终止信号 (SIGINT → SIGKILL fallback)]\n"
|
||||
except Exception as e:
|
||||
return f"[❌ 终止失败: {e}]\n"
|
||||
|
|
@ -117,7 +117,6 @@ def stop_eval():
|
|||
return "[⚠️ 无活动 evalscope 进程]\n"
|
||||
|
||||
|
||||
|
||||
# ---------------- Run/Stop 控制器 ----------------
|
||||
def toggle_run(
|
||||
inputs, native, other, output_choices,
|
||||
|
|
@ -128,13 +127,7 @@ def toggle_run(
|
|||
model_override,
|
||||
is_running
|
||||
):
|
||||
global should_stop # ✅ 加上这一行
|
||||
|
||||
# 🛑 判空逻辑:输入源 + 输出形式 至少一个
|
||||
if not inputs and not output_choices:
|
||||
msg = "[❌ 请选择至少一个输入源或输出形式]"
|
||||
return msg, False, gr.update(value="Run Evaluation")
|
||||
|
||||
global should_stop
|
||||
if not is_running:
|
||||
should_stop = False
|
||||
yield from run_eval(
|
||||
|
|
@ -150,6 +143,12 @@ def toggle_run(
|
|||
yield msg, False, gr.update(value="Run Evaluation")
|
||||
|
||||
|
||||
# ---------------- 禁用按钮逻辑 ----------------
|
||||
def update_button_enable(inputs, outputs):
|
||||
enabled = bool(inputs or outputs)
|
||||
return gr.update(interactive=enabled)
|
||||
|
||||
|
||||
# ---------------- 互斥逻辑 ----------------
|
||||
def enforce_input_exclusive_and_toggle_fields(selected):
|
||||
order = ["API Models", "Local Models", "Benchmarks", "Custom Datasets"]
|
||||
|
|
@ -169,9 +168,7 @@ def enforce_input_exclusive_and_toggle_fields(selected):
|
|||
final_list = [itm for itm in order if itm in final_sel]
|
||||
|
||||
input_update = gr.update() if list(selected) == final_list else gr.update(value=final_list)
|
||||
|
||||
show_api_fields = "API Models" in final_sel
|
||||
api_field_update = gr.update(visible=show_api_fields) # ✅ 正确
|
||||
api_field_update = gr.update(visible="API Models" in final_sel)
|
||||
|
||||
return input_update, api_field_update
|
||||
|
||||
|
|
@ -180,7 +177,6 @@ def enforce_input_exclusive_and_toggle_fields(selected):
|
|||
with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
||||
is_running = gr.State(value=False)
|
||||
|
||||
# ===== 输入源 =====
|
||||
with gr.Group():
|
||||
with gr.Row():
|
||||
input_choices = gr.CheckboxGroup(
|
||||
|
|
@ -189,17 +185,9 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
|||
interactive=True
|
||||
)
|
||||
|
||||
# ===== API 地址 & 运行参数(统一控制显示) =====
|
||||
with gr.Column(visible=False) as api_fields:
|
||||
api_url_input = gr.Textbox(
|
||||
label="API 地址",
|
||||
placeholder="https://api.example.com/v1/chat"
|
||||
)
|
||||
api_token_input = gr.Textbox(
|
||||
label="Token 密钥",
|
||||
type="password",
|
||||
placeholder="sk-xxx"
|
||||
)
|
||||
api_url_input = gr.Textbox(label="API 地址", placeholder="https://api.example.com/v1/chat")
|
||||
api_token_input = gr.Textbox(label="Token 密钥", type="password", placeholder="sk-xxx")
|
||||
with gr.Accordion("运行参数(可选修改)", open=False):
|
||||
with gr.Row():
|
||||
api_provider_dropdown = gr.Dropdown(
|
||||
|
|
@ -217,29 +205,13 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
|||
placeholder="e.g. my-llm-7b"
|
||||
)
|
||||
with gr.Row():
|
||||
max_tokens_slider = gr.Slider(
|
||||
label="Max Tokens (--max-tokens)",
|
||||
minimum=256, maximum=8192, step=256, value=1024
|
||||
)
|
||||
min_tokens_slider = gr.Slider(
|
||||
label="Min Tokens (--min-tokens)",
|
||||
minimum=0, maximum=4096, step=64, value=1024
|
||||
)
|
||||
max_tokens_slider = gr.Slider("Max Tokens (--max-tokens)", 256, 8192, 256, value=1024)
|
||||
min_tokens_slider = gr.Slider("Min Tokens (--min-tokens)", 0, 4096, 64, value=1024)
|
||||
with gr.Row():
|
||||
parallel_slider = gr.Slider(
|
||||
label="并发请求数 (--parallel)",
|
||||
minimum=1, maximum=16, step=1, value=1
|
||||
)
|
||||
num_req_slider = gr.Slider(
|
||||
label="请求条数 (--number)",
|
||||
minimum=1, maximum=1000, step=1, value=100
|
||||
)
|
||||
max_prompt_len_slider = gr.Slider(
|
||||
label="最大 Prompt 长度 (--max-prompt-length)",
|
||||
minimum=2048, maximum=32768, step=512, value=15360
|
||||
)
|
||||
parallel_slider = gr.Slider("并发请求数 (--parallel)", 1, 16, 1, value=1)
|
||||
num_req_slider = gr.Slider("请求条数 (--number)", 1, 1000, 1, value=100)
|
||||
max_prompt_len_slider = gr.Slider("最大 Prompt 长度 (--max-prompt-length)", 2048, 32768, 512, value=15360)
|
||||
|
||||
# ===== 本地/外部组件 =====
|
||||
with gr.Row():
|
||||
with gr.Column():
|
||||
native_choices = gr.CheckboxGroup(
|
||||
|
|
@ -252,14 +224,13 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
|||
choices=["OpenCompass", "VLMEvalKit", "RAGAS", "MTEB/CMTEB"]
|
||||
)
|
||||
|
||||
# ===== 输出形式 =====
|
||||
output_choices = gr.CheckboxGroup(
|
||||
label="输出形式",
|
||||
choices=["Evaluation Report", "Gradio", "WandB", "Swanlab"]
|
||||
)
|
||||
|
||||
# ===== 控制按钮 & 日志 =====
|
||||
run_button = gr.Button("Run Evaluation")
|
||||
run_button = gr.Button("Run Evaluation", interactive=False)
|
||||
|
||||
output_text = gr.TextArea(
|
||||
label="执行结果",
|
||||
lines=20,
|
||||
|
|
@ -267,11 +238,22 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
|||
show_copy_button=True
|
||||
)
|
||||
|
||||
# ===== 绑定事件 =====
|
||||
input_choices.change(
|
||||
fn=enforce_input_exclusive_and_toggle_fields,
|
||||
inputs=input_choices,
|
||||
outputs=[input_choices, api_fields] # ✅ 只输出这两个
|
||||
outputs=[input_choices, api_fields]
|
||||
)
|
||||
|
||||
input_choices.change(
|
||||
fn=update_button_enable,
|
||||
inputs=[input_choices, output_choices],
|
||||
outputs=run_button
|
||||
)
|
||||
|
||||
output_choices.change(
|
||||
fn=update_button_enable,
|
||||
inputs=[input_choices, output_choices],
|
||||
outputs=run_button
|
||||
)
|
||||
|
||||
run_button.click(
|
||||
|
|
|
|||
Loading…
Reference in New Issue