Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse files- Dockerfile +2 -0
- scripts/run_windows.bat +300 -300
- scripts/server_llamacpp_windows.bat +115 -115
- scripts/update_windows.bat +99 -99
Dockerfile
CHANGED
|
@@ -54,6 +54,8 @@ RUN apt-get autoremove \
|
|
| 54 |
&& rm -rf /var/lib/apt/lists/* \
|
| 55 |
&& rm -rf ~/.cache
|
| 56 |
|
|
|
|
|
|
|
| 57 |
CMD ["python", "app.py"]
|
| 58 |
|
| 59 |
# Full version
|
|
|
|
| 54 |
&& rm -rf /var/lib/apt/lists/* \
|
| 55 |
&& rm -rf ~/.cache
|
| 56 |
|
| 57 |
+
RUN pip install theflow
|
| 58 |
+
|
| 59 |
CMD ["python", "app.py"]
|
| 60 |
|
| 61 |
# Full version
|
scripts/run_windows.bat
CHANGED
|
@@ -1,300 +1,300 @@
|
|
| 1 |
-
@ECHO off
|
| 2 |
-
|
| 3 |
-
:: Main script execution
|
| 4 |
-
CD /D "%~dp0\.."
|
| 5 |
-
|
| 6 |
-
SET /p app_version=<"%CD%\VERSION" || SET app_version=latest
|
| 7 |
-
SET install_dir=%CD%\install_dir
|
| 8 |
-
SET conda_root=%install_dir%\conda
|
| 9 |
-
SET env_dir=%install_dir%\env
|
| 10 |
-
SET python_version=3.10
|
| 11 |
-
SET miniconda_download_url=https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe
|
| 12 |
-
|
| 13 |
-
SET git_install_dir=%install_dir%\Git
|
| 14 |
-
SET seven_zip_dir=%install_dir%\7zip
|
| 15 |
-
:: Determine if the machine is 32-bit or 64-bit
|
| 16 |
-
IF "%PROCESSOR_ARCHITECTURE%"=="x86" (
|
| 17 |
-
SET seven_zip_url=https://7-zip.org/a/7z2408.exe
|
| 18 |
-
SET git_download_url=https://github.com/git-for-windows/git/releases/download/v2.46.0.windows.1/PortableGit-2.46.0-32-bit.7z.exe
|
| 19 |
-
) ELSE (
|
| 20 |
-
SET seven_zip_url=https://7-zip.org/a/7z2408-x64.exe
|
| 21 |
-
SET git_download_url=https://github.com/git-for-windows/git/releases/download/v2.46.0.windows.1/PortableGit-2.46.0-64-bit.7z.exe
|
| 22 |
-
)
|
| 23 |
-
|
| 24 |
-
ECHO %CD%| FINDSTR /C:" " >nul 2>&1
|
| 25 |
-
IF %ERRORLEVEL% EQU 0 (
|
| 26 |
-
ECHO The current workdir has whitespace which can lead to unintended behaviour. Please modify your path and continue later.
|
| 27 |
-
GOTO :end
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
IF NOT EXIST "%install_dir%" ( MKDIR "%install_dir%" )
|
| 31 |
-
|
| 32 |
-
CALL :print_highlight "Setting up Git"
|
| 33 |
-
CALL :download_and_install_git
|
| 34 |
-
IF ERRORLEVEL 1 GOTO :end
|
| 35 |
-
|
| 36 |
-
:: Temporarily add Portable Git to PATH
|
| 37 |
-
SET "PATH=%git_install_dir%\bin;%PATH%"
|
| 38 |
-
|
| 39 |
-
CALL :print_highlight "Setting up Miniconda"
|
| 40 |
-
CALL :download_and_install_miniconda
|
| 41 |
-
IF ERRORLEVEL 1 GOTO :end
|
| 42 |
-
|
| 43 |
-
CALL :print_highlight "Creating conda environment"
|
| 44 |
-
CALL :create_conda_environment
|
| 45 |
-
IF ERRORLEVEL 1 GOTO :end
|
| 46 |
-
|
| 47 |
-
CALL :activate_environment
|
| 48 |
-
IF ERRORLEVEL 1 GOTO :end
|
| 49 |
-
|
| 50 |
-
CALL :print_highlight "Installing Kotaemon"
|
| 51 |
-
CALL :install_dependencies
|
| 52 |
-
IF ERRORLEVEL 1 GOTO :end
|
| 53 |
-
|
| 54 |
-
CALL :print_highlight "Setting up a local model"
|
| 55 |
-
CALL :setup_local_model
|
| 56 |
-
IF ERRORLEVEL 1 GOTO :end
|
| 57 |
-
|
| 58 |
-
CALL :print_highlight "Downloading and extracting PDF.js"
|
| 59 |
-
CALL :download_and_extract_pdf_js
|
| 60 |
-
IF ERRORLEVEL 1 GOTO :end
|
| 61 |
-
|
| 62 |
-
CALL :print_highlight "Launching Kotaemon in your browser, please wait..."
|
| 63 |
-
CALL :launch_ui
|
| 64 |
-
|
| 65 |
-
CALL :deactivate_environment
|
| 66 |
-
GOTO :end_success
|
| 67 |
-
|
| 68 |
-
:download_and_install_7zip
|
| 69 |
-
:: Check if 7-Zip is installed
|
| 70 |
-
IF NOT EXIST "%seven_zip_dir%\7z.exe" (
|
| 71 |
-
ECHO Downloading 7-Zip from %seven_zip_url%
|
| 72 |
-
CALL curl -Lk "%seven_zip_url%" -o "%install_dir%\7zip_installer.exe" || (
|
| 73 |
-
ECHO. && ECHO Failed to download 7-Zip. Aborting...
|
| 74 |
-
GOTO :exit_func_with_error
|
| 75 |
-
)
|
| 76 |
-
ECHO Installing 7-Zip to %seven_zip_dir%
|
| 77 |
-
CALL "%install_dir%\7zip_installer.exe" /S /D=%seven_zip_dir%
|
| 78 |
-
DEL "%install_dir%\7zip_installer.exe"
|
| 79 |
-
)
|
| 80 |
-
ECHO 7-Zip is installed at %seven_zip_dir%
|
| 81 |
-
|
| 82 |
-
GOTO :eof
|
| 83 |
-
|
| 84 |
-
:uninstall_7zip
|
| 85 |
-
IF EXIST "%seven_zip_dir%\Uninstall.exe" (
|
| 86 |
-
CALL "%seven_zip_dir%\Uninstall.exe" /S
|
| 87 |
-
) ELSE (
|
| 88 |
-
ECHO. && ECHO Uninstaller not found. Manually deleting 7-Zip directory...
|
| 89 |
-
RMDIR /S /Q "%seven_zip_dir%"
|
| 90 |
-
)
|
| 91 |
-
|
| 92 |
-
GOTO :eof
|
| 93 |
-
|
| 94 |
-
:download_and_install_git
|
| 95 |
-
:: Check if Git is already installed
|
| 96 |
-
CALL "%git_install_dir%\bin\git.exe" --version >nul 2>&1
|
| 97 |
-
IF %ERRORLEVEL% NEQ 0 (
|
| 98 |
-
ECHO Install 7-Zip to extract Portable Git. It will be uninstalled automatically after Git installation. && ECHO.
|
| 99 |
-
CALL :download_and_install_7zip
|
| 100 |
-
IF ERRORLEVEL 1 GOTO :end
|
| 101 |
-
|
| 102 |
-
ECHO. && ECHO Downloading Portable Git from %git_download_url%
|
| 103 |
-
CALL curl -Lk "%git_download_url%" -o "%install_dir%\portable_git.7z.exe" || (
|
| 104 |
-
ECHO. && ECHO Failed to download Git. Aborting...
|
| 105 |
-
GOTO :exit_func_with_error
|
| 106 |
-
)
|
| 107 |
-
|
| 108 |
-
ECHO Extracting Git to %git_install_dir%...
|
| 109 |
-
CALL "%seven_zip_dir%\7z.exe" x "%install_dir%\portable_git.7z.exe" -o"%git_install_dir%" -y >nul || (
|
| 110 |
-
ECHO. && ECHO Failed to extract Git. Aborting...
|
| 111 |
-
GOTO :exit_func_with_error
|
| 112 |
-
)
|
| 113 |
-
DEL "%install_dir%\portable_git.7z.exe"
|
| 114 |
-
|
| 115 |
-
ECHO. && ECHO Uninstalling 7-Zip...
|
| 116 |
-
CALL :uninstall_7zip
|
| 117 |
-
IF ERRORLEVEL 1 GOTO :end
|
| 118 |
-
)
|
| 119 |
-
ECHO Git is installed at %git_install_dir%
|
| 120 |
-
:: Recheck Git installation
|
| 121 |
-
CALL "%git_install_dir%\bin\git.exe" --version || (
|
| 122 |
-
ECHO. && ECHO Git not found. Aborting...
|
| 123 |
-
GOTO :exit_func_with_error
|
| 124 |
-
)
|
| 125 |
-
|
| 126 |
-
SET "PATH=%git_install_dir%\bin;%PATH%"
|
| 127 |
-
ECHO Git is added to PATH for this session
|
| 128 |
-
|
| 129 |
-
GOTO :eof
|
| 130 |
-
|
| 131 |
-
:download_and_install_miniconda
|
| 132 |
-
:: If conda has been installed at the %conda_root%, don't need to reinstall it
|
| 133 |
-
CALL "%conda_root%\_conda.exe" --version >nul 2>&1
|
| 134 |
-
IF %ERRORLEVEL% NEQ 0 (
|
| 135 |
-
IF NOT EXIST "%install_dir%\miniconda_installer.exe" (
|
| 136 |
-
ECHO Downloading Miniconda from %miniconda_download_url%
|
| 137 |
-
CALL curl -Lk "%miniconda_download_url%" -o "%install_dir%\miniconda_installer.exe" || (
|
| 138 |
-
ECHO. && ECHO Failed to download Miniconda. Aborting...
|
| 139 |
-
GOTO :exit_func_with_error
|
| 140 |
-
)
|
| 141 |
-
)
|
| 142 |
-
ECHO Installing Miniconda to %conda_root%
|
| 143 |
-
START /wait "" "%install_dir%\miniconda_installer.exe" /InstallationType=JustMe /NoShortcuts=1 /AddToPath=0 /RegisterPython=0 /NoRegistry=1 /S /D=%conda_root%
|
| 144 |
-
DEL "%install_dir%\miniconda_installer.exe"
|
| 145 |
-
)
|
| 146 |
-
ECHO Conda is installed at %conda_root%
|
| 147 |
-
|
| 148 |
-
:: Recheck conda
|
| 149 |
-
ECHO Conda version:
|
| 150 |
-
CALL "%conda_root%\_conda.exe" --version || ( ECHO. && ECHO Conda not found. Aborting... && GOTO :exit_func_with_error )
|
| 151 |
-
|
| 152 |
-
GOTO :eof
|
| 153 |
-
|
| 154 |
-
:create_conda_environment
|
| 155 |
-
:: Create new conda environment if it doesn't exist
|
| 156 |
-
IF NOT EXIST %env_dir% (
|
| 157 |
-
ECHO Creating conda environment with python=%python_version% in %env_dir%
|
| 158 |
-
:: Create conda environment. If the interruption happens, rollback and remove the env_dir
|
| 159 |
-
CALL "%conda_root%\_conda.exe" create --no-shortcuts -y -k --prefix %env_dir% python=%python_version% || (
|
| 160 |
-
ECHO. && ECHO Failed to create conda environment. Will delete the %env_dir% and abort now...
|
| 161 |
-
RMDIR /s /q %env_dir%
|
| 162 |
-
GOTO :exit_func_with_error
|
| 163 |
-
)
|
| 164 |
-
ECHO Conda environment created successfully
|
| 165 |
-
) ELSE (
|
| 166 |
-
ECHO Conda environment exists at %env_dir%
|
| 167 |
-
)
|
| 168 |
-
GOTO :eof
|
| 169 |
-
|
| 170 |
-
:activate_environment
|
| 171 |
-
:: Deactivate existing conda env(s) to avoid conflicts
|
| 172 |
-
IF EXIST "%conda_root%\condabin\conda.bat" (
|
| 173 |
-
CALL "%conda_root%\condabin\conda.bat" deactivate
|
| 174 |
-
CALL "%conda_root%\condabin\conda.bat" deactivate
|
| 175 |
-
CALL "%conda_root%\condabin\conda.bat" deactivate
|
| 176 |
-
)
|
| 177 |
-
|
| 178 |
-
CALL "%env_dir%\python.exe" --version >nul 2>&1 || (
|
| 179 |
-
ECHO The environment appears to be broken. You may need to remove %env_dir% and run the installer again.
|
| 180 |
-
GOTO :exit_func_with_error
|
| 181 |
-
)
|
| 182 |
-
|
| 183 |
-
CALL "%conda_root%\condabin\conda.bat" activate %env_dir% || (
|
| 184 |
-
ECHO Failed to activate environment. You may need to remove %env_dir% and run the installer again.
|
| 185 |
-
GOTO :exit_func_with_error
|
| 186 |
-
)
|
| 187 |
-
ECHO Activate conda environment at %env_dir%
|
| 188 |
-
|
| 189 |
-
GOTO :eof
|
| 190 |
-
|
| 191 |
-
:deactivate_environment
|
| 192 |
-
:: Conda deactivate if we are in the right env
|
| 193 |
-
IF "%CONDA_PREFIX%" == "%env_dir%" (
|
| 194 |
-
CALL "%conda_root%\condabin\conda.bat" deactivate
|
| 195 |
-
ECHO Deactivate conda environment at %env_dir%
|
| 196 |
-
)
|
| 197 |
-
GOTO :eof
|
| 198 |
-
|
| 199 |
-
:install_dependencies
|
| 200 |
-
pip list | findstr /C:"kotaemon" >NUL 2>&1
|
| 201 |
-
IF %ERRORLEVEL% == 0 (
|
| 202 |
-
ECHO Dependencies are already installed
|
| 203 |
-
) ELSE (
|
| 204 |
-
IF EXIST "pyproject.toml" (
|
| 205 |
-
ECHO Found pyproject.toml. Installing from source...
|
| 206 |
-
|
| 207 |
-
ECHO Installing libs\kotaemon
|
| 208 |
-
python -m pip install -e "%CD%\libs\kotaemon"
|
| 209 |
-
|
| 210 |
-
ECHO Installing libs\ktem
|
| 211 |
-
python -m pip install -e "%CD%\libs\ktem"
|
| 212 |
-
|
| 213 |
-
python -m pip install --no-deps -e .
|
| 214 |
-
) ELSE (
|
| 215 |
-
ECHO Installing Kotaemon %app_version%
|
| 216 |
-
@REM Work around for versioning control
|
| 217 |
-
python -m pip install git+https://github.com/Cinnamon/kotaemon.git@"%app_version%"#subdirectory=libs/kotaemon
|
| 218 |
-
python -m pip install git+https://github.com/Cinnamon/kotaemon.git@"%app_version%"#subdirectory=libs/ktem
|
| 219 |
-
python -m pip install --no-deps git+https://github.com/Cinnamon/kotaemon.git@"%app_version%"
|
| 220 |
-
)
|
| 221 |
-
|
| 222 |
-
( CALL pip list | findstr /C:"kotaemon" >NUL 2>&1 ) || (
|
| 223 |
-
ECHO. && ECHO Installation failed. You may need to run the installer again.
|
| 224 |
-
CALL :deactivate_environment
|
| 225 |
-
GOTO :exit_func_with_error
|
| 226 |
-
)
|
| 227 |
-
|
| 228 |
-
CALL :print_highlight "Install successfully. Clear cache..."
|
| 229 |
-
"%conda_root%\condabin\conda.bat" clean --all -y
|
| 230 |
-
python -m pip cache purge
|
| 231 |
-
)
|
| 232 |
-
GOTO :eof
|
| 233 |
-
|
| 234 |
-
:download_and_extract_pdf_js
|
| 235 |
-
:: Download and extract a ZIP file from a URL to a destination directory
|
| 236 |
-
|
| 237 |
-
REM Define variables
|
| 238 |
-
set "pdf_js_version=4.0.379"
|
| 239 |
-
set "pdf_js_dist_name=pdfjs-%pdf_js_version%-dist"
|
| 240 |
-
set "pdf_js_dist_url=https://github.com/mozilla/pdf.js/releases/download/v%pdf_js_version%/%pdf_js_dist_name%.zip"
|
| 241 |
-
for /f "delims=" %%i in ('cd') do set "current_dir=%%i"
|
| 242 |
-
set "target_pdf_js_dir=%current_dir%\libs\ktem\ktem\assets\prebuilt\%pdf_js_dist_name%"
|
| 243 |
-
|
| 244 |
-
REM Create the target directory if it does not exist (including parent folders)
|
| 245 |
-
if not exist "%target_pdf_js_dir%" (
|
| 246 |
-
echo Creating directory %target_pdf_js_dir%
|
| 247 |
-
mkdir "%target_pdf_js_dir%"
|
| 248 |
-
) else (
|
| 249 |
-
echo Directory already exists: %target_pdf_js_dir%
|
| 250 |
-
GOTO :eof
|
| 251 |
-
)
|
| 252 |
-
|
| 253 |
-
REM Download the ZIP file using PowerShell
|
| 254 |
-
set "zip_file=%temp%\downloaded.zip"
|
| 255 |
-
echo Downloading %url% to %zip_file%
|
| 256 |
-
powershell -Command "Invoke-WebRequest -Uri '%pdf_js_dist_url%' -OutFile '%zip_file%'"
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
REM Extract the ZIP file using PowerShell
|
| 260 |
-
echo Extracting %zip_file% to %dest_dir%
|
| 261 |
-
powershell -Command "Expand-Archive -Path '%zip_file%' -DestinationPath '%target_pdf_js_dir%'"
|
| 262 |
-
|
| 263 |
-
REM Clean up the downloaded ZIP file
|
| 264 |
-
del "%zip_file%"
|
| 265 |
-
echo Download and extraction completed successfully.
|
| 266 |
-
|
| 267 |
-
goto :eof
|
| 268 |
-
|
| 269 |
-
:setup_local_model
|
| 270 |
-
python "%CD%\scripts\serve_local.py"
|
| 271 |
-
GOTO :eof
|
| 272 |
-
|
| 273 |
-
:launch_ui
|
| 274 |
-
:: Workaround for diskcache path with folder start with .
|
| 275 |
-
SET THEFLOW_TEMP_PATH=flow_tmp
|
| 276 |
-
SET PDFJS_PREBUILT_DIR=%target_pdf_js_dir%
|
| 277 |
-
ECHO Starting Kotaemon UI... (prebuilt PDF.js is at %PDFJS_PREBUILT_DIR%)
|
| 278 |
-
CALL python "%CD%\app.py" || ( ECHO. && ECHO Will exit now... && GOTO :exit_func_with_error )
|
| 279 |
-
GOTO :eof
|
| 280 |
-
|
| 281 |
-
:print_highlight
|
| 282 |
-
ECHO. && ECHO ******************************************************
|
| 283 |
-
ECHO %~1
|
| 284 |
-
ECHO ****************************************************** && ECHO.
|
| 285 |
-
GOTO :eof
|
| 286 |
-
|
| 287 |
-
:exit_func_with_error
|
| 288 |
-
:: Called inside functions when error happens, then back to the main routine with error code 1
|
| 289 |
-
EXIT /B 1
|
| 290 |
-
|
| 291 |
-
:end_success
|
| 292 |
-
:: Exit the script main routine with error code 0 (success)
|
| 293 |
-
ECHO Script completed successfully.
|
| 294 |
-
PAUSE
|
| 295 |
-
EXIT /B 0
|
| 296 |
-
|
| 297 |
-
:end
|
| 298 |
-
:: Exit the script main routine with error code 1 (fail)
|
| 299 |
-
PAUSE
|
| 300 |
-
EXIT /B 1
|
|
|
|
| 1 |
+
@ECHO off
|
| 2 |
+
|
| 3 |
+
:: Main script execution
|
| 4 |
+
CD /D "%~dp0\.."
|
| 5 |
+
|
| 6 |
+
SET /p app_version=<"%CD%\VERSION" || SET app_version=latest
|
| 7 |
+
SET install_dir=%CD%\install_dir
|
| 8 |
+
SET conda_root=%install_dir%\conda
|
| 9 |
+
SET env_dir=%install_dir%\env
|
| 10 |
+
SET python_version=3.10
|
| 11 |
+
SET miniconda_download_url=https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe
|
| 12 |
+
|
| 13 |
+
SET git_install_dir=%install_dir%\Git
|
| 14 |
+
SET seven_zip_dir=%install_dir%\7zip
|
| 15 |
+
:: Determine if the machine is 32-bit or 64-bit
|
| 16 |
+
IF "%PROCESSOR_ARCHITECTURE%"=="x86" (
|
| 17 |
+
SET seven_zip_url=https://7-zip.org/a/7z2408.exe
|
| 18 |
+
SET git_download_url=https://github.com/git-for-windows/git/releases/download/v2.46.0.windows.1/PortableGit-2.46.0-32-bit.7z.exe
|
| 19 |
+
) ELSE (
|
| 20 |
+
SET seven_zip_url=https://7-zip.org/a/7z2408-x64.exe
|
| 21 |
+
SET git_download_url=https://github.com/git-for-windows/git/releases/download/v2.46.0.windows.1/PortableGit-2.46.0-64-bit.7z.exe
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
ECHO %CD%| FINDSTR /C:" " >nul 2>&1
|
| 25 |
+
IF %ERRORLEVEL% EQU 0 (
|
| 26 |
+
ECHO The current workdir has whitespace which can lead to unintended behaviour. Please modify your path and continue later.
|
| 27 |
+
GOTO :end
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
IF NOT EXIST "%install_dir%" ( MKDIR "%install_dir%" )
|
| 31 |
+
|
| 32 |
+
CALL :print_highlight "Setting up Git"
|
| 33 |
+
CALL :download_and_install_git
|
| 34 |
+
IF ERRORLEVEL 1 GOTO :end
|
| 35 |
+
|
| 36 |
+
:: Temporarily add Portable Git to PATH
|
| 37 |
+
SET "PATH=%git_install_dir%\bin;%PATH%"
|
| 38 |
+
|
| 39 |
+
CALL :print_highlight "Setting up Miniconda"
|
| 40 |
+
CALL :download_and_install_miniconda
|
| 41 |
+
IF ERRORLEVEL 1 GOTO :end
|
| 42 |
+
|
| 43 |
+
CALL :print_highlight "Creating conda environment"
|
| 44 |
+
CALL :create_conda_environment
|
| 45 |
+
IF ERRORLEVEL 1 GOTO :end
|
| 46 |
+
|
| 47 |
+
CALL :activate_environment
|
| 48 |
+
IF ERRORLEVEL 1 GOTO :end
|
| 49 |
+
|
| 50 |
+
CALL :print_highlight "Installing Kotaemon"
|
| 51 |
+
CALL :install_dependencies
|
| 52 |
+
IF ERRORLEVEL 1 GOTO :end
|
| 53 |
+
|
| 54 |
+
CALL :print_highlight "Setting up a local model"
|
| 55 |
+
CALL :setup_local_model
|
| 56 |
+
IF ERRORLEVEL 1 GOTO :end
|
| 57 |
+
|
| 58 |
+
CALL :print_highlight "Downloading and extracting PDF.js"
|
| 59 |
+
CALL :download_and_extract_pdf_js
|
| 60 |
+
IF ERRORLEVEL 1 GOTO :end
|
| 61 |
+
|
| 62 |
+
CALL :print_highlight "Launching Kotaemon in your browser, please wait..."
|
| 63 |
+
CALL :launch_ui
|
| 64 |
+
|
| 65 |
+
CALL :deactivate_environment
|
| 66 |
+
GOTO :end_success
|
| 67 |
+
|
| 68 |
+
:download_and_install_7zip
|
| 69 |
+
:: Check if 7-Zip is installed
|
| 70 |
+
IF NOT EXIST "%seven_zip_dir%\7z.exe" (
|
| 71 |
+
ECHO Downloading 7-Zip from %seven_zip_url%
|
| 72 |
+
CALL curl -Lk "%seven_zip_url%" -o "%install_dir%\7zip_installer.exe" || (
|
| 73 |
+
ECHO. && ECHO Failed to download 7-Zip. Aborting...
|
| 74 |
+
GOTO :exit_func_with_error
|
| 75 |
+
)
|
| 76 |
+
ECHO Installing 7-Zip to %seven_zip_dir%
|
| 77 |
+
CALL "%install_dir%\7zip_installer.exe" /S /D=%seven_zip_dir%
|
| 78 |
+
DEL "%install_dir%\7zip_installer.exe"
|
| 79 |
+
)
|
| 80 |
+
ECHO 7-Zip is installed at %seven_zip_dir%
|
| 81 |
+
|
| 82 |
+
GOTO :eof
|
| 83 |
+
|
| 84 |
+
:uninstall_7zip
|
| 85 |
+
IF EXIST "%seven_zip_dir%\Uninstall.exe" (
|
| 86 |
+
CALL "%seven_zip_dir%\Uninstall.exe" /S
|
| 87 |
+
) ELSE (
|
| 88 |
+
ECHO. && ECHO Uninstaller not found. Manually deleting 7-Zip directory...
|
| 89 |
+
RMDIR /S /Q "%seven_zip_dir%"
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
GOTO :eof
|
| 93 |
+
|
| 94 |
+
:download_and_install_git
|
| 95 |
+
:: Check if Git is already installed
|
| 96 |
+
CALL "%git_install_dir%\bin\git.exe" --version >nul 2>&1
|
| 97 |
+
IF %ERRORLEVEL% NEQ 0 (
|
| 98 |
+
ECHO Install 7-Zip to extract Portable Git. It will be uninstalled automatically after Git installation. && ECHO.
|
| 99 |
+
CALL :download_and_install_7zip
|
| 100 |
+
IF ERRORLEVEL 1 GOTO :end
|
| 101 |
+
|
| 102 |
+
ECHO. && ECHO Downloading Portable Git from %git_download_url%
|
| 103 |
+
CALL curl -Lk "%git_download_url%" -o "%install_dir%\portable_git.7z.exe" || (
|
| 104 |
+
ECHO. && ECHO Failed to download Git. Aborting...
|
| 105 |
+
GOTO :exit_func_with_error
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
ECHO Extracting Git to %git_install_dir%...
|
| 109 |
+
CALL "%seven_zip_dir%\7z.exe" x "%install_dir%\portable_git.7z.exe" -o"%git_install_dir%" -y >nul || (
|
| 110 |
+
ECHO. && ECHO Failed to extract Git. Aborting...
|
| 111 |
+
GOTO :exit_func_with_error
|
| 112 |
+
)
|
| 113 |
+
DEL "%install_dir%\portable_git.7z.exe"
|
| 114 |
+
|
| 115 |
+
ECHO. && ECHO Uninstalling 7-Zip...
|
| 116 |
+
CALL :uninstall_7zip
|
| 117 |
+
IF ERRORLEVEL 1 GOTO :end
|
| 118 |
+
)
|
| 119 |
+
ECHO Git is installed at %git_install_dir%
|
| 120 |
+
:: Recheck Git installation
|
| 121 |
+
CALL "%git_install_dir%\bin\git.exe" --version || (
|
| 122 |
+
ECHO. && ECHO Git not found. Aborting...
|
| 123 |
+
GOTO :exit_func_with_error
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
SET "PATH=%git_install_dir%\bin;%PATH%"
|
| 127 |
+
ECHO Git is added to PATH for this session
|
| 128 |
+
|
| 129 |
+
GOTO :eof
|
| 130 |
+
|
| 131 |
+
:download_and_install_miniconda
|
| 132 |
+
:: If conda has been installed at the %conda_root%, don't need to reinstall it
|
| 133 |
+
CALL "%conda_root%\_conda.exe" --version >nul 2>&1
|
| 134 |
+
IF %ERRORLEVEL% NEQ 0 (
|
| 135 |
+
IF NOT EXIST "%install_dir%\miniconda_installer.exe" (
|
| 136 |
+
ECHO Downloading Miniconda from %miniconda_download_url%
|
| 137 |
+
CALL curl -Lk "%miniconda_download_url%" -o "%install_dir%\miniconda_installer.exe" || (
|
| 138 |
+
ECHO. && ECHO Failed to download Miniconda. Aborting...
|
| 139 |
+
GOTO :exit_func_with_error
|
| 140 |
+
)
|
| 141 |
+
)
|
| 142 |
+
ECHO Installing Miniconda to %conda_root%
|
| 143 |
+
START /wait "" "%install_dir%\miniconda_installer.exe" /InstallationType=JustMe /NoShortcuts=1 /AddToPath=0 /RegisterPython=0 /NoRegistry=1 /S /D=%conda_root%
|
| 144 |
+
DEL "%install_dir%\miniconda_installer.exe"
|
| 145 |
+
)
|
| 146 |
+
ECHO Conda is installed at %conda_root%
|
| 147 |
+
|
| 148 |
+
:: Recheck conda
|
| 149 |
+
ECHO Conda version:
|
| 150 |
+
CALL "%conda_root%\_conda.exe" --version || ( ECHO. && ECHO Conda not found. Aborting... && GOTO :exit_func_with_error )
|
| 151 |
+
|
| 152 |
+
GOTO :eof
|
| 153 |
+
|
| 154 |
+
:create_conda_environment
|
| 155 |
+
:: Create new conda environment if it doesn't exist
|
| 156 |
+
IF NOT EXIST %env_dir% (
|
| 157 |
+
ECHO Creating conda environment with python=%python_version% in %env_dir%
|
| 158 |
+
:: Create conda environment. If the interruption happens, rollback and remove the env_dir
|
| 159 |
+
CALL "%conda_root%\_conda.exe" create --no-shortcuts -y -k --prefix %env_dir% python=%python_version% || (
|
| 160 |
+
ECHO. && ECHO Failed to create conda environment. Will delete the %env_dir% and abort now...
|
| 161 |
+
RMDIR /s /q %env_dir%
|
| 162 |
+
GOTO :exit_func_with_error
|
| 163 |
+
)
|
| 164 |
+
ECHO Conda environment created successfully
|
| 165 |
+
) ELSE (
|
| 166 |
+
ECHO Conda environment exists at %env_dir%
|
| 167 |
+
)
|
| 168 |
+
GOTO :eof
|
| 169 |
+
|
| 170 |
+
:activate_environment
|
| 171 |
+
:: Deactivate existing conda env(s) to avoid conflicts
|
| 172 |
+
IF EXIST "%conda_root%\condabin\conda.bat" (
|
| 173 |
+
CALL "%conda_root%\condabin\conda.bat" deactivate
|
| 174 |
+
CALL "%conda_root%\condabin\conda.bat" deactivate
|
| 175 |
+
CALL "%conda_root%\condabin\conda.bat" deactivate
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
CALL "%env_dir%\python.exe" --version >nul 2>&1 || (
|
| 179 |
+
ECHO The environment appears to be broken. You may need to remove %env_dir% and run the installer again.
|
| 180 |
+
GOTO :exit_func_with_error
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
CALL "%conda_root%\condabin\conda.bat" activate %env_dir% || (
|
| 184 |
+
ECHO Failed to activate environment. You may need to remove %env_dir% and run the installer again.
|
| 185 |
+
GOTO :exit_func_with_error
|
| 186 |
+
)
|
| 187 |
+
ECHO Activate conda environment at %env_dir%
|
| 188 |
+
|
| 189 |
+
GOTO :eof
|
| 190 |
+
|
| 191 |
+
:deactivate_environment
|
| 192 |
+
:: Conda deactivate if we are in the right env
|
| 193 |
+
IF "%CONDA_PREFIX%" == "%env_dir%" (
|
| 194 |
+
CALL "%conda_root%\condabin\conda.bat" deactivate
|
| 195 |
+
ECHO Deactivate conda environment at %env_dir%
|
| 196 |
+
)
|
| 197 |
+
GOTO :eof
|
| 198 |
+
|
| 199 |
+
:install_dependencies
|
| 200 |
+
pip list | findstr /C:"kotaemon" >NUL 2>&1
|
| 201 |
+
IF %ERRORLEVEL% == 0 (
|
| 202 |
+
ECHO Dependencies are already installed
|
| 203 |
+
) ELSE (
|
| 204 |
+
IF EXIST "pyproject.toml" (
|
| 205 |
+
ECHO Found pyproject.toml. Installing from source...
|
| 206 |
+
|
| 207 |
+
ECHO Installing libs\kotaemon
|
| 208 |
+
python -m pip install -e "%CD%\libs\kotaemon"
|
| 209 |
+
|
| 210 |
+
ECHO Installing libs\ktem
|
| 211 |
+
python -m pip install -e "%CD%\libs\ktem"
|
| 212 |
+
|
| 213 |
+
python -m pip install --no-deps -e .
|
| 214 |
+
) ELSE (
|
| 215 |
+
ECHO Installing Kotaemon %app_version%
|
| 216 |
+
@REM Work around for versioning control
|
| 217 |
+
python -m pip install git+https://github.com/Cinnamon/kotaemon.git@"%app_version%"#subdirectory=libs/kotaemon
|
| 218 |
+
python -m pip install git+https://github.com/Cinnamon/kotaemon.git@"%app_version%"#subdirectory=libs/ktem
|
| 219 |
+
python -m pip install --no-deps git+https://github.com/Cinnamon/kotaemon.git@"%app_version%"
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
( CALL pip list | findstr /C:"kotaemon" >NUL 2>&1 ) || (
|
| 223 |
+
ECHO. && ECHO Installation failed. You may need to run the installer again.
|
| 224 |
+
CALL :deactivate_environment
|
| 225 |
+
GOTO :exit_func_with_error
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
CALL :print_highlight "Install successfully. Clear cache..."
|
| 229 |
+
"%conda_root%\condabin\conda.bat" clean --all -y
|
| 230 |
+
python -m pip cache purge
|
| 231 |
+
)
|
| 232 |
+
GOTO :eof
|
| 233 |
+
|
| 234 |
+
:download_and_extract_pdf_js
|
| 235 |
+
:: Download and extract a ZIP file from a URL to a destination directory
|
| 236 |
+
|
| 237 |
+
REM Define variables
|
| 238 |
+
set "pdf_js_version=4.0.379"
|
| 239 |
+
set "pdf_js_dist_name=pdfjs-%pdf_js_version%-dist"
|
| 240 |
+
set "pdf_js_dist_url=https://github.com/mozilla/pdf.js/releases/download/v%pdf_js_version%/%pdf_js_dist_name%.zip"
|
| 241 |
+
for /f "delims=" %%i in ('cd') do set "current_dir=%%i"
|
| 242 |
+
set "target_pdf_js_dir=%current_dir%\libs\ktem\ktem\assets\prebuilt\%pdf_js_dist_name%"
|
| 243 |
+
|
| 244 |
+
REM Create the target directory if it does not exist (including parent folders)
|
| 245 |
+
if not exist "%target_pdf_js_dir%" (
|
| 246 |
+
echo Creating directory %target_pdf_js_dir%
|
| 247 |
+
mkdir "%target_pdf_js_dir%"
|
| 248 |
+
) else (
|
| 249 |
+
echo Directory already exists: %target_pdf_js_dir%
|
| 250 |
+
GOTO :eof
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
REM Download the ZIP file using PowerShell
|
| 254 |
+
set "zip_file=%temp%\downloaded.zip"
|
| 255 |
+
echo Downloading %url% to %zip_file%
|
| 256 |
+
powershell -Command "Invoke-WebRequest -Uri '%pdf_js_dist_url%' -OutFile '%zip_file%'"
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
REM Extract the ZIP file using PowerShell
|
| 260 |
+
echo Extracting %zip_file% to %dest_dir%
|
| 261 |
+
powershell -Command "Expand-Archive -Path '%zip_file%' -DestinationPath '%target_pdf_js_dir%'"
|
| 262 |
+
|
| 263 |
+
REM Clean up the downloaded ZIP file
|
| 264 |
+
del "%zip_file%"
|
| 265 |
+
echo Download and extraction completed successfully.
|
| 266 |
+
|
| 267 |
+
goto :eof
|
| 268 |
+
|
| 269 |
+
:setup_local_model
|
| 270 |
+
python "%CD%\scripts\serve_local.py"
|
| 271 |
+
GOTO :eof
|
| 272 |
+
|
| 273 |
+
:launch_ui
|
| 274 |
+
:: Workaround for diskcache path with folder start with .
|
| 275 |
+
SET THEFLOW_TEMP_PATH=flow_tmp
|
| 276 |
+
SET PDFJS_PREBUILT_DIR=%target_pdf_js_dir%
|
| 277 |
+
ECHO Starting Kotaemon UI... (prebuilt PDF.js is at %PDFJS_PREBUILT_DIR%)
|
| 278 |
+
CALL python "%CD%\app.py" || ( ECHO. && ECHO Will exit now... && GOTO :exit_func_with_error )
|
| 279 |
+
GOTO :eof
|
| 280 |
+
|
| 281 |
+
:print_highlight
|
| 282 |
+
ECHO. && ECHO ******************************************************
|
| 283 |
+
ECHO %~1
|
| 284 |
+
ECHO ****************************************************** && ECHO.
|
| 285 |
+
GOTO :eof
|
| 286 |
+
|
| 287 |
+
:exit_func_with_error
|
| 288 |
+
:: Called inside functions when error happens, then back to the main routine with error code 1
|
| 289 |
+
EXIT /B 1
|
| 290 |
+
|
| 291 |
+
:end_success
|
| 292 |
+
:: Exit the script main routine with error code 0 (success)
|
| 293 |
+
ECHO Script completed successfully.
|
| 294 |
+
PAUSE
|
| 295 |
+
EXIT /B 0
|
| 296 |
+
|
| 297 |
+
:end
|
| 298 |
+
:: Exit the script main routine with error code 1 (fail)
|
| 299 |
+
PAUSE
|
| 300 |
+
EXIT /B 1
|
scripts/server_llamacpp_windows.bat
CHANGED
|
@@ -1,115 +1,115 @@
|
|
| 1 |
-
@echo off
|
| 2 |
-
|
| 3 |
-
@rem main code execution
|
| 4 |
-
|
| 5 |
-
call :print_highlight "Starting inference server for llama-cpp"
|
| 6 |
-
|
| 7 |
-
cd /D "%~dp0\.."
|
| 8 |
-
echo "Change the current directory to: %cd%"
|
| 9 |
-
|
| 10 |
-
call :path_sanity_check
|
| 11 |
-
call :deactivate_environment
|
| 12 |
-
|
| 13 |
-
@rem config
|
| 14 |
-
set ENV_NAME=llama-cpp-python-server
|
| 15 |
-
set PYTHON_VERSION=3.10
|
| 16 |
-
set CONDA_ROOT_PREFIX=%cd%\install_dir\conda
|
| 17 |
-
set INSTALL_ENV_DIR=%cd%\install_dir\server_envs\%ENV_NAME%
|
| 18 |
-
|
| 19 |
-
echo "Python version: %PYTHON_VERSION%"
|
| 20 |
-
echo "Conda prefix: %CONDA_ROOT_PREFIX%"
|
| 21 |
-
echo "Environment path: %INSTALL_ENV_DIR%"
|
| 22 |
-
|
| 23 |
-
@rem handle conda environment
|
| 24 |
-
call :check_conda_existence
|
| 25 |
-
call :create_conda_environment
|
| 26 |
-
call :isolate_environment
|
| 27 |
-
call :activate_environment
|
| 28 |
-
|
| 29 |
-
@rem install dependencies
|
| 30 |
-
@rem ver 0.2.56 produces segment error for /embeddings on MacOS
|
| 31 |
-
call python -m pip install llama-cpp-python[server]==0.2.55
|
| 32 |
-
|
| 33 |
-
@REM @rem start the server with passed params
|
| 34 |
-
call python -m llama_cpp.server %*
|
| 35 |
-
call conda deactivate
|
| 36 |
-
|
| 37 |
-
goto :end
|
| 38 |
-
@rem the end of main code execution
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
@rem below are the functions used in the above execution
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
:print_highlight
|
| 45 |
-
echo.
|
| 46 |
-
echo ******************************************************
|
| 47 |
-
echo %~1
|
| 48 |
-
echo ******************************************************
|
| 49 |
-
echo.
|
| 50 |
-
goto :eof
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
:path_sanity_check
|
| 54 |
-
echo "Path sanity checking"
|
| 55 |
-
echo "%cd%"| findstr /C:" " >nul ^
|
| 56 |
-
&& (call :print_highlight "This script relies on Miniconda which can not be silently installed under a path with spaces." ^
|
| 57 |
-
&& goto :end)
|
| 58 |
-
goto :eof
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
:deactivate_environment
|
| 62 |
-
echo "Deactivate existing environment(s)"
|
| 63 |
-
(call conda deactivate && call conda deactivate && call conda deactivate) 2>nul
|
| 64 |
-
goto :eof
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
:check_conda_existence
|
| 68 |
-
echo "Check for conda existence"
|
| 69 |
-
set conda_exists=F
|
| 70 |
-
|
| 71 |
-
@rem figure out whether conda exists
|
| 72 |
-
call "%CONDA_ROOT_PREFIX%\_conda.exe" --version >nul 2>&1
|
| 73 |
-
if "%ERRORLEVEL%" EQU "0" set conda_exists=T
|
| 74 |
-
|
| 75 |
-
@rem verify if conda is installed by the main app, if not then raise error
|
| 76 |
-
if "%conda_exists%" == "F" (
|
| 77 |
-
call :print_highlight "conda is not installed, seems like the app wasn't installed correctly."
|
| 78 |
-
goto :end
|
| 79 |
-
)
|
| 80 |
-
goto :eof
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
:create_conda_environment
|
| 84 |
-
@rem create the environment if needed
|
| 85 |
-
if not exist "%INSTALL_ENV_DIR%" (
|
| 86 |
-
echo "Create conda environment"
|
| 87 |
-
call "%CONDA_ROOT_PREFIX%\_conda.exe" create ^
|
| 88 |
-
--no-shortcuts -y -k --prefix "%INSTALL_ENV_DIR%" python="%PYTHON_VERSION%" || ^
|
| 89 |
-
( echo. && call :print_highlight "Conda environment creation failed." && goto :end )
|
| 90 |
-
)
|
| 91 |
-
|
| 92 |
-
@rem check if conda environment was actually created
|
| 93 |
-
if not exist "%INSTALL_ENV_DIR%\python.exe" (
|
| 94 |
-
call :print_highlight "Conda environment was not correctly created."
|
| 95 |
-
goto :end
|
| 96 |
-
)
|
| 97 |
-
goto :eof
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
:isolate_environment
|
| 101 |
-
echo "Isolate environment"
|
| 102 |
-
set PYTHONNOUSERSITE=1
|
| 103 |
-
set PYTHONPATH=
|
| 104 |
-
set PYTHONHOME=
|
| 105 |
-
goto :eof
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
:activate_environment
|
| 109 |
-
echo "Activate conda environment"
|
| 110 |
-
call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%" || ^
|
| 111 |
-
( echo. && call :print_highlight "Miniconda hook not found." && goto :end )
|
| 112 |
-
goto :eof
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
:end
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
|
| 3 |
+
@rem main code execution
|
| 4 |
+
|
| 5 |
+
call :print_highlight "Starting inference server for llama-cpp"
|
| 6 |
+
|
| 7 |
+
cd /D "%~dp0\.."
|
| 8 |
+
echo "Change the current directory to: %cd%"
|
| 9 |
+
|
| 10 |
+
call :path_sanity_check
|
| 11 |
+
call :deactivate_environment
|
| 12 |
+
|
| 13 |
+
@rem config
|
| 14 |
+
set ENV_NAME=llama-cpp-python-server
|
| 15 |
+
set PYTHON_VERSION=3.10
|
| 16 |
+
set CONDA_ROOT_PREFIX=%cd%\install_dir\conda
|
| 17 |
+
set INSTALL_ENV_DIR=%cd%\install_dir\server_envs\%ENV_NAME%
|
| 18 |
+
|
| 19 |
+
echo "Python version: %PYTHON_VERSION%"
|
| 20 |
+
echo "Conda prefix: %CONDA_ROOT_PREFIX%"
|
| 21 |
+
echo "Environment path: %INSTALL_ENV_DIR%"
|
| 22 |
+
|
| 23 |
+
@rem handle conda environment
|
| 24 |
+
call :check_conda_existence
|
| 25 |
+
call :create_conda_environment
|
| 26 |
+
call :isolate_environment
|
| 27 |
+
call :activate_environment
|
| 28 |
+
|
| 29 |
+
@rem install dependencies
|
| 30 |
+
@rem ver 0.2.56 produces segment error for /embeddings on MacOS
|
| 31 |
+
call python -m pip install llama-cpp-python[server]==0.2.55
|
| 32 |
+
|
| 33 |
+
@REM @rem start the server with passed params
|
| 34 |
+
call python -m llama_cpp.server %*
|
| 35 |
+
call conda deactivate
|
| 36 |
+
|
| 37 |
+
goto :end
|
| 38 |
+
@rem the end of main code execution
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
@rem below are the functions used in the above execution
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
:print_highlight
|
| 45 |
+
echo.
|
| 46 |
+
echo ******************************************************
|
| 47 |
+
echo %~1
|
| 48 |
+
echo ******************************************************
|
| 49 |
+
echo.
|
| 50 |
+
goto :eof
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
:path_sanity_check
|
| 54 |
+
echo "Path sanity checking"
|
| 55 |
+
echo "%cd%"| findstr /C:" " >nul ^
|
| 56 |
+
&& (call :print_highlight "This script relies on Miniconda which can not be silently installed under a path with spaces." ^
|
| 57 |
+
&& goto :end)
|
| 58 |
+
goto :eof
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
:deactivate_environment
|
| 62 |
+
echo "Deactivate existing environment(s)"
|
| 63 |
+
(call conda deactivate && call conda deactivate && call conda deactivate) 2>nul
|
| 64 |
+
goto :eof
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
:check_conda_existence
|
| 68 |
+
echo "Check for conda existence"
|
| 69 |
+
set conda_exists=F
|
| 70 |
+
|
| 71 |
+
@rem figure out whether conda exists
|
| 72 |
+
call "%CONDA_ROOT_PREFIX%\_conda.exe" --version >nul 2>&1
|
| 73 |
+
if "%ERRORLEVEL%" EQU "0" set conda_exists=T
|
| 74 |
+
|
| 75 |
+
@rem verify if conda is installed by the main app, if not then raise error
|
| 76 |
+
if "%conda_exists%" == "F" (
|
| 77 |
+
call :print_highlight "conda is not installed, seems like the app wasn't installed correctly."
|
| 78 |
+
goto :end
|
| 79 |
+
)
|
| 80 |
+
goto :eof
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
:create_conda_environment
|
| 84 |
+
@rem create the environment if needed
|
| 85 |
+
if not exist "%INSTALL_ENV_DIR%" (
|
| 86 |
+
echo "Create conda environment"
|
| 87 |
+
call "%CONDA_ROOT_PREFIX%\_conda.exe" create ^
|
| 88 |
+
--no-shortcuts -y -k --prefix "%INSTALL_ENV_DIR%" python="%PYTHON_VERSION%" || ^
|
| 89 |
+
( echo. && call :print_highlight "Conda environment creation failed." && goto :end )
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
@rem check if conda environment was actually created
|
| 93 |
+
if not exist "%INSTALL_ENV_DIR%\python.exe" (
|
| 94 |
+
call :print_highlight "Conda environment was not correctly created."
|
| 95 |
+
goto :end
|
| 96 |
+
)
|
| 97 |
+
goto :eof
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
:isolate_environment
|
| 101 |
+
echo "Isolate environment"
|
| 102 |
+
set PYTHONNOUSERSITE=1
|
| 103 |
+
set PYTHONPATH=
|
| 104 |
+
set PYTHONHOME=
|
| 105 |
+
goto :eof
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
:activate_environment
|
| 109 |
+
echo "Activate conda environment"
|
| 110 |
+
call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%" || ^
|
| 111 |
+
( echo. && call :print_highlight "Miniconda hook not found." && goto :end )
|
| 112 |
+
goto :eof
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
:end
|
scripts/update_windows.bat
CHANGED
|
@@ -1,99 +1,99 @@
|
|
| 1 |
-
@ECHO off
|
| 2 |
-
|
| 3 |
-
:: Main script execution
|
| 4 |
-
CD /D "%~dp0\.."
|
| 5 |
-
|
| 6 |
-
SET app_version=latest
|
| 7 |
-
SET install_dir=%CD%\install_dir
|
| 8 |
-
SET conda_root=%install_dir%\conda
|
| 9 |
-
SET env_dir=%install_dir%\env
|
| 10 |
-
|
| 11 |
-
ECHO %CD%| FINDSTR /C:" " >nul 2>&1
|
| 12 |
-
IF %ERRORLEVEL% EQU 0 (
|
| 13 |
-
ECHO The current workdir has whitespace which can lead to unintended behaviour. Please modify your path and continue later.
|
| 14 |
-
GOTO :end
|
| 15 |
-
)
|
| 16 |
-
|
| 17 |
-
CALL :print_highlight "Activating conda environment"
|
| 18 |
-
CALL :activate_environment
|
| 19 |
-
IF ERRORLEVEL 1 GOTO :end
|
| 20 |
-
|
| 21 |
-
CALL :print_highlight "Updating Kotaemon to latest"
|
| 22 |
-
CALL :update_latest
|
| 23 |
-
IF ERRORLEVEL 1 GOTO :end
|
| 24 |
-
|
| 25 |
-
CALL :deactivate_environment
|
| 26 |
-
GOTO :end_success
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
:activate_environment
|
| 30 |
-
:: deactivate existing conda env(s) to avoid conflicts
|
| 31 |
-
( CALL conda deactivate && CALL conda deactivate && CALL conda deactivate ) 2> nul
|
| 32 |
-
|
| 33 |
-
CALL "%env_dir%\python.exe" --version >nul 2>&1 || (
|
| 34 |
-
ECHO The environment appears to be broken. You may need to remove %env_dir% and run the installer again.
|
| 35 |
-
GOTO :exit_func_with_error
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
CALL "%conda_root%\condabin\conda.bat" activate %env_dir% || (
|
| 39 |
-
ECHO Failed to activate environment. You may need to remove %env_dir% and run the installer again.
|
| 40 |
-
GOTO :exit_func_with_error
|
| 41 |
-
)
|
| 42 |
-
ECHO Activate conda environment at %env_dir%
|
| 43 |
-
|
| 44 |
-
GOTO :eof
|
| 45 |
-
|
| 46 |
-
:deactivate_environment
|
| 47 |
-
:: Conda deactivate if we are in the right env
|
| 48 |
-
IF "%CONDA_PREFIX%" == "%env_dir%" (
|
| 49 |
-
CALL "%conda_root%\condabin\conda.bat" deactivate
|
| 50 |
-
ECHO Deactivate conda environment at %env_dir%
|
| 51 |
-
)
|
| 52 |
-
GOTO :eof
|
| 53 |
-
|
| 54 |
-
:update_latest
|
| 55 |
-
FOR /F "tokens=1,2" %%a in ('pip list') do if "%%a"=="kotaemon-app" set current_version=%%b
|
| 56 |
-
ECHO Current version %current_version%
|
| 57 |
-
|
| 58 |
-
IF EXIST "pyproject.toml" (
|
| 59 |
-
ECHO Source files detected. Please perform git pull manually.
|
| 60 |
-
CALL :deactivate_environment
|
| 61 |
-
GOTO :exit_func_with_error
|
| 62 |
-
) ELSE (
|
| 63 |
-
ECHO Installing version: %app_version%
|
| 64 |
-
@REM Work around for versioning control
|
| 65 |
-
python -m pip install git+https://github.com/Cinnamon/kotaemon.git@"%app_version%"#subdirectory=libs/kotaemon
|
| 66 |
-
python -m pip install git+https://github.com/Cinnamon/kotaemon.git@"%app_version%"#subdirectory=libs/ktem
|
| 67 |
-
python -m pip install --no-deps git+https://github.com/Cinnamon/kotaemon.git@"%app_version%"
|
| 68 |
-
) || (
|
| 69 |
-
ECHO. && ECHO Update failed. You may need to run the update again.
|
| 70 |
-
CALL :deactivate_environment
|
| 71 |
-
GOTO :exit_func_with_error
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
CALL :print_highlight "Update successfully."
|
| 75 |
-
FOR /F "tokens=1,2" %%a in ('pip list') do if "%%a"=="kotaemon-app" set updated_version=%%b
|
| 76 |
-
ECHO Updated version %updated_version%
|
| 77 |
-
ECHO %updated_version% > VERSION
|
| 78 |
-
GOTO :eof
|
| 79 |
-
|
| 80 |
-
:print_highlight
|
| 81 |
-
ECHO. && ECHO ******************************************************
|
| 82 |
-
ECHO %~1
|
| 83 |
-
ECHO ****************************************************** && ECHO.
|
| 84 |
-
GOTO :eof
|
| 85 |
-
|
| 86 |
-
:exit_func_with_error
|
| 87 |
-
:: Called inside functions when error happens, then back to the main routine with error code 1
|
| 88 |
-
EXIT /B 1
|
| 89 |
-
|
| 90 |
-
:end_success
|
| 91 |
-
:: Exit the script main routine with error code 0 (success)
|
| 92 |
-
ECHO Script completed successfully.
|
| 93 |
-
PAUSE
|
| 94 |
-
EXIT /B 0
|
| 95 |
-
|
| 96 |
-
:end
|
| 97 |
-
:: Exit the script main routine with error code 1 (fail)
|
| 98 |
-
PAUSE
|
| 99 |
-
EXIT /B 1
|
|
|
|
| 1 |
+
@ECHO off
|
| 2 |
+
|
| 3 |
+
:: Main script execution
|
| 4 |
+
CD /D "%~dp0\.."
|
| 5 |
+
|
| 6 |
+
SET app_version=latest
|
| 7 |
+
SET install_dir=%CD%\install_dir
|
| 8 |
+
SET conda_root=%install_dir%\conda
|
| 9 |
+
SET env_dir=%install_dir%\env
|
| 10 |
+
|
| 11 |
+
ECHO %CD%| FINDSTR /C:" " >nul 2>&1
|
| 12 |
+
IF %ERRORLEVEL% EQU 0 (
|
| 13 |
+
ECHO The current workdir has whitespace which can lead to unintended behaviour. Please modify your path and continue later.
|
| 14 |
+
GOTO :end
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
CALL :print_highlight "Activating conda environment"
|
| 18 |
+
CALL :activate_environment
|
| 19 |
+
IF ERRORLEVEL 1 GOTO :end
|
| 20 |
+
|
| 21 |
+
CALL :print_highlight "Updating Kotaemon to latest"
|
| 22 |
+
CALL :update_latest
|
| 23 |
+
IF ERRORLEVEL 1 GOTO :end
|
| 24 |
+
|
| 25 |
+
CALL :deactivate_environment
|
| 26 |
+
GOTO :end_success
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
:activate_environment
|
| 30 |
+
:: deactivate existing conda env(s) to avoid conflicts
|
| 31 |
+
( CALL conda deactivate && CALL conda deactivate && CALL conda deactivate ) 2> nul
|
| 32 |
+
|
| 33 |
+
CALL "%env_dir%\python.exe" --version >nul 2>&1 || (
|
| 34 |
+
ECHO The environment appears to be broken. You may need to remove %env_dir% and run the installer again.
|
| 35 |
+
GOTO :exit_func_with_error
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
CALL "%conda_root%\condabin\conda.bat" activate %env_dir% || (
|
| 39 |
+
ECHO Failed to activate environment. You may need to remove %env_dir% and run the installer again.
|
| 40 |
+
GOTO :exit_func_with_error
|
| 41 |
+
)
|
| 42 |
+
ECHO Activate conda environment at %env_dir%
|
| 43 |
+
|
| 44 |
+
GOTO :eof
|
| 45 |
+
|
| 46 |
+
:deactivate_environment
|
| 47 |
+
:: Conda deactivate if we are in the right env
|
| 48 |
+
IF "%CONDA_PREFIX%" == "%env_dir%" (
|
| 49 |
+
CALL "%conda_root%\condabin\conda.bat" deactivate
|
| 50 |
+
ECHO Deactivate conda environment at %env_dir%
|
| 51 |
+
)
|
| 52 |
+
GOTO :eof
|
| 53 |
+
|
| 54 |
+
:update_latest
|
| 55 |
+
FOR /F "tokens=1,2" %%a in ('pip list') do if "%%a"=="kotaemon-app" set current_version=%%b
|
| 56 |
+
ECHO Current version %current_version%
|
| 57 |
+
|
| 58 |
+
IF EXIST "pyproject.toml" (
|
| 59 |
+
ECHO Source files detected. Please perform git pull manually.
|
| 60 |
+
CALL :deactivate_environment
|
| 61 |
+
GOTO :exit_func_with_error
|
| 62 |
+
) ELSE (
|
| 63 |
+
ECHO Installing version: %app_version%
|
| 64 |
+
@REM Work around for versioning control
|
| 65 |
+
python -m pip install git+https://github.com/Cinnamon/kotaemon.git@"%app_version%"#subdirectory=libs/kotaemon
|
| 66 |
+
python -m pip install git+https://github.com/Cinnamon/kotaemon.git@"%app_version%"#subdirectory=libs/ktem
|
| 67 |
+
python -m pip install --no-deps git+https://github.com/Cinnamon/kotaemon.git@"%app_version%"
|
| 68 |
+
) || (
|
| 69 |
+
ECHO. && ECHO Update failed. You may need to run the update again.
|
| 70 |
+
CALL :deactivate_environment
|
| 71 |
+
GOTO :exit_func_with_error
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
CALL :print_highlight "Update successfully."
|
| 75 |
+
FOR /F "tokens=1,2" %%a in ('pip list') do if "%%a"=="kotaemon-app" set updated_version=%%b
|
| 76 |
+
ECHO Updated version %updated_version%
|
| 77 |
+
ECHO %updated_version% > VERSION
|
| 78 |
+
GOTO :eof
|
| 79 |
+
|
| 80 |
+
:print_highlight
|
| 81 |
+
ECHO. && ECHO ******************************************************
|
| 82 |
+
ECHO %~1
|
| 83 |
+
ECHO ****************************************************** && ECHO.
|
| 84 |
+
GOTO :eof
|
| 85 |
+
|
| 86 |
+
:exit_func_with_error
|
| 87 |
+
:: Called inside functions when error happens, then back to the main routine with error code 1
|
| 88 |
+
EXIT /B 1
|
| 89 |
+
|
| 90 |
+
:end_success
|
| 91 |
+
:: Exit the script main routine with error code 0 (success)
|
| 92 |
+
ECHO Script completed successfully.
|
| 93 |
+
PAUSE
|
| 94 |
+
EXIT /B 0
|
| 95 |
+
|
| 96 |
+
:end
|
| 97 |
+
:: Exit the script main routine with error code 1 (fail)
|
| 98 |
+
PAUSE
|
| 99 |
+
EXIT /B 1
|