diff --git a/clever_install.bat b/clever_install.bat new file mode 100644 index 00000000..bde01903 --- /dev/null +++ b/clever_install.bat @@ -0,0 +1,118 @@ +@echo off + +@rem This script will install miniconda and git with all dependencies for this project +@rem This enables a user to install this project without manually installing conda and git. + +@rem workaround for broken Windows installs +set PATH=%PATH%;%SystemRoot%\system32 + +cd /D "%~dp0" + +echo "%cd%"| findstr /C:" " >nul && call :PrintBigMessage "This script relies on Miniconda which can not be silently installed under a path with spaces." && goto end +call :PrintBigMessage "WARNING: This script relies on Miniconda which will fail to install if the path is too long." +set "SPCHARMESSAGE="WARNING: Special characters were detected in the installation path!" " This can cause the installation to fail!"" +echo "%CD%"| findstr /R /C:"[!#\$%&()\*+,;<=>?@\[\]\^`{|}~]" >nul && ( + call :PrintBigMessage %SPCHARMESSAGE% +) +set SPCHARMESSAGE= + +pause +cls + +echo What is your GPU? +echo. +echo A) NVIDIA +echo B) None (I want to run in CPU mode) +echo. +set /p "gpuchoice=Input> " +set gpuchoice=%gpuchoice:~0,1% + +if /I "%gpuchoice%" == "A" ( + set "PACKAGES_TO_INSTALL=python=3.10 cuda-toolkit ninja git" + set "CHANNEL=-c nvidia/label/cuda-11.7.0 -c nvidia -c conda-forge" +) else if /I "%gpuchoice%" == "B" ( + set "PACKAGES_TO_INSTALL=python=3.10 ninja git" + set "CHANNEL=-c conda-forge" +) else ( + echo Invalid choice. Exiting... + exit +) + +@rem better isolation for virtual environment +SET "CONDA_SHLVL=" +SET PYTHONNOUSERSITE=1 +SET "PYTHONPATH=" +SET "PYTHONHOME=" +SET "TEMP=%cd%\installer_files\temp" +SET "TMP=%cd%\installer_files\temp" + +set MINICONDA_DIR=%cd%\installer_files\miniconda3 +set INSTALL_ENV_DIR=%cd%\installer_files\env +set MINICONDA_DOWNLOAD_URL=https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe +set REPO_URL=https://github.com/ParisNeo/lollms-webui.git + +if not exist "%MINICONDA_DIR%\Scripts\conda.exe" ( + @rem download miniconda + echo Downloading Miniconda installer from %MINICONDA_DOWNLOAD_URL% + call curl -LOk "%MINICONDA_DOWNLOAD_URL%" + + @rem install miniconda + echo. && echo Installing Miniconda To "%MINICONDA_DIR%" && echo Please Wait... && echo. + start "" /W /D "%cd%" "Miniconda3-latest-Windows-x86_64.exe" /InstallationType=JustMe /NoShortcuts=1 /AddToPath=0 /RegisterPython=0 /NoRegistry=1 /S /D=%MINICONDA_DIR% || ( echo. && echo Miniconda installer not found. && goto end ) + del /q "Miniconda3-latest-Windows-x86_64.exe" + if not exist "%MINICONDA_DIR%\Scripts\activate.bat" ( echo. && echo Miniconda install failed. && goto end ) +) + +@rem activate miniconda +call "%MINICONDA_DIR%\Scripts\activate.bat" || ( echo Miniconda hook not found. && goto end ) + +@rem create the installer env +if not exist "%INSTALL_ENV_DIR%" ( + echo Packages to install: %PACKAGES_TO_INSTALL% + call conda create --no-shortcuts -y -k -p "%INSTALL_ENV_DIR%" %CHANNEL% %PACKAGES_TO_INSTALL% || ( echo. && echo Conda environment creation failed. && goto end ) + if /I "%gpuchoice%" == "A" call conda run --live-stream -p "%INSTALL_ENV_DIR%" python -m pip install torch==2.0.1+cu117 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117|| ( echo. && echo Pytorch installation failed.&& goto end ) + if /I "%gpuchoice%" == "B" call conda run --live-stream -p "%INSTALL_ENV_DIR%" python -m pip install torch torchvision torchaudio|| ( echo. && echo Pytorch installation failed.&& goto end ) +) + +@rem check if conda environment was actually created +if not exist "%INSTALL_ENV_DIR%\python.exe" ( echo. && echo Conda environment is empty. && goto end ) + +@rem activate installer env +call conda activate "%INSTALL_ENV_DIR%" || ( echo. && echo Conda environment activation failed. && goto end ) + +@rem set default cuda toolkit to the one in the environment +set "CUDA_PATH=%INSTALL_ENV_DIR%" + +@rem clone the repository +if exist lollms-webui\ ( + cd lollms-webui + git pull +) else ( + git clone https://github.com/ParisNeo/lollms-webui.git + cd lollms-webui || goto end +) + +@rem Loop through each "git+" requirement and uninstall it workaround for inconsistent git package updating +for /F "delims=" %%a in (requirements.txt) do echo "%%a"| findstr /C:"git+" >nul&& for /F "tokens=4 delims=/" %%b in ("%%a") do for /F "delims=@" %%c in ("%%b") do python -m pip uninstall -y %%c + +@rem install the pip requirements +call python -m pip install -r requirements.txt --upgrade + +@rem create launcher +if exist ..\clever_run.bat ( + echo Clever run found +) else ( + copy clever_run.bat ..\ + goto end +) + +:PrintBigMessage +echo. && echo. +echo ******************************************************************* +for %%M in (%*) do echo * %%~M +echo ******************************************************************* +echo. && echo. +exit /b + +:end +pause diff --git a/clever_install.sh b/clever_install.sh new file mode 100644 index 00000000..76e8f18e --- /dev/null +++ b/clever_install.sh @@ -0,0 +1,134 @@ +#!/bin/bash + +# This script will install miniconda and git with all dependencies for this project +# This enables a user to install this project without manually installing conda and git. + + +cd "$(dirname "$0")" + +if [[ "$PWD" == *" "* ]]; then + echo "This script relies on Miniconda which cannot be silently installed under a path with spaces." + exit 1 +fi + +echo "WARNING: This script relies on Miniconda which will fail to install if the path is too long." + +if [[ "$PWD" =~ [^#\$\%\&\(\)\*\+\] ]]; then + echo "WARNING: Special characters were detected in the installation path!" + echo " This can cause the installation to fail!" +fi + + + + +read -rp "Press Enter to continue..." + +clear + +echo "What is your GPU?" +echo +echo "A) NVIDIA" +echo "B) None (I want to run in CPU mode)" +echo +read -rp "Input> " gpuchoice +gpuchoice="${gpuchoice:0:1}" + +if [[ "${gpuchoice^^}" == "A" ]]; then + PACKAGES_TO_INSTALL="python=3.10 cuda-toolkit ninja git" + CHANNEL="-c nvidia/label/cuda-11.7.0 -c nvidia -c conda-forge" +elif [[ "${gpuchoice^^}" == "B" ]]; then + PACKAGES_TO_INSTALL="python=3.10 ninja git" + CHANNEL="-c conda-forge" +else + echo "Invalid choice. Exiting..." + exit 1 +fi + +# Better isolation for virtual environment +unset CONDA_SHLVL +export PYTHONNOUSERSITE=1 +unset PYTHONPATH +unset PYTHONHOME +export TEMP="$PWD/installer_files/temp" +export TMP="$PWD/installer_files/temp" + +MINICONDA_DIR="$PWD/installer_files/miniconda3" +INSTALL_ENV_DIR="$PWD/installer_files/env" +MINICONDA_DOWNLOAD_URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" +REPO_URL="https://github.com/ParisNeo/lollms-webui.git" + +if [ ! -f "$MINICONDA_DIR/Scripts/conda" ]; then + # Download miniconda + echo "Downloading Miniconda installer from $MINICONDA_DOWNLOAD_URL" + curl -LOk "$MINICONDA_DOWNLOAD_URL" + + # Install miniconda + echo + echo "Installing Miniconda to $MINICONDA_DIR" + echo "Please wait..." + echo + bash "Miniconda3-latest-Linux-x86_64.sh" -b -p "$MINICONDA_DIR" || ( echo && echo "Miniconda installer not found." && exit 1 ) + rm -f "Miniconda3-latest-Linux-x86_64.sh" + if [ ! -f "$MINICONDA_DIR/bin/activate" ]; then + echo && echo "Miniconda install failed." && exit 1 + fi +fi + +# Activate miniconda +source "$MINICONDA_DIR/bin/activate" || ( echo "Miniconda hook not found." && exit 1 ) + +# Create the installer environment +if [ ! -d "$INSTALL_ENV_DIR" ]; then + echo "Packages to install: $PACKAGES_TO_INSTALL" + conda create --no-shortcuts -y -k -p "$INSTALL_ENV_DIR" $CHANNEL $PACKAGES_TO_INSTALL || ( echo && echo "Conda environment creation failed." && exit 1 ) + if [[ "${gpuchoice^^}" == "A" ]]; then + conda run --live-stream -p "$INSTALL_ENV_DIR" python -m pip install torch==2.0.1+cu117 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117 || ( echo && echo "Pytorch installation failed." && exit 1 ) + elif [[ "${gpuchoice^^}" == "B" ]]; then + conda run --live-stream -p "$INSTALL_ENV_DIR" python -m pip install torch torchvision torchaudio || ( echo && echo "Pytorch installation failed." && exit 1 ) + fi +fi + +# Check if conda environment was actually created +if [ ! -x "$INSTALL_ENV_DIR/bin/python" ]; then + echo && echo "Conda environment is empty." && exit 1 +fi + +# Activate installer environment +source activate "$INSTALL_ENV_DIR" || ( echo && echo "Conda environment activation failed." && exit 1 ) + +# Set default cuda toolkit to the one in the environment +export CUDA_PATH="$INSTALL_ENV_DIR" + +# Clone the repository +if [ -d "lollms-webui" ]; then + cd lollms-webui || exit 1 + git pull +else + git clone "$REPO_URL" + cd lollms-webui || exit 1 +fi + +# Loop through each "git+" requirement and uninstall it (workaround for inconsistent git package updating) +while IFS= read -r requirement; do + if echo "$requirement" | grep -q "git+"; then + package_name=$(echo "$requirement" | awk -F'/' '{ print $4 }' | awk -F'@' '{ print $1 }') + python -m pip uninstall -y "$package_name" + fi +done < requirements.txt + +# Install the pip requirements +python -m pip install -r requirements.txt --upgrade + +PrintBigMessage() { + echo + echo "*******************************************************************" + for message in "$@"; do + echo "* $message" + done + echo "*******************************************************************" + echo +} + +PrintBigMessage "$@" + +exit 0 \ No newline at end of file diff --git a/clever_run.bat b/clever_run.bat new file mode 100644 index 00000000..0335a03f --- /dev/null +++ b/clever_run.bat @@ -0,0 +1,30 @@ +@echo off +@echo Starting LOLLMS Web UI... + +cd /D "%~dp0" + +@rem better isolation for virtual environment +SET "CONDA_SHLVL=" +SET PYTHONNOUSERSITE=1 +SET "PYTHONPATH=" +SET "PYTHONHOME=" +SET "TEMP=%cd%\installer_files\temp" +SET "TMP=%cd%\installer_files\temp" + +@rem workaround for broken Windows installs +set PATH=%PATH%;%SystemRoot%\system32 + +set INSTALL_ENV_DIR=%cd%\installer_files\env +set MINICONDA_DIR=%cd%\installer_files\miniconda3 + +if not exist "%MINICONDA_DIR%\Scripts\activate.bat" ( echo Miniconda not found. && goto end ) +call "%MINICONDA_DIR%\Scripts\activate.bat" activate "%INSTALL_ENV_DIR%" +cd lollms-webui + +@rem set default cuda toolkit to the one in the environment +set "CUDA_PATH=%INSTALL_ENV_DIR%" + +call python app.py %* + +:end +pause diff --git a/clever_run.sh b/clever_run.sh new file mode 100644 index 00000000..c637a9f4 --- /dev/null +++ b/clever_run.sh @@ -0,0 +1,29 @@ +#!/bin/bash +echo Starting LOLLMS Web UI... + +cd "$(dirname "$0")" + +# better isolation for virtual environment +CONDA_SHLVL="" +PYTHONNOUSERSITE=1 +PYTHONPATH="" +PYTHONHOME="" +TEMP="$(pwd)/installer_files/temp" +TMP="$(pwd)/installer_files/temp" +INSTALL_ENV_DIR="$(pwd)/installer_files/env" +MINICONDA_DIR="$(pwd)/installer_files/miniconda3" + +if [ ! -f "$MINICONDA_DIR/bin/activate.bat" ]; then + echo "Miniconda not found." + exit 1 +fi + +source "$MINICONDA_DIR/bin/activate.bat" activate "$INSTALL_ENV_DIR" +cd lollms-webui + +# set default cuda toolkit to the one in the environment +CUDA_PATH="$INSTALL_ENV_DIR" + +python app.py "$@" + +pause