This commit is contained in:
parent
3722aafdd1
commit
38f680e1eb
27
gradio_ui.py
27
gradio_ui.py
|
|
@ -134,14 +134,19 @@ def toggle_run(
|
|||
|
||||
# ---------------- 互斥逻辑 ----------------
|
||||
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"]
|
||||
group1 = {"API Models", "Local Models"}
|
||||
group2 = {"Benchmarks", "Custom Datasets"}
|
||||
|
||||
# 在每个互斥组里仅保留最后一次点选的项
|
||||
def keep_only_one(group):
|
||||
filtered = [item for item in selected if item in group]
|
||||
return filtered[-1:] # 最后一个(空 list 亦可)
|
||||
return filtered[-1:]
|
||||
|
||||
final_sel = set(selected)
|
||||
final_sel -= group1
|
||||
|
|
@ -149,20 +154,23 @@ def enforce_input_exclusive_and_toggle_fields(selected):
|
|||
final_sel -= group2
|
||||
final_sel |= set(keep_only_one(group2))
|
||||
|
||||
# ① 保证输出顺序固定
|
||||
final_list = [itm for itm in order if itm in final_sel]
|
||||
|
||||
# ② 只有真正变化时才更新,避免死循环
|
||||
# ① 输入框更新(仅在变化时才触发)
|
||||
if list(selected) == final_list:
|
||||
input_update = gr.update() # 不带 value => 不触发二次 change
|
||||
input_update = gr.update()
|
||||
else:
|
||||
input_update = gr.update(value=final_list)
|
||||
|
||||
# ② URL/Token 行仅在选中 API Models 时显示
|
||||
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 ----------------
|
||||
|
|
@ -206,7 +214,8 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
|||
"RAGAS", "MTEB/CMTEB"]
|
||||
)
|
||||
|
||||
# ===== 运行参数 =====
|
||||
# ===== 运行参数(可隐藏) =====
|
||||
with gr.Column(visible=False) as run_params_section:
|
||||
with gr.Accordion("运行参数(可选修改)", open=False):
|
||||
with gr.Row():
|
||||
api_provider_dropdown = gr.Dropdown(
|
||||
|
|
@ -265,7 +274,7 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
|||
input_choices.change(
|
||||
fn=enforce_input_exclusive_and_toggle_fields,
|
||||
inputs=input_choices,
|
||||
outputs=[input_choices, api_fields]
|
||||
outputs=[input_choices, api_fields, run_params_section]
|
||||
)
|
||||
|
||||
run_button.click(
|
||||
|
|
|
|||
Loading…
Reference in New Issue