This commit is contained in:
hailin 2025-07-08 10:24:59 +08:00
parent 668da15a06
commit 9f6fe28212
1 changed files with 54 additions and 39 deletions

View File

@ -1,9 +1,11 @@
import gradio as gr
def run_eval(inputs, native, other, outputs):
def run_eval(inputs, native, other, outputs, api_url, api_token):
result = (
f"\n[Eval Started]\n"
f"Inputs: {inputs}\n"
f"API URL: {api_url}\n"
f"API Token: {api_token}\n"
f"Native Modules: {native}\n"
f"Other Backends: {other}\n"
f"Outputs: {outputs}\n"
@ -11,6 +13,29 @@ def run_eval(inputs, native, other, outputs):
)
return result
def enforce_input_exclusive_and_toggle_fields(selected):
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:] # 只保留最后一个
final_selection = set(selected)
final_selection -= group1
final_selection |= set(keep_only_one(group1))
final_selection -= group2
final_selection |= set(keep_only_one(group2))
show_api_fields = "API Models" in final_selection
return (
gr.update(value=list(final_selection)),
gr.update(visible=show_api_fields),
gr.update(visible=show_api_fields)
)
with gr.Blocks(title="EvalScope 全功能界面") as demo:
with gr.Group():
with gr.Row():
@ -20,54 +45,44 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo:
interactive=True
)
with gr.Row(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")
with gr.Row():
with gr.Column():
with gr.Group():
native_choices = gr.CheckboxGroup(
label="启用本地模块",
choices=["Model Adapter", "Data Adapter", "Evaluator", "Perf Monitor"]
)
native_choices = gr.CheckboxGroup(
label="启用本地模块",
choices=["Model Adapter", "Data Adapter", "Evaluator", "Perf Monitor"]
)
with gr.Column():
with gr.Group():
other_choices = gr.CheckboxGroup(
label="启用外部后端",
choices=["OpenCompass", "VLMEvalKit", "RAGAS", "MTEB/CMTEB"]
)
with gr.Group():
with gr.Row():
output_choices = gr.CheckboxGroup(
label="输出形式",
choices=["Evaluation Report", "Gradio", "WandB", "Swanlab"]
other_choices = gr.CheckboxGroup(
label="启用外部后端",
choices=["OpenCompass", "VLMEvalKit", "RAGAS", "MTEB/CMTEB"]
)
with gr.Row():
output_choices = gr.CheckboxGroup(
label="输出形式",
choices=["Evaluation Report", "Gradio", "WandB", "Swanlab"]
)
run_button = gr.Button("Run Evaluation")
output_text = gr.Textbox(label="执行结果", lines=10)
def enforce_input_exclusive(selected):
# 互斥组1
group1 = {"API Models", "Local Models"}
# 互斥组2
group2 = {"Benchmarks", "Custom Datasets"}
# 绑定输入源选择的变化,控制互斥+是否显示API字段
input_choices.change(
fn=enforce_input_exclusive_and_toggle_fields,
inputs=input_choices,
outputs=[input_choices, api_url_input, api_token_input]
)
# 判断是否需要清除某个组
def enforce_group_exclusive(group):
selected_set = set(selected)
selected_in_group = selected_set & group
if len(selected_in_group) > 1:
# 如果同时选中多个,就保留最后一个
last_selected = next((item for item in reversed(selected) if item in group), None)
return (selected_set - group) | {last_selected}
return selected_set
final_selection = enforce_group_exclusive(group1)
final_selection = enforce_group_exclusive(group2 | final_selection)
return list(final_selection)
input_choices.change(fn=enforce_input_exclusive, inputs=input_choices, outputs=input_choices)
run_button.click(run_eval, inputs=[input_choices, native_choices, other_choices, output_choices], outputs=output_text)
run_button.click(
run_eval,
inputs=[input_choices, native_choices, other_choices, output_choices, api_url_input, api_token_input],
outputs=output_text
)
if __name__ == '__main__':
demo.launch(server_name="0.0.0.0", server_port=7900)