This commit is contained in:
parent
3722aafdd1
commit
38f680e1eb
99
gradio_ui.py
99
gradio_ui.py
|
|
@ -134,14 +134,19 @@ def toggle_run(
|
||||||
|
|
||||||
# ---------------- 互斥逻辑 ----------------
|
# ---------------- 互斥逻辑 ----------------
|
||||||
def enforce_input_exclusive_and_toggle_fields(selected):
|
def enforce_input_exclusive_and_toggle_fields(selected):
|
||||||
|
"""
|
||||||
|
1. API Models / Local Models 二选一
|
||||||
|
2. Benchmarks / Custom Datasets 二选一
|
||||||
|
3. 保持顺序稳定,避免死循环
|
||||||
|
4. 根据选择决定 api_fields 和 run_params_section 的显隐
|
||||||
|
"""
|
||||||
order = ["API Models", "Local Models", "Benchmarks", "Custom Datasets"]
|
order = ["API Models", "Local Models", "Benchmarks", "Custom Datasets"]
|
||||||
group1 = {"API Models", "Local Models"}
|
group1 = {"API Models", "Local Models"}
|
||||||
group2 = {"Benchmarks", "Custom Datasets"}
|
group2 = {"Benchmarks", "Custom Datasets"}
|
||||||
|
|
||||||
# 在每个互斥组里仅保留最后一次点选的项
|
|
||||||
def keep_only_one(group):
|
def keep_only_one(group):
|
||||||
filtered = [item for item in selected if item in group]
|
filtered = [item for item in selected if item in group]
|
||||||
return filtered[-1:] # 最后一个(空 list 亦可)
|
return filtered[-1:]
|
||||||
|
|
||||||
final_sel = set(selected)
|
final_sel = set(selected)
|
||||||
final_sel -= group1
|
final_sel -= group1
|
||||||
|
|
@ -149,20 +154,23 @@ def enforce_input_exclusive_and_toggle_fields(selected):
|
||||||
final_sel -= group2
|
final_sel -= group2
|
||||||
final_sel |= set(keep_only_one(group2))
|
final_sel |= set(keep_only_one(group2))
|
||||||
|
|
||||||
# ① 保证输出顺序固定
|
|
||||||
final_list = [itm for itm in order if itm in final_sel]
|
final_list = [itm for itm in order if itm in final_sel]
|
||||||
|
|
||||||
# ② 只有真正变化时才更新,避免死循环
|
# ① 输入框更新(仅在变化时才触发)
|
||||||
if list(selected) == final_list:
|
if list(selected) == final_list:
|
||||||
input_update = gr.update() # 不带 value => 不触发二次 change
|
input_update = gr.update()
|
||||||
else:
|
else:
|
||||||
input_update = gr.update(value=final_list)
|
input_update = gr.update(value=final_list)
|
||||||
|
|
||||||
|
# ② URL/Token 行仅在选中 API Models 时显示
|
||||||
show_api_fields = "API Models" in final_sel
|
show_api_fields = "API Models" in final_sel
|
||||||
row_update = gr.Row.update(visible=show_api_fields)
|
api_row_update = gr.Row.update(visible=show_api_fields)
|
||||||
|
|
||||||
return input_update, row_update
|
# ③ 运行参数区域在选中 API Models 或 Local Models 时显示
|
||||||
|
show_run_params = bool(final_sel & {"API Models", "Local Models"})
|
||||||
|
run_params_update = gr.Column.update(visible=show_run_params)
|
||||||
|
|
||||||
|
return input_update, api_row_update, run_params_update
|
||||||
|
|
||||||
|
|
||||||
# ---------------- 构建 Gradio UI ----------------
|
# ---------------- 构建 Gradio UI ----------------
|
||||||
|
|
@ -206,45 +214,46 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
||||||
"RAGAS", "MTEB/CMTEB"]
|
"RAGAS", "MTEB/CMTEB"]
|
||||||
)
|
)
|
||||||
|
|
||||||
# ===== 运行参数 =====
|
# ===== 运行参数(可隐藏) =====
|
||||||
with gr.Accordion("运行参数(可选修改)", open=False):
|
with gr.Column(visible=False) as run_params_section:
|
||||||
with gr.Row():
|
with gr.Accordion("运行参数(可选修改)", open=False):
|
||||||
api_provider_dropdown = gr.Dropdown(
|
with gr.Row():
|
||||||
label="API Provider (--api)",
|
api_provider_dropdown = gr.Dropdown(
|
||||||
choices=["openai", "azure", "ollama", "gemini"],
|
label="API Provider (--api)",
|
||||||
value="openai"
|
choices=["openai", "azure", "ollama", "gemini"],
|
||||||
|
value="openai"
|
||||||
|
)
|
||||||
|
dataset_dropdown = gr.Dropdown(
|
||||||
|
label="评测数据集 (--dataset)",
|
||||||
|
choices=["openqa", "gsm8k", "mmlu", "truthfulqa"],
|
||||||
|
value="openqa"
|
||||||
|
)
|
||||||
|
model_override_input = gr.Textbox(
|
||||||
|
label="自定义模型名 (--model),留空则使用时间戳",
|
||||||
|
placeholder="e.g. my-llm-7b"
|
||||||
)
|
)
|
||||||
dataset_dropdown = gr.Dropdown(
|
with gr.Row():
|
||||||
label="评测数据集 (--dataset)",
|
max_tokens_slider = gr.Slider(
|
||||||
choices=["openqa", "gsm8k", "mmlu", "truthfulqa"],
|
label="Max Tokens (--max-tokens)",
|
||||||
value="openqa"
|
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():
|
||||||
|
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
|
||||||
)
|
)
|
||||||
model_override_input = gr.Textbox(
|
|
||||||
label="自定义模型名 (--model),留空则使用时间戳",
|
|
||||||
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
|
|
||||||
)
|
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|
||||||
# ===== 输出形式 =====
|
# ===== 输出形式 =====
|
||||||
output_choices = gr.CheckboxGroup(
|
output_choices = gr.CheckboxGroup(
|
||||||
|
|
@ -265,7 +274,7 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
||||||
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, run_params_section]
|
||||||
)
|
)
|
||||||
|
|
||||||
run_button.click(
|
run_button.click(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue