This commit is contained in:
parent
6d8fbdc748
commit
34c0c43673
30
meta_ui.py
30
meta_ui.py
|
|
@ -72,6 +72,9 @@ def chat(
|
|||
rep_pen, pres_pen, stop_raw,
|
||||
log_state
|
||||
):
|
||||
import threading
|
||||
from queue import Queue, Empty
|
||||
|
||||
stop = [s.strip() for s in stop_raw.split(",") if s.strip()] or None
|
||||
samp = {
|
||||
"max_new_tokens": int(max_new),
|
||||
|
|
@ -79,12 +82,31 @@ def chat(
|
|||
"top_p": top_p,
|
||||
"top_k": int(top_k),
|
||||
"repetition_penalty": rep_pen,
|
||||
"presence_penalty": pres_pen,
|
||||
"presence_penalty": pres_pen,
|
||||
**({"stop": stop} if stop else {})
|
||||
}
|
||||
out = backend(user, samp)
|
||||
# 返回回答,同时把 log_state 原样带回(不刷新由 Interval 处理)
|
||||
return out, log_state
|
||||
|
||||
result_q = Queue()
|
||||
|
||||
# 后台线程执行 backend 推理
|
||||
def worker():
|
||||
out = backend(user, samp)
|
||||
result_q.put(out)
|
||||
|
||||
thread = threading.Thread(target=worker)
|
||||
thread.start()
|
||||
|
||||
# 先返回提示
|
||||
yield "⏳ 正在生成中...", log_state
|
||||
|
||||
# 每 0.1 秒轮询结果队列(避免阻塞 UI)
|
||||
while thread.is_alive() or not result_q.empty():
|
||||
try:
|
||||
result = result_q.get(timeout=0.1)
|
||||
yield result, log_state
|
||||
except Empty:
|
||||
continue
|
||||
|
||||
|
||||
# ───────────────────── Gradio UI ─────────────────────
|
||||
with gr.Blocks(title="调试界面") as demo:
|
||||
|
|
|
|||
Loading…
Reference in New Issue