104 lines
2.9 KiB
Batchfile
104 lines
2.9 KiB
Batchfile
@echo off
|
|
setlocal DisableDelayedExpansion
|
|
cd /d "%~dp0"
|
|
|
|
set "PYTHON_ARGS="
|
|
if defined VIRTUAL_ENV (
|
|
set "PYTHON_EXE=%VIRTUAL_ENV%\Scripts\python.exe"
|
|
call :probe_python
|
|
if not errorlevel 1 goto python_ready
|
|
)
|
|
|
|
set "PYTHON_EXE=%~dp0.venv\Scripts\python.exe"
|
|
call :probe_python
|
|
if not errorlevel 1 goto python_ready
|
|
|
|
set "PYTHON_EXE=py.exe"
|
|
set "PYTHON_ARGS=-3"
|
|
call :probe_python
|
|
if not errorlevel 1 goto python_ready
|
|
|
|
set "PYTHON_EXE=python.exe"
|
|
set "PYTHON_ARGS="
|
|
call :probe_python
|
|
if not errorlevel 1 goto python_ready
|
|
|
|
echo [ERROR] No working Python 3 interpreter found. Install Python or recreate .venv.
|
|
if /i "%~1"=="--check-python" exit /b 1
|
|
pause
|
|
exit /b 1
|
|
|
|
:python_ready
|
|
if /i "%~1"=="--check-python" (
|
|
"%PYTHON_EXE%" %PYTHON_ARGS% -c "import sys; print(sys.executable)"
|
|
exit /b
|
|
)
|
|
|
|
chcp 936 >nul
|
|
title Baiyue Logistics AI Customer Service
|
|
echo ============================================
|
|
echo Baiyue Logistics AI Customer Service
|
|
echo ============================================
|
|
echo.
|
|
|
|
echo [1/3] Checking port 5000 ...
|
|
netstat -ano | findstr "LISTENING" | findstr /C:":5000 " >nul
|
|
if not errorlevel 1 (
|
|
echo.
|
|
echo [INFO] Port 5000 is already in use, a server is probably running:
|
|
echo.
|
|
netstat -ano | findstr "LISTENING" | findstr /C:":5000 "
|
|
echo.
|
|
echo The last column is the process id. To stop it:
|
|
echo taskkill /PID 12345 /F
|
|
echo.
|
|
start "" http://127.0.0.1:5000
|
|
echo Browser opened. Press any key to close this window.
|
|
pause
|
|
exit /b 0
|
|
)
|
|
echo OK - port is free.
|
|
|
|
echo [2/3] Checking dependencies ...
|
|
"%PYTHON_EXE%" %PYTHON_ARGS% -c "import flask, requests, waitress, dotenv" >nul 2>nul
|
|
if errorlevel 1 (
|
|
echo Missing packages, installing ...
|
|
"%PYTHON_EXE%" %PYTHON_ARGS% -m pip install -r requirements.txt
|
|
if errorlevel 1 (
|
|
echo [ERROR] pip install failed, check network and retry.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
)
|
|
echo OK - dependencies ready.
|
|
|
|
echo [3/3] Checking DeepSeek configuration ...
|
|
"%PYTHON_EXE%" %PYTHON_ARGS% -c "import sys; from logistics_chat.config import default_config; sys.exit(0 if default_config()['DEEPSEEK_API_KEY'] else 1)" >nul
|
|
if errorlevel 1 (
|
|
echo [WARN] No DeepSeek API key configured.
|
|
echo Copy .env.example to .env and set DEEPSEEK_API_KEY, then restart.
|
|
) else (
|
|
echo OK - key detected in .env or environment.
|
|
)
|
|
|
|
echo.
|
|
echo ============================================
|
|
echo Starting: http://127.0.0.1:5000
|
|
echo Close this window or press Ctrl+C to stop
|
|
echo ============================================
|
|
echo.
|
|
|
|
start "" http://127.0.0.1:5000
|
|
"%PYTHON_EXE%" %PYTHON_ARGS% am.py
|
|
set "APP_EXIT_CODE=%ERRORLEVEL%"
|
|
|
|
echo.
|
|
echo Server stopped.
|
|
pause
|
|
exit /b %APP_EXIT_CODE%
|
|
|
|
:probe_python
|
|
"%PYTHON_EXE%" %PYTHON_ARGS% -c "import sys; sys.exit(0 if sys.version_info.major == 3 else 1)" >nul 2>nul
|
|
if "%ERRORLEVEL%"=="0" exit /b 0
|
|
exit /b 1
|