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