zjrwtx commited on
Commit
c34fb3d
·
1 Parent(s): 93ada60

delete stop button

Browse files
Files changed (1) hide show
  1. owl/webapp_zh.py +4 -41
owl/webapp_zh.py CHANGED
@@ -285,7 +285,7 @@ def run_owl(question: str, example_module: str) -> Tuple[str, List[List[str]], s
285
  Returns:
286
  Tuple[...]: 回答、聊天历史、令牌计数、状态
287
  """
288
- global CURRENT_PROCESS, STOP_REQUESTED, CONVERSATION_UPDATE_QUEUE
289
 
290
  # 清空对话更新队列
291
  while not CONVERSATION_UPDATE_QUEUE.empty():
@@ -294,9 +294,6 @@ def run_owl(question: str, example_module: str) -> Tuple[str, List[List[str]], s
294
  except queue.Empty:
295
  break
296
 
297
- # 重置停止标志
298
- STOP_REQUESTED.clear()
299
-
300
  # 验证输入
301
  if not validate_input(question):
302
  logging.warning("用户提交了无效的输入")
@@ -567,10 +564,7 @@ def create_ui():
567
  # 创建一个实时日志更新函数
568
  def process_with_live_logs(question, module_name):
569
  """处理问题并实时更新日志和对话历史"""
570
- global CURRENT_PROCESS, STOP_REQUESTED, CONVERSATION_UPDATE_QUEUE
571
-
572
- # 重置停止标志
573
- STOP_REQUESTED.clear()
574
 
575
  # 创建一个后台线程来处理问题
576
  result_queue = queue.Queue()
@@ -592,7 +586,7 @@ def create_ui():
592
  # 移动到文件末尾
593
  f.seek(0, 2)
594
 
595
- while not STOP_REQUESTED.is_set():
596
  line = f.readline()
597
  if line:
598
  # 尝试多种模式来检测对话信息
@@ -661,18 +655,7 @@ def create_ui():
661
 
662
  def process_in_background():
663
  try:
664
- # 检查是否已请求停止
665
- if STOP_REQUESTED.is_set():
666
- result_queue.put((f"操作已取消", [], "0", f"❌ 操作已取消"))
667
- return
668
-
669
  result = run_owl(question, module_name)
670
-
671
- # 再次检查是否已请求停止
672
- if STOP_REQUESTED.is_set():
673
- result_queue.put((f"操作已取消", [], "0", f"❌ 操作已取消"))
674
- return
675
-
676
  result_queue.put(result)
677
  except Exception as e:
678
  result_queue.put((f"发生错误: {str(e)}", [], "0", f"❌ 错误: {str(e)}"))
@@ -688,12 +671,6 @@ def create_ui():
688
 
689
  # 在等待处理完成的同时,每秒更新一次日志和对话历史
690
  while bg_thread.is_alive():
691
- # 检查是否已请求停止
692
- if STOP_REQUESTED.is_set():
693
- logs = get_latest_logs(100)
694
- yield "操作已取消", current_chat_history, "0", "<span class='status-indicator status-warning'></span> 正在停止...", logs
695
- break
696
-
697
  # 检查是否有新的对话更新(从日志解析)
698
  updated = False
699
  while not chat_history_queue.empty():
@@ -747,13 +724,6 @@ def create_ui():
747
 
748
  time.sleep(1)
749
 
750
- # 如果已请求停止但线程仍在运行
751
- if STOP_REQUESTED.is_set() and bg_thread.is_alive():
752
- # 不再强制join线程,让它自然结束
753
- logs = get_latest_logs(100)
754
- yield "生成已停止", current_chat_history, "0", "<span class='status-indicator status-warning'></span> 已停止生成", logs
755
- return
756
-
757
  # 处理完成,获取结果
758
  if not result_queue.empty():
759
  result = result_queue.get()
@@ -778,7 +748,7 @@ def create_ui():
778
  yield answer, current_chat_history, token_count, status_with_indicator, logs
779
  else:
780
  logs = get_latest_logs(100)
781
- yield "操作已取消或未完成", current_chat_history, "0", "<span class='status-indicator status-error'></span> 已终止", logs
782
 
783
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as app:
784
  gr.Markdown(
@@ -931,7 +901,6 @@ def create_ui():
931
 
932
  with gr.Row():
933
  run_button = gr.Button("运行", variant="primary", elem_classes="primary")
934
- stop_button = gr.Button("停止", variant="stop", elem_classes="stop")
935
 
936
  status_output = gr.HTML(
937
  value="<span class='status-indicator status-success'></span> 已就绪",
@@ -1138,12 +1107,6 @@ def create_ui():
1138
  outputs=[answer_output, chat_output, token_count_output, status_output, log_display]
1139
  )
1140
 
1141
- # 添加停止按钮事件处理
1142
- stop_button.click(
1143
- fn=terminate_process,
1144
- outputs=[answer_output, status_output]
1145
- )
1146
-
1147
  # 模块选择更新描述
1148
  module_dropdown.change(
1149
  fn=update_module_description,
 
285
  Returns:
286
  Tuple[...]: 回答、聊天历史、令牌计数、状态
287
  """
288
+ global CURRENT_PROCESS, CONVERSATION_UPDATE_QUEUE
289
 
290
  # 清空对话更新队列
291
  while not CONVERSATION_UPDATE_QUEUE.empty():
 
294
  except queue.Empty:
295
  break
296
 
 
 
 
297
  # 验证输入
298
  if not validate_input(question):
299
  logging.warning("用户提交了无效的输入")
 
564
  # 创建一个实时日志更新函数
565
  def process_with_live_logs(question, module_name):
566
  """处理问题并实时更新日志和对话历史"""
567
+ global CURRENT_PROCESS, CONVERSATION_UPDATE_QUEUE
 
 
 
568
 
569
  # 创建一个后台线程来处理问题
570
  result_queue = queue.Queue()
 
586
  # 移动到文件末尾
587
  f.seek(0, 2)
588
 
589
+ while True:
590
  line = f.readline()
591
  if line:
592
  # 尝试多种模式来检测对话信息
 
655
 
656
  def process_in_background():
657
  try:
 
 
 
 
 
658
  result = run_owl(question, module_name)
 
 
 
 
 
 
659
  result_queue.put(result)
660
  except Exception as e:
661
  result_queue.put((f"发生错误: {str(e)}", [], "0", f"❌ 错误: {str(e)}"))
 
671
 
672
  # 在等待处理完成的同时,每秒更新一次日志和对话历史
673
  while bg_thread.is_alive():
 
 
 
 
 
 
674
  # 检查是否有新的对话更新(从日志解析)
675
  updated = False
676
  while not chat_history_queue.empty():
 
724
 
725
  time.sleep(1)
726
 
 
 
 
 
 
 
 
727
  # 处理完成,获取结果
728
  if not result_queue.empty():
729
  result = result_queue.get()
 
748
  yield answer, current_chat_history, token_count, status_with_indicator, logs
749
  else:
750
  logs = get_latest_logs(100)
751
+ yield "操作未完成", current_chat_history, "0", "<span class='status-indicator status-error'></span> 已终止", logs
752
 
753
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as app:
754
  gr.Markdown(
 
901
 
902
  with gr.Row():
903
  run_button = gr.Button("运行", variant="primary", elem_classes="primary")
 
904
 
905
  status_output = gr.HTML(
906
  value="<span class='status-indicator status-success'></span> 已就绪",
 
1107
  outputs=[answer_output, chat_output, token_count_output, status_output, log_display]
1108
  )
1109
 
 
 
 
 
 
 
1110
  # 模块选择更新描述
1111
  module_dropdown.change(
1112
  fn=update_module_description,