Skip to content

Commit 918091e

Browse files
committed
updaste comments in visualize-trace
1 parent 45e5a86 commit 918091e

File tree

7 files changed

+387
-387
lines changed

7 files changed

+387
-387
lines changed

apps/visualize-trace/app.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
@app.route("/")
1616
def index():
17-
"""主页面"""
17+
"""Main page"""
1818
return render_template("index.html")
1919

2020

2121
@app.route("/api/list_files", methods=["GET"])
2222
def list_files():
23-
"""列出可用的JSON文件"""
23+
"""List available JSON files"""
2424
try:
2525
directory = request.args.get("directory", "")
2626

@@ -35,10 +35,10 @@ def list_files():
3535
directory = os.path.abspath(directory)
3636

3737
if not os.path.exists(directory):
38-
return jsonify({"error": f"目录不存在: {directory}"}), 404
38+
return jsonify({"error": f"Directory does not exist: {directory}"}), 404
3939

4040
if not os.path.isdir(directory):
41-
return jsonify({"error": f"路径不是目录: {directory}"}), 400
41+
return jsonify({"error": f"Path is not a directory: {directory}"}), 400
4242

4343
try:
4444
json_files = []
@@ -68,54 +68,54 @@ def list_files():
6868
{
6969
"files": json_files,
7070
"directory": directory,
71-
"message": f'在目录 "{directory}" 中找到 {len(json_files)} 个JSON文件',
71+
"message": f'Found {len(json_files)} JSON files in directory "{directory}"',
7272
}
7373
)
7474
except PermissionError:
75-
return jsonify({"error": f"没有权限访问目录: {directory}"}), 403
75+
return jsonify({"error": f"No permission to access directory: {directory}"}), 403
7676
except Exception as e:
77-
return jsonify({"error": f"读取目录失败: {str(e)}"}), 500
77+
return jsonify({"error": f"Failed to read directory: {str(e)}"}), 500
7878

7979
except Exception as e:
8080
return jsonify({"error": str(e)}), 500
8181

8282

8383
@app.route("/api/load_trace", methods=["POST"])
8484
def load_trace():
85-
"""加载trace文件"""
85+
"""Load trace file"""
8686
global analyzer
8787

8888
data = request.get_json()
8989
file_path = data.get("file_path")
9090

9191
if not file_path:
92-
return jsonify({"error": "请提供文件路径"}), 400
92+
return jsonify({"error": "Please provide file path"}), 400
9393

9494
# If it's a relative path, convert to absolute path
9595
if not os.path.isabs(file_path):
9696
file_path = os.path.abspath(file_path)
9797

9898
if not os.path.exists(file_path):
99-
return jsonify({"error": f"文件不存在: {file_path}"}), 404
99+
return jsonify({"error": f"File does not exist: {file_path}"}), 404
100100

101101
try:
102102
analyzer = TraceAnalyzer(file_path)
103103
return jsonify(
104104
{
105-
"message": "文件加载成功",
105+
"message": "File loaded successfully",
106106
"file_path": file_path,
107107
"file_name": os.path.basename(file_path),
108108
}
109109
)
110110
except Exception as e:
111-
return jsonify({"error": f"加载文件失败: {str(e)}"}), 500
111+
return jsonify({"error": f"Failed to load file: {str(e)}"}), 500
112112

113113

114114
@app.route("/api/basic_info")
115115
def get_basic_info():
116-
"""获取基本信息"""
116+
"""Get basic information"""
117117
if not analyzer:
118-
return jsonify({"error": "请先加载trace文件"}), 400
118+
return jsonify({"error": "Please load trace file first"}), 400
119119

120120
try:
121121
return jsonify(analyzer.get_basic_info())
@@ -125,9 +125,9 @@ def get_basic_info():
125125

126126
@app.route("/api/performance_summary")
127127
def get_performance_summary():
128-
"""获取性能摘要"""
128+
"""Get performance summary"""
129129
if not analyzer:
130-
return jsonify({"error": "请先加载trace文件"}), 400
130+
return jsonify({"error": "Please load trace file first"}), 400
131131

