Wendong-Fan commited on
Commit
b037620
·
1 Parent(s): 6c1fb8e
Files changed (2) hide show
  1. owl/webapp.py +8 -20
  2. owl/webapp_zh.py +0 -12
owl/webapp.py CHANGED
@@ -24,7 +24,7 @@ import importlib
24
  from dotenv import load_dotenv, set_key, find_dotenv, unset_key
25
  import threading
26
  import queue
27
- import re # For regular expression operations
28
 
29
  os.environ["PYTHONIOENCODING"] = "utf-8"
30
 
@@ -170,7 +170,7 @@ def get_latest_logs(max_lines=100, queue_source=None):
170
  processed_messages = set()
171
 
172
  def process_message(role, content):
173
- # 创建一个唯一标识符来跟踪消息
174
  msg_id = f"{role}:{content}"
175
  if msg_id in processed_messages:
176
  return None
@@ -184,7 +184,7 @@ def get_latest_logs(max_lines=100, queue_source=None):
184
 
185
  for log in filtered_logs:
186
  formatted_messages = []
187
- # 尝试提取消息数组
188
  messages_match = re.search(
189
  r"Model (.*?), index (\d+), processed these messages: (\[.*\])", log
190
  )
@@ -671,7 +671,7 @@ def save_env_table_changes(data):
671
  current_env_vars = load_env_vars()
672
  processed_keys = set() # Record processed keys to detect deleted variables
673
 
674
- # 处理pandas DataFrame对象
675
  import pandas as pd
676
 
677
  if isinstance(data, pd.DataFrame):
@@ -681,7 +681,7 @@ def save_env_table_changes(data):
681
 
682
  # Iterate through each row of the DataFrame
683
  for index, row in data.iterrows():
684
- # 使用列名访问数据
685
  if len(columns) >= 3:
686
  # Get variable name and value (column 0 is name, column 1 is value)
687
  key = row[0] if isinstance(row, pd.Series) else row.iloc[0]
@@ -696,10 +696,10 @@ def save_env_table_changes(data):
696
  )
697
  add_env_var(key, str(value))
698
  processed_keys.add(key)
699
- # 处理其他格式
700
  elif isinstance(data, dict):
701
  logging.info(f"Dictionary format data keys: {list(data.keys())}")
702
- # 如果是字典格式,尝试不同的键
703
  if "data" in data:
704
  rows = data["data"]
705
  elif "values" in data:
@@ -707,7 +707,7 @@ def save_env_table_changes(data):
707
  elif "value" in data:
708
  rows = data["value"]
709
  else:
710
- # 尝试直接使用字典作为行数据
711
  rows = []
712
  for key, value in data.items():
713
  if key not in ["headers", "types", "columns"]:
@@ -766,11 +766,6 @@ def get_env_var_value(key):
766
  def create_ui():
767
  """Create enhanced Gradio interface"""
768
 
769
- # Define conversation record update function
770
- def update_logs2():
771
- """Get the latest conversation records and return them to the frontend for display"""
772
- return get_latest_logs(100, LOG_QUEUE)
773
-
774
  def clear_log_file():
775
  """Clear log file content"""
776
  try:
@@ -1289,13 +1284,6 @@ def main():
1289
  init_env_file()
1290
  app = create_ui()
1291
 
1292
- # Register cleanup function for when the application closes
1293
- def cleanup():
1294
- global STOP_LOG_THREAD, STOP_REQUESTED
1295
- STOP_LOG_THREAD.set()
1296
- STOP_REQUESTED.set()
1297
- logging.info("Application closed, stopping log thread")
1298
-
1299
  app.queue()
1300
  app.launch(share=False, server_name="127.0.0.1", server_port=7860)
1301
  except Exception as e:
 
24
  from dotenv import load_dotenv, set_key, find_dotenv, unset_key
25
  import threading
26
  import queue
27
+ import re
28
 
29
  os.environ["PYTHONIOENCODING"] = "utf-8"
30
 
 
170
  processed_messages = set()
171
 
172
  def process_message(role, content):
173
+ # Create a unique identifier to track messages
174
  msg_id = f"{role}:{content}"
175
  if msg_id in processed_messages:
176
  return None
 
184
 
185
  for log in filtered_logs:
186
  formatted_messages = []
187
+ # Try to extract message array
188
  messages_match = re.search(
189
  r"Model (.*?), index (\d+), processed these messages: (\[.*\])", log
190
  )
 
671
  current_env_vars = load_env_vars()
672
  processed_keys = set() # Record processed keys to detect deleted variables
673
 
674
+ # Process pandas DataFrame object
675
  import pandas as pd
676
 
677
  if isinstance(data, pd.DataFrame):
 
681
 
682
  # Iterate through each row of the DataFrame
683
  for index, row in data.iterrows():
684
+ # Use column names to access data
685
  if len(columns) >= 3:
686
  # Get variable name and value (column 0 is name, column 1 is value)
687
  key = row[0] if isinstance(row, pd.Series) else row.iloc[0]
 
696
  )
697
  add_env_var(key, str(value))
698
  processed_keys.add(key)
699
+ # Process other formats
700
  elif isinstance(data, dict):
701
  logging.info(f"Dictionary format data keys: {list(data.keys())}")
702
+ # If dictionary format, try different keys
703
  if "data" in data:
704
  rows = data["data"]
705
  elif "values" in data:
 
707
  elif "value" in data:
708
  rows = data["value"]
709
  else:
710
+ # Try using dictionary directly as row data
711
  rows = []
712
  for key, value in data.items():
713
  if key not in ["headers", "types", "columns"]:
 
766
  def create_ui():
767
  """Create enhanced Gradio interface"""
768
 
 
 
 
 
 
769
  def clear_log_file():
770
  """Clear log file content"""
771
  try:
 
1284
  init_env_file()
1285
  app = create_ui()
1286
 
 
 
 
 
 
 
 
1287
  app.queue()
1288
  app.launch(share=False, server_name="127.0.0.1", server_port=7860)
1289
  except Exception as e:
owl/webapp_zh.py CHANGED
@@ -744,11 +744,6 @@ def get_env_var_value(key):
744
  def create_ui():
745
  """创建增强版Gradio界面"""
746
 
747
- # 定义对话记录更新函数
748
- def update_logs2():
749
- """获取最新对话记录并返回给前端显示"""
750
- return get_latest_logs(100, LOG_QUEUE)
751
-
752
  def clear_log_file():
753
  """清空日志文件内容"""
754
  try:
@@ -1259,13 +1254,6 @@ def main():
1259
  init_env_file()
1260
  app = create_ui()
1261
 
1262
- # 注册应用关闭时的清理函数
1263
- def cleanup():
1264
- global STOP_LOG_THREAD, STOP_REQUESTED
1265
- STOP_LOG_THREAD.set()
1266
- STOP_REQUESTED.set()
1267
- logging.info("应用程序关闭,停止日志线程")
1268
-
1269
  app.queue()
1270
  app.launch(share=False, server_name="127.0.0.1", server_port=7860)
1271
  except Exception as e:
 
744
  def create_ui():
745
  """创建增强版Gradio界面"""
746
 
 
 
 
 
 
747
  def clear_log_file():
748
  """清空日志文件内容"""
749
  try:
 
1254
  init_env_file()
1255
  app = create_ui()
1256
 
 
 
 
 
 
 
 
1257
  app.queue()
1258
  app.launch(share=False, server_name="127.0.0.1", server_port=7860)
1259
  except Exception as e: