This commit is contained in:
hailin 2025-07-27 17:05:54 +08:00
parent 34c0c43673
commit 8f12b8269a
1 changed files with 19 additions and 21 deletions

View File

@ -114,7 +114,7 @@ with gr.Blocks(title="调试界面") as demo:
# 采样参数控件
with gr.Row():
max_new = gr.Slider(32, 32768, 2048, label="max_new_tokens")
max_new = gr.Slider(32, 32768, 128, label="max_new_tokens")
temp = gr.Slider(0, 1.5, 0.8, step=0.05, label="temperature")
with gr.Row():
top_p = gr.Slider(0, 1, 0.95, step=0.01, label="top_p")
@ -124,31 +124,29 @@ with gr.Blocks(title="调试界面") as demo:
pres_pen= gr.Slider(0, 2, 0.0, step=0.05, label="presence_penalty")
stop_txt = gr.Textbox("", label="stop 序列(逗号分隔)")
dbg_chk = gr.Checkbox(label="📜 显示 Debug 面板", value=True)
log_box = gr.Textbox(label="实时日志", lines=20, interactive=False, visible=True)
log_state= gr.State("") # 保存全部日志文本
log_state = gr.State("") # 状态透传
dbg_chk = gr.Checkbox(label="📜 显示 Debug 面板", value=False) # ✅ 默认关闭
log_box = gr.Textbox(label="实时日志", lines=20, interactive=False, visible=False) # ✅ 默认隐藏
# ────────────── 定时刷新日志 ──────────────
timer = gr.Timer(1.0, render=True) # ✅ 这是关键
timer.tick( # ✅ 不依赖 log_state
fn=consume_logs,
inputs=[], # ✅ 空输入,避免绑定 UI 焦点
outputs=[log_box], # ✅ 强制刷新 log_box
)
# 显示到 log_box
log_state.change(lambda txt: gr.update(value=txt), log_state, log_box)
# Debug 面板可见性切换
dbg_chk.change(lambda v: gr.update(visible=v), dbg_chk, log_box)
# Chatbot
# Chat 界面(移到日志之前)
chatbot = gr.ChatInterface(
fn=chat,
additional_inputs=[max_new, temp, top_p, top_k,
rep_pen, pres_pen, stop_txt, log_state],
additional_outputs=[log_state], # ★ 必加
additional_outputs=[log_state],
type="messages"
)
# 日志刷新定时器
timer = gr.Timer(1.0, render=True)
timer.tick(
fn=consume_logs,
inputs=[],
outputs=[log_box],
)
log_state.change(lambda txt: gr.update(value=txt), log_state, log_box)
dbg_chk.change(lambda v: gr.update(visible=v), dbg_chk, log_box)
demo.launch(server_name="0.0.0.0", server_port=30001)