11#!/usr/bin/env python3
22"""
3- WebQA Agent Gradio启动脚本
3+ WebQA Agent Gradio Launch Script
44"""
55
66import sys
77import os
88import subprocess
99import 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
1529if __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 } \n Please 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