-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.bat
More file actions
107 lines (94 loc) · 3.35 KB
/
Copy pathstart.bat
File metadata and controls
107 lines (94 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
@echo off
setlocal
REM Check for Python 3
python --version >nul 2>&1
if %errorlevel% neq 0 (
echo Error: Python is not installed or not found in PATH.
echo Please install Python 3 and ensure it's added to your PATH.
goto :error_exit
)
python --version 2>&1 | findstr /C:"Python 3" >nul
if %errorlevel% neq 0 (
echo Error: Python 3 is required. The installed version is not Python 3.
echo Please install Python 3.
goto :error_exit
)
echo Python 3 found.
REM Virtual Environment
if not exist "venv" (
echo Creating Python 3 virtual environment 'venv'...
python -m venv venv
if %errorlevel% neq 0 (
echo Error: Failed to create virtual environment.
goto :error_exit
)
echo Virtual environment 'venv' created.
) else (
echo Virtual environment 'venv' already exists.
)
REM Activate Virtual Environment
echo Activating virtual environment...
if not exist "venv\Scripts\activate.bat" (
echo Error: venv\Scripts\activate.bat not found. Cannot activate virtual environment.
goto :error_exit
)
call venv\Scripts\activate.bat
if %errorlevel% neq 0 (
echo Error: Failed to activate virtual environment.
goto :error_exit
)
echo Virtual environment activated.
REM Install Dependencies
echo Installing dependencies from requirements.txt...
if not exist "requirements.txt" (
echo Error: requirements.txt not found.
call :deactivate_and_exit
)
pip install -r requirements.txt
if %errorlevel% neq 0 (
echo Error: Failed to install dependencies.
call :deactivate_and_exit
)
echo Dependencies installed successfully or were already up-to-date.
REM Start Application
echo Starting Docling-webui.py...
REM The 'start' command launches the Python script in a new window, allowing the batch script to continue.
start "Docling WebUI" python Docling-webui.py
if %errorlevel% neq 0 (
echo Error: Failed to start Docling-webui.py.
call :deactivate_and_exit
)
echo Docling-webui.py is starting. Check its console output for the exact URL and port.
REM Open Browser
echo Waiting for the server to start...
timeout /t 5 /nobreak >nul
echo Attempting to open http://localhost:7860 in your browser.
echo Please check the console output from Docling-webui.py for the actual address if it's different.
start http://localhost:7860
echo Script finished. The application should be running.
goto :cleanup
:deactivate_and_exit
REM This label is for deactivating venv if it was activated, then exiting.
echo Deactivating virtual environment due to an error...
if defined VIRTUAL_ENV (
call venv\Scripts\deactivate.bat
)
goto :error_exit
:error_exit
echo Script terminated due to an error.
call :cleanup_exit
:cleanup
REM Clean up and exit script
if defined VIRTUAL_ENV (
REM Deactivate if the script is ending normally and venv is active
REM This might not be strictly necessary as the parent cmd prompt will not be affected by 'call activate'
REM but it's good practice for scripts that might be sourced or have other side effects.
REM However, for a simple launcher, it might be better to leave the venv active if the user ran the script directly in their cmd.
REM For now, we'll assume the primary purpose is launching the app, so we won't explicitly deactivate here on normal exit.
echo Virtual environment is still active in this window if you ran the script directly.
)
endlocal
exit /b 0
:cleanup_exit
endlocal
exit /b 1