This commit is contained in:
parent
8b8949779d
commit
3722aafdd1
32
gradio_ui.py
32
gradio_ui.py
|
|
@ -134,25 +134,35 @@ def toggle_run(
|
|||
|
||||
# ---------------- 互斥逻辑 ----------------
|
||||
def enforce_input_exclusive_and_toggle_fields(selected):
|
||||
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:]
|
||||
return filtered[-1:] # 最后一个(空 list 亦可)
|
||||
|
||||
final_selection = set(selected)
|
||||
final_selection -= group1
|
||||
final_selection |= set(keep_only_one(group1))
|
||||
final_sel = set(selected)
|
||||
final_sel -= group1
|
||||
final_sel |= set(keep_only_one(group1))
|
||||
final_sel -= group2
|
||||
final_sel |= set(keep_only_one(group2))
|
||||
|
||||
final_selection -= group2
|
||||
final_selection |= 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
|
||||
else:
|
||||
input_update = gr.update(value=final_list)
|
||||
|
||||
show_api_fields = "API Models" in final_sel
|
||||
row_update = gr.Row.update(visible=show_api_fields)
|
||||
|
||||
return input_update, row_update
|
||||
|
||||
show_api_fields = "API Models" in final_selection
|
||||
return (
|
||||
gr.update(value=list(final_selection)),
|
||||
gr.Row.update(visible=show_api_fields)
|
||||
)
|
||||
|
||||
|
||||
# ---------------- 构建 Gradio UI ----------------
|
||||
|
|
|
|||
Loading…
Reference in New Issue