132132
try:
133133
return jsonify(analyzer.get_performance_summary())
@@ -137,9 +137,9 @@ def get_performance_summary():
137137

138138
@app.route("/api/execution_flow")
139139
def get_execution_flow():
140-
"""获取执行流程"""
140+
"""Get execution flow"""
141141
if not analyzer:
142-
return jsonify({"error": "请先加载trace文件"}), 400
142+
return jsonify({"error": "Please load trace file first"}), 400
143143

144144
try:
145145
return jsonify(analyzer.analyze_conversation_flow())
@@ -149,9 +149,9 @@ def get_execution_flow():
149149

150150
@app.route("/api/execution_summary")
151151
def get_execution_summary():
152-
"""获取执行摘要"""
152+
"""Get execution summary"""
153153
if not analyzer:
154-
return jsonify({"error": "请先加载trace文件"}), 400
154+
return jsonify({"error": "Please load trace file first"}), 400
155155

156156
try:
157157
return jsonify(analyzer.get_execution_summary())
@@ -161,9 +161,9 @@ def get_execution_summary():
161161

162162
@app.route("/api/spans_summary")
163163
def get_spans_summary():
164-
"""获取spans摘要"""
164+
"""Get spans summary"""
165165
if not analyzer:
166-
return jsonify({"error": "请先加载trace文件"}), 400
166+
return jsonify({"error": "Please load trace file first"}), 400
167167

168168
try:
169169
return jsonify(analyzer.get_spans_summary())
@@ -173,9 +173,9 @@ def get_spans_summary():
173173

174174
@app.route("/api/step_logs_summary")
175175
def get_step_logs_summary():
176-
"""获取步骤日志摘要"""
176+
"""Get step logs summary"""
177177
if not analyzer:
178-
return jsonify({"error": "请先加载trace文件"}), 400
178+
return jsonify({"error": "Please load trace file first"}), 400
179179

180180
try:
181181
return jsonify(analyzer.get_step_logs_summary())
@@ -185,9 +185,9 @@ def get_step_logs_summary():
185185

186186
@app.route("/api/debug/raw_messages")
187187
def get_raw_messages():
188-
"""获取原始消息数据用于调试"""
188+
"""Get raw message data for debugging"""
189189
if not analyzer:
190-
return jsonify({"error": "请先加载trace文件"}), 400
190+
return jsonify({"error": "Please load trace file first"}), 400
191191

192192
try:
193193
main_history = analyzer.get_main_agent_history()
@@ -220,7 +220,7 @@ def get_raw_messages():
220220
"raw_main_history": main_history,
221221
"raw_browser_sessions": {
222222
k: v for k, v in list(browser_sessions.items())[:2]
223-
}, # 只显示前两个会话
223+
}, # Only show first two sessions
224224
}
225225
)
226226
except Exception as e:

apps/visualize-trace/run.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# SPDX-License-Identifier: Apache-2.0
66

77
"""
8-
Trace Analysis Web Demo 启动脚本
8+
Trace Analysis Web Demo startup script
99
"""
1010

1111
import os
@@ -14,98 +14,98 @@
1414

1515

1616
def check_dependencies():
17-
"""检查依赖是否已安装"""
17+
"""Check if dependencies are installed"""
1818
try:
1919
import importlib.util
2020

2121
if importlib.util.find_spec("flask") is not None:
22-
print("✓ Flask 已安装")
22+
print("✓ Flask installed")
2323
return True
2424
else:
2525
raise ImportError("Flask not found")
2626
except ImportError:
27-
print("✗ Flask 未安装")
28-
print("请使用以下命令安装依赖:")
27+
print("✗ Flask not installed")
28+
print("Please use the following command to install dependencies:")
2929
print(" uv sync")
30-
print("或者:")
30+
print("or:")
3131
print(" uv pip install -r requirements.txt")
3232
return False
3333

3434

