Skip to content

Commit 2bdb7f9

Browse files
committed
feat: add multilingual support with English/Chinese UI switching
- Add report en|zh parameter to switch UI language between English and Chinese - Implement bilingual Gradio interface with language toggle support - Configure default test cases for navigation functionality testing - Update entry scripts with English prompts and instructions
1 parent d75cc85 commit 2bdb7f9

28 files changed

+1886
-960
lines changed

Dockerfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
FROM mcr.microsoft.com/playwright/python:v1.52.0-noble
22

3-
# 设置工作目录
3+
# Set working directory
44
WORKDIR /app
55

6-
# 安装 Node.jsnpm,以及必要的工具
6+
# Install Node.js, npm, and necessary tools
77
RUN apt-get update && apt-get install -y \
88
curl \
99
unzip \
@@ -12,13 +12,13 @@ RUN apt-get update && apt-get install -y \
1212
&& apt-get install -y nodejs \
1313
&& rm -rf /var/lib/apt/lists/*
1414

15-
# 优化pip配置和网络设置
15+
# Optimize pip configuration and network settings
1616
RUN pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple && \
1717
pip config set global.trusted-host mirrors.tuna.tsinghua.edu.cn && \
1818
pip config set global.timeout 300 && \
1919
pip config set global.retries 5
2020

21-
# 1. 先安装nuclei
21+
# 1. Install nuclei first
2222
RUN ARCH=$(dpkg --print-architecture) && \
2323
if [ "$ARCH" = "amd64" ]; then \
2424
NUCLEI_ARCH="amd64"; \
@@ -35,19 +35,19 @@ RUN ARCH=$(dpkg --print-architecture) && \
3535
chmod +x /usr/local/bin/nuclei && \
3636
rm -rf /tmp/nuclei /tmp/nuclei.zip
3737

38-
# 2. 复制Python依赖文件并安装
38+
# 2. Copy Python dependency file and install
3939
COPY requirements.txt /app/
4040
RUN pip install --no-cache-dir --default-timeout=300 -r requirements.txt
4141

42-
# 3. 复制Node.js依赖文件并安装
42+
# 3. Copy Node.js dependency file and install
4343
COPY package.json /app/
4444
RUN npm install
4545

46-
# 4. 复制项目文件
46+
# 4. Copy project files
4747
COPY . /app
4848

49-
# 更新nuclei模板
49+
# Update nuclei templates
5050
RUN nuclei -ut -v
5151

52-
# 设置运行webqa-agent
52+
# Set to run webqa-agent
5353
CMD ["python", "webqa-agent.py"]

README_zh-CN.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ browser_config:
139139
headless: False # Docker环境会自动覆盖为True
140140
language: zh-CN
141141
cookies: []
142-
143142
```
144143
145144
在配置和运行测试时,请注意以下重要事项:

app.py

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
11
#!/usr/bin/env python3
22
"""
3-
WebQA Agent Gradio启动脚本
3+
WebQA Agent Gradio Launch Script
44
"""
55

66
import sys
77
import os
88
import subprocess
99
import asyncio
1010

11-
# 添加项目路径到Python路径
12-
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
11+
# Add project path to Python path
12+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
1313

14-
# 导入并启动Gradio应用
14+
# Language configuration from environment variable
15+
def get_gradio_language():
16+
"""Get Gradio interface language from environment variable with validation"""
17+
supported_languages = ["zh-CN", "en-US"]
18+
env_lang = os.getenv("GRADIO_LANGUAGE", "en-US") # Default to English
19+
20+
if env_lang in supported_languages:
21+
return env_lang
22+
else:
23+
print(f"⚠️ Warning: Unsupported language '{env_lang}', falling back to 'en-US'")
24+
return "en-US"
25+
26+
GRADIO_LANGUAGE = get_gradio_language()
27+
28+
# Import and launch Gradio application
1529
if __name__ == "__main__":
1630
try:
17-
from demo_gradio import create_gradio_interface, queue_manager, process_queue
31+
from app_gradio.demo_gradio import create_gradio_interface, queue_manager, process_queue
1832
import threading
1933
from playwright.async_api import async_playwright, Error as PlaywrightError
2034

21-
print("🚀 启动WebQA Agent Gradio界面...")
22-
print("📱 界面将在 http://localhost:7860 启动")
23-
print("⚠️ 注意:请确保已安装所有依赖包 (pip install -r requirements.txt)")
24-
print("🔍 正在检查 Playwright 浏览器依赖...")
35+
print("🚀 Starting WebQA Agent Gradio interface...")
36+
print("📱 Interface will start at http://localhost:7860")
37+
print(f"🌐 Interface language: {GRADIO_LANGUAGE}")
38+
print("💡 Tip: Set environment variable GRADIO_LANGUAGE=en-US for English or GRADIO_LANGUAGE=zh-CN for Chinese")
39+
print("⚠️ Note: Please ensure all dependencies are installed (pip install -r requirements.txt)")
40+
print("🔍 Checking Playwright browser dependencies...")
2541

2642
async def _check_playwright():
2743
try:
@@ -36,53 +52,53 @@ async def _check_playwright():
3652

3753
ok = asyncio.run(_check_playwright())
3854
if not ok:
39-
print("⚠️ 检测到 Playwright 浏览器未安装,正在自动安装...")
55+
print("⚠️ Detected Playwright browsers not installed, installing automatically...")
4056
try:
4157
cmd = [sys.executable, "-m", "playwright", "install"]
4258
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
4359
print(result.stdout)
4460
except Exception as e:
45-
print(f"❌ 自动安装失败:{e}\n请手动执行:playwright install")
61+
print(f"❌ Automatic installation failed: {e}\nPlease run manually: playwright install")
4662
sys.exit(1)
4763

48-
# 安装后再次校验
64+
# Verify again after installation
4965
ok_after = asyncio.run(_check_playwright())
5066
if not ok_after:
51-
print("❌ Playwright 浏览器仍不可用,请手动执行:playwright install")
67+
print("❌ Playwright browsers still unavailable, please run manually: playwright install")
5268
sys.exit(1)
53-
print("✅ Playwright 浏览器可用")
69+
print("✅ Playwright browsers available")
5470

55-
# 启动队列处理器
71+
# Start queue processor
5672
def run_queue_processor():
57-
"""在后台线程中运行队列处理器"""
73+
"""Run queue processor in background thread"""
5874
loop = asyncio.new_event_loop()
5975
asyncio.set_event_loop(loop)
6076
loop.run_until_complete(process_queue())
6177

6278
queue_thread = threading.Thread(target=run_queue_processor, daemon=True)
6379
queue_thread.start()
64-
print("✅ 任务队列处理器已启动")
80+
print("✅ Task queue processor started")
6581

66-
# 创建并启动Gradio应用
67-
app = create_gradio_interface()
68-
print("✅ Gradio界面已创建")
82+
# Create and launch Gradio application with language configuration
83+
app = create_gradio_interface(language=GRADIO_LANGUAGE)
84+
print(f"✅ Gradio interface created with language: {GRADIO_LANGUAGE}")
6985

7086
app.launch(
7187
server_name="0.0.0.0",
7288
server_port=7860,
7389
share=False,
7490
show_error=True,
75-
inbrowser=True # 自动打开浏览器
91+
inbrowser=True # Auto open browser
7692
)
7793

7894
except ImportError as e:
79-
print(f"❌ 导入错误: {e}")
80-
print("请确保已安装所有依赖包:")
95+
print(f"❌ Import error: {e}")
96+
print("Please ensure all dependencies are installed:")
8197
print("pip install -r requirements.txt")
8298
sys.exit(1)
8399

84100
except Exception as e:
85-
print(f"❌ 启动失败: {e}")
101+
print(f"❌ Startup failed: {e}")
86102
import traceback
87103
traceback.print_exc()
88104
sys.exit(1)

0 commit comments

Comments
 (0)