delete stop button

This commit is contained in:
zjrwtx 2025-03-14 15:16:42 +08:00
parent 3c1539a31c
commit 68941aa1ff

View File

@ -285,7 +285,7 @@ def run_owl(question: str, example_module: str) -> Tuple[str, List[List[str]], s
Returns: Returns:
Tuple[...]: 回答聊天历史令牌计数状态 Tuple[...]: 回答聊天历史令牌计数状态
""" """
global CURRENT_PROCESS, STOP_REQUESTED, CONVERSATION_UPDATE_QUEUE global CURRENT_PROCESS, CONVERSATION_UPDATE_QUEUE
# 清空对话更新队列 # 清空对话更新队列
while not CONVERSATION_UPDATE_QUEUE.empty(): while not CONVERSATION_UPDATE_QUEUE.empty():
@ -294,9 +294,6 @@ def run_owl(question: str, example_module: str) -> Tuple[str, List[List[str]], s
except queue.Empty: except queue.Empty:
break break
# 重置停止标志
STOP_REQUESTED.clear()
# 验证输入 # 验证输入
if not validate_input(question): if not validate_input(question):
logging.warning("用户提交了无效的输入") logging.warning("用户提交了无效的输入")
@ -567,10 +564,7 @@ def create_ui():
# 创建一个实时日志更新函数 # 创建一个实时日志更新函数
def process_with_live_logs(question, module_name): def process_with_live_logs(question, module_name):
"""处理问题并实时更新日志和对话历史""" """处理问题并实时更新日志和对话历史"""
global CURRENT_PROCESS, STOP_REQUESTED, CONVERSATION_UPDATE_QUEUE global CURRENT_PROCESS, CONVERSATION_UPDATE_QUEUE
# 重置停止标志
STOP_REQUESTED.clear()
# 创建一个后台线程来处理问题 # 创建一个后台线程来处理问题
result_queue = queue.Queue() result_queue = queue.Queue()
@ -592,7 +586,7 @@ def create_ui():
# 移动到文件末尾 # 移动到文件末尾
f.seek(0, 2) f.seek(0, 2)
while not STOP_REQUESTED.is_set(): while True:
line = f.readline() line = f.readline()
if line: if line:
# 尝试多种模式来检测对话信息 # 尝试多种模式来检测对话信息
@ -661,18 +655,7 @@ def create_ui():
def process_in_background(): def process_in_background():
try: try:
# 检查是否已请求停止
if STOP_REQUESTED.is_set():
result_queue.put((f"操作已取消", [], "0", f"❌ 操作已取消"))
return
result = run_owl(question, module_name) result = run_owl(question, module_name)
# 再次检查是否已请求停止
if STOP_REQUESTED.is_set():
result_queue.put((f"操作已取消", [], "0", f"❌ 操作已取消"))
return
result_queue.put(result) result_queue.put(result)
except Exception as e: except Exception as e:
result_queue.put((f"发生错误: {str(e)}", [], "0", f"❌ 错误: {str(e)}")) result_queue.put((f"发生错误: {str(e)}", [], "0", f"❌ 错误: {str(e)}"))
@ -688,12 +671,6 @@ def create_ui():
# 在等待处理完成的同时,每秒更新一次日志和对话历史 # 在等待处理完成的同时,每秒更新一次日志和对话历史
while bg_thread.is_alive(): while bg_thread.is_alive():
# 检查是否已请求停止
if STOP_REQUESTED.is_set():
logs = get_latest_logs(100)
yield "操作已取消", current_chat_history, "0", "<span class='status-indicator status-warning'></span> 正在停止...", logs
break
# 检查是否有新的对话更新(从日志解析) # 检查是否有新的对话更新(从日志解析)
updated = False updated = False
while not chat_history_queue.empty(): while not chat_history_queue.empty():
@ -747,13 +724,6 @@ def create_ui():
time.sleep(1) time.sleep(1)
# 如果已请求停止但线程仍在运行
if STOP_REQUESTED.is_set() and bg_thread.is_alive():
# 不再强制join线程让它自然结束
logs = get_latest_logs(100)
yield "生成已停止", current_chat_history, "0", "<span class='status-indicator status-warning'></span> 已停止生成", logs
return
# 处理完成,获取结果 # 处理完成,获取结果
if not result_queue.empty(): if not result_queue.empty():
result = result_queue.get() result = result_queue.get()
@ -778,7 +748,7 @@ def create_ui():
yield answer, current_chat_history, token_count, status_with_indicator, logs yield answer, current_chat_history, token_count, status_with_indicator, logs
else: else:
logs = get_latest_logs(100) logs = get_latest_logs(100)
yield "操作已取消或未完成", current_chat_history, "0", "<span class='status-indicator status-error'></span> 已终止", logs yield "操作未完成", current_chat_history, "0", "<span class='status-indicator status-error'></span> 已终止", logs
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as app: with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as app:
gr.Markdown( gr.Markdown(
@ -931,7 +901,6 @@ def create_ui():
with gr.Row(): with gr.Row():
run_button = gr.Button("运行", variant="primary", elem_classes="primary") run_button = gr.Button("运行", variant="primary", elem_classes="primary")
stop_button = gr.Button("停止", variant="stop", elem_classes="stop")
status_output = gr.HTML( status_output = gr.HTML(
value="<span class='status-indicator status-success'></span> 已就绪", value="<span class='status-indicator status-success'></span> 已就绪",
@ -1138,12 +1107,6 @@ def create_ui():
outputs=[answer_output, chat_output, token_count_output, status_output, log_display] outputs=[answer_output, chat_output, token_count_output, status_output, log_display]
) )
# 添加停止按钮事件处理
stop_button.click(
fn=terminate_process,
outputs=[answer_output, status_output]
)
# 模块选择更新描述 # 模块选择更新描述
module_dropdown.change( module_dropdown.change(
fn=update_module_description, fn=update_module_description,