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 gradio as gr
|
||||||
|
import subprocess
|
||||||
|
|
||||||
def run_eval(inputs, native, other, outputs, api_url, api_token):
|
def run_eval(inputs, native, other, outputs, api_url, api_token):
|
||||||
result = (
|
# 构造命令
|
||||||
f"\n[Eval Started]\n"
|
command = [
|
||||||
f"Inputs: {inputs}\n"
|
"evalscope", "perf",
|
||||||
f"API URL: {api_url}\n"
|
"--parallel", "20",
|
||||||
f"API Token: {api_token}\n"
|
"--model", "Qwen2.5-0.5B-Instruct",
|
||||||
f"Native Modules: {native}\n"
|
"--url", api_url.strip(),
|
||||||
f"Other Backends: {other}\n"
|
"--api", "openai",
|
||||||
f"Outputs: {outputs}\n"
|
"--token", api_token.strip(),
|
||||||
f"[Eval Finished]"
|
"--dataset", "random",
|
||||||
)
|
"--min-tokens", "128",
|
||||||
return result
|
"--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):
|
def enforce_input_exclusive_and_toggle_fields(selected):
|
||||||
group1 = {"API Models", "Local Models"}
|
group1 = {"API Models", "Local Models"}
|
||||||
|
|
@ -19,7 +39,7 @@ def enforce_input_exclusive_and_toggle_fields(selected):
|
||||||
|
|
||||||
def keep_only_one(group):
|
def keep_only_one(group):
|
||||||
filtered = [item for item in selected if item in group]
|
filtered = [item for item in selected if item in group]
|
||||||
return filtered[-1:] # 保留最后一个
|
return filtered[-1:]
|
||||||
|
|
||||||
final_selection = set(selected)
|
final_selection = set(selected)
|
||||||
final_selection -= group1
|
final_selection -= group1
|
||||||
|
|
@ -32,7 +52,7 @@ def enforce_input_exclusive_and_toggle_fields(selected):
|
||||||
|
|
||||||
return (
|
return (
|
||||||
gr.update(value=list(final_selection)),
|
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:
|
with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
||||||
|
|
@ -68,9 +88,8 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
||||||
)
|
)
|
||||||
|
|
||||||
run_button = gr.Button("Run Evaluation")
|
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(
|
input_choices.change(
|
||||||
fn=enforce_input_exclusive_and_toggle_fields,
|
fn=enforce_input_exclusive_and_toggle_fields,
|
||||||
inputs=input_choices,
|
inputs=input_choices,
|
||||||
|
|
@ -78,16 +97,10 @@ with gr.Blocks(title="EvalScope 全功能界面") as demo:
|
||||||
)
|
)
|
||||||
|
|
||||||
run_button.click(
|
run_button.click(
|
||||||
run_eval,
|
fn=run_eval,
|
||||||
inputs=[
|
inputs=[input_choices, native_choices, other_choices, output_choices, api_url_input, api_token_input],
|
||||||
input_choices,
|
outputs=output_text,
|
||||||
native_choices,
|
show_progress=True
|
||||||
other_choices,
|
|
||||||
output_choices,
|
|
||||||
api_url_input,
|
|
||||||
api_token_input
|
|
||||||
],
|
|
||||||
outputs=output_text
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue