From 38f680e1eb2bf5ef7e621608e7b5c38dcbdd076a Mon Sep 17 00:00:00 2001 From: hailin Date: Tue, 8 Jul 2025 17:21:17 +0800 Subject: [PATCH] . --- gradio_ui.py | 99 ++++++++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/gradio_ui.py b/gradio_ui.py index e968c8e..92d7aab 100644 --- a/gradio_ui.py +++ b/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,45 +214,46 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo: "RAGAS", "MTEB/CMTEB"] ) - # ===== 运行参数 ===== - with gr.Accordion("运行参数(可选修改)", open=False): - with gr.Row(): - api_provider_dropdown = gr.Dropdown( - label="API Provider (--api)", - choices=["openai", "azure", "ollama", "gemini"], - value="openai" + # ===== 运行参数(可隐藏) ===== + with gr.Column(visible=False) as run_params_section: + with gr.Accordion("运行参数(可选修改)", open=False): + with gr.Row(): + api_provider_dropdown = gr.Dropdown( + label="API Provider (--api)", + 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( - label="评测数据集 (--dataset)", - choices=["openqa", "gsm8k", "mmlu", "truthfulqa"], - value="openqa" + 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 ) - 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( @@ -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(