update log
Browse files- owl/webapp_zh.py +35 -6
owl/webapp_zh.py
CHANGED
@@ -485,6 +485,38 @@ def create_ui():
|
|
485 |
"""清空日志显示"""
|
486 |
return ""
|
487 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
488 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as app:
|
489 |
gr.Markdown(
|
490 |
"""
|
@@ -692,12 +724,9 @@ def create_ui():
|
|
692 |
|
693 |
# 设置事件处理
|
694 |
run_button.click(
|
695 |
-
fn=
|
696 |
inputs=[question_input, module_dropdown],
|
697 |
-
outputs=[answer_output, chat_output, token_count_output, status_output]
|
698 |
-
).then(
|
699 |
-
fn=update_logs, # 任务完成后自动更新日志
|
700 |
-
outputs=[log_display]
|
701 |
)
|
702 |
|
703 |
# 模块选择更新描述
|
@@ -763,7 +792,7 @@ def main():
|
|
763 |
STOP_LOG_THREAD.set()
|
764 |
logging.info("应用程序关闭,停止日志线程")
|
765 |
|
766 |
-
app.launch(share=False)
|
767 |
except Exception as e:
|
768 |
logging.error(f"启动应用程序时发生错误: {str(e)}")
|
769 |
print(f"启动应用程序时发生错误: {str(e)}")
|
|
|
485 |
"""清空日志显示"""
|
486 |
return ""
|
487 |
|
488 |
+
# 创建一个实时日志更新函数
|
489 |
+
def process_with_live_logs(question, module_name):
|
490 |
+
"""处理问题并实时更新日志"""
|
491 |
+
# 创建一个后台线程来处理问题
|
492 |
+
result_queue = queue.Queue()
|
493 |
+
|
494 |
+
def process_in_background():
|
495 |
+
try:
|
496 |
+
result = run_owl(question, module_name)
|
497 |
+
result_queue.put(result)
|
498 |
+
except Exception as e:
|
499 |
+
result_queue.put((f"发生错误: {str(e)}", [], "0", f"❌ 错误: {str(e)}"))
|
500 |
+
|
501 |
+
# 启动后台处理线程
|
502 |
+
bg_thread = threading.Thread(target=process_in_background)
|
503 |
+
bg_thread.start()
|
504 |
+
|
505 |
+
# 在等待处理完成的同时,每秒更新一次日志
|
506 |
+
while bg_thread.is_alive():
|
507 |
+
# 更新日志显示
|
508 |
+
logs = get_latest_logs(100)
|
509 |
+
yield None, None, None, "⏳ 处理中...", logs
|
510 |
+
time.sleep(1)
|
511 |
+
|
512 |
+
# 处理完成,获取结果
|
513 |
+
result = result_queue.get()
|
514 |
+
answer, chat_history, token_count, status = result
|
515 |
+
|
516 |
+
# 最后一次更新日志
|
517 |
+
logs = get_latest_logs(100)
|
518 |
+
yield answer, chat_history, token_count, status, logs
|
519 |
+
|
520 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as app:
|
521 |
gr.Markdown(
|
522 |
"""
|
|
|
724 |
|
725 |
# 设置事件处理
|
726 |
run_button.click(
|
727 |
+
fn=process_with_live_logs,
|
728 |
inputs=[question_input, module_dropdown],
|
729 |
+
outputs=[answer_output, chat_output, token_count_output, status_output, log_display]
|
|
|
|
|
|
|
730 |
)
|
731 |
|
732 |
# 模块选择更新描述
|
|
|
792 |
STOP_LOG_THREAD.set()
|
793 |
logging.info("应用程序关闭,停止日志线程")
|
794 |
|
795 |
+
app.launch(share=False,enable_queue=True,server_name="127.0.0.1",server_port=7860)
|
796 |
except Exception as e:
|
797 |
logging.error(f"启动应用程序时发生错误: {str(e)}")
|
798 |
print(f"启动应用程序时发生错误: {str(e)}")
|