3535
def install_dependencies():
36-
"""安装依赖(建议使用uv)"""
37-
print("正在安装依赖...")
36+
"""Install dependencies (recommended to use uv)"""
37+
print("Installing dependencies...")
3838
try:
39-
# 优先尝试使用uv
39+
# Try using uv first
4040
try:
4141
subprocess.check_call(["uv", "sync"])
42-
print("✓ 使用uv安装依赖完成")
42+
print("✓ Dependencies installed using uv")
4343
return True
4444
except (subprocess.CalledProcessError, FileNotFoundError):
45-
# 回退到pip
45+
# Fall back to pip
4646
subprocess.check_call(
4747
[sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]
4848
)
49-
print("✓ 使用pip安装依赖完成")
49+
print("✓ Dependencies installed using pip")
5050
return True
5151
except subprocess.CalledProcessError:
52-
print("✗ 依赖安装失败")
53-
print("请手动运行: uv sync pip install -r requirements.txt")
52+
print("✗ Failed to install dependencies")
53+
print("Please run manually: uv sync or pip install -r requirements.txt")
5454
return False
5555

5656

5757
def main():
58-
"""主函数"""
58+
"""Main function"""
5959
import argparse
6060

61-
# 解析命令行参数
61+
# Parse command line arguments
6262
parser = argparse.ArgumentParser(description="Trace Analysis Web Demo")
6363
parser.add_argument(
64-
"-p", "--port", type=int, default=5000, help="指定端口号 (默认: 5000)"
64+
"-p", "--port", type=int, default=5000, help="Specify port number (default: 5000)"
6565
)
6666
args = parser.parse_args()
6767

6868
print("=" * 50)
6969
print("Trace Analysis Web Demo")
7070
print("=" * 50)
7171

72-
# 检查依赖
72+
# Check dependencies
7373
if not check_dependencies():
74-
print("\n正在安装依赖...")
74+
print("\nInstalling dependencies...")
7575
if not install_dependencies():
76-
print("请手动安装依赖: pip install -r requirements.txt")
76+
print("Please install dependencies manually: pip install -r requirements.txt")
7777
return
7878

79-
# 检查JSON文件
79+
# Check JSON files
8080
parent_dir = os.path.dirname(os.path.abspath(__file__))
8181
json_files = [
8282
f for f in os.listdir(os.path.join(parent_dir, "..")) if f.endswith(".json")
8383
]
8484

8585
if not json_files:
86-
print("\n警告: 在上级目录中没有找到JSON文件")
87-
print("请确保有trace JSON文件在 trace_analyze/ 目录中")
86+
print("\nWarning: No JSON files found in parent directory")
87+
print("Please ensure there are trace JSON files in the trace_analyze/ directory")
8888
else:
89-
print(f"\n找到 {len(json_files)} 个JSON文件:")
90-
for file in json_files[:5]: # 只显示前5个
89+
print(f"\nFound {len(json_files)} JSON files:")
90+
for file in json_files[:5]: # Show only first 5
9191
print(f" - {file}")
9292
if len(json_files) > 5:
93-
print(f" ... 和其他 {len(json_files) - 5} 个文件")
93+
print(f" ... and {len(json_files) - 5} other files")
9494

95-
# 启动应用
96-
print("\n正在启动Web应用...")
97-
print(f"应用将在 http://localhost:{args.port} 运行")
98-
print(" Ctrl+C 停止应用")
95+
# Start application
96+
print("\nStarting web application...")
97+
print(f"Application will run at http://localhost:{args.port}")
98+
print("Press Ctrl+C to stop the application")
9999
print("=" * 50)
100100

101101
try:
102102
from app import app
103103

104104
app.run(debug=True, host="0.0.0.0", port=args.port)
105105
except KeyboardInterrupt:
106-
print("\n应用已停止")
106+
print("\nApplication stopped")
107107
except Exception as e:
108-
print(f"\n启动应用失败: {e}")
108+
print(f"\nFailed to start application: {e}")
109109

110110

111111
if __name__ == "__main__":

0 commit comments

Comments
 (0)