This commit is contained in:
parent
85d16ef782
commit
6f1c422871
63
gradio_ui.py
63
gradio_ui.py
|
|
@ -1,17 +1,37 @@
|
|||
import gradio as gr
|
||||
import subprocess
|
||||
|
||||
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"
|
||||
f"[Eval Finished]"
|
||||
)
|
||||
return result
|
||||
# 构造命令
|
||||
command = [
|
||||
"evalscope", "perf",
|
||||
"--parallel", "20",
|
||||
"--model", "Qwen2.5-0.5B-Instruct",
|
||||
"--url", api_url.strip(),
|
||||
"--api", "openai",
|
||||
"--token", api_token.strip(),
|
||||
"--dataset", "random",
|
||||
"--min-tokens", "128",
|
||||
"--max-tokens", "128",
|
||||
"--prefix-length", "64",
|
||||
"--min-prompt-length", "1024",
|
||||
"--max-prompt-length", "2048",
|
||||
"--number", "100",
|
||||
"--tokenizer-path", "Qwen/Qwen2.5-0.5B-Instruct",
|
||||
"--debug"
|
||||
]
|
||||
|
||||
# 执行并流式输出
|
||||
yield "[Eval Started]\n"
|
||||
try:
|
||||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1)
|
||||
for line in process.stdout:
|
||||
yield line
|
||||
process.stdout.close()
|
||||
process.wait()
|
||||
except Exception as e:
|
||||
yield f"[Error] {str(e)}\n"
|
||||
yield "[Eval Finished]"
|
||||
|
||||
def enforce_input_exclusive_and_toggle_fields(selected):
|
||||
group1 = {"API Models", "Local Models"}
|
||||
|
|
@ -19,7 +39,7 @@ def enforce_input_exclusive_and_toggle_fields(selected):
|
|||
|
||||
def keep_only_one(group):
|
||||
filtered = [item for item in selected if item in group]
|
||||
return filtered[-1:] # 保留最后一个
|
||||
return filtered[-1:]
|
||||
|
||||
final_selection = set(selected)
|
||||
final_selection -= group1
|
||||
|
|
@ -32,7 +52,7 @@ def enforce_input_exclusive_and_toggle_fields(selected):
|
|||
|
||||
return (
|
||||
gr.update(value=list(final_selection)),
|
||||
gr.Row.update(visible=show_api_fields) # ✅ 用 Row 的更新
|
||||
gr.Row.update(visible=show_api_fields)
|
||||
)
|
||||
|
||||
with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
||||
|
|
@ -68,9 +88,8 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
|||
)
|
||||
|
||||
run_button = gr.Button("Run Evaluation")
|
||||
output_text = gr.Textbox(label="执行结果", lines=10)
|
||||
output_text = gr.Textbox(label="执行结果", lines=20, interactive=False)
|
||||
|
||||
# ✅ 绑定变化,更新互斥选项与 API 表单显示
|
||||
input_choices.change(
|
||||
fn=enforce_input_exclusive_and_toggle_fields,
|
||||
inputs=input_choices,
|
||||
|
|
@ -78,16 +97,10 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
|||
)
|
||||
|
||||
run_button.click(
|
||||
run_eval,
|
||||
inputs=[
|
||||
input_choices,
|
||||
native_choices,
|
||||
other_choices,
|
||||
output_choices,
|
||||
api_url_input,
|
||||
api_token_input
|
||||
],
|
||||
outputs=output_text
|
||||
fn=run_eval,
|
||||
inputs=[input_choices, native_choices, other_choices, output_choices, api_url_input, api_token_input],
|
||||
outputs=output_text,
|
||||
show_progress=True
|
||||
)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Reference in New Issue