From c36c5f6545bfb3b31000798729b252f1097aba25 Mon Sep 17 00:00:00 2001 From: deffcolony <61471128+deffcolony@users.noreply.github.com> Date: Thu, 18 Jan 2024 19:19:19 +0100 Subject: [PATCH] launcher upgrades +added option to update menu for updating sillytavern-launcher repo +added more checks if git pull fails then retry 3 times +gitignore the xtts folder +added option to cancel install for install.sh -forgot to remove xtts launch from extras launch --- .gitignore | 1 + Launcher.bat | 82 ++++++++++++++++++++---------------- install.sh | 114 +++++++++++++++++++++++++++------------------------ launcher.sh | 91 +++++++++++++++++++++------------------- 4 files changed, 156 insertions(+), 132 deletions(-) diff --git a/.gitignore b/.gitignore index 3e687f3..023a5b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ SillyTavern/ SillyTavern-extras/ +xtts/ modules.txt \ No newline at end of file diff --git a/Launcher.bat b/Launcher.bat index 132e81a..d16fd1e 100644 --- a/Launcher.bat +++ b/Launcher.bat @@ -219,23 +219,6 @@ goto :home :start_extras -REM Check if XTTS environment exists -set "xtts_env_exist=" -call conda activate xtts && set "xtts_env_exist=1" || set "xtts_env_exist=" - -REM Ask the user if they want to start XTTS only if the environment exists -if defined xtts_env_exist ( - set /p start_xtts=Start XTTS as well? [Y/N] - if /i "%start_xtts%"=="Y" ( - REM Activate the xtts environment - call conda activate xtts - - REM Start XTTS - echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% XTTS launched in a new window. - start cmd /k "title XTTSv2 API Server && cd /d %~dp0xtts && python -m xtts_api_server" - ) -) - REM Run conda activate from the Miniconda installation call "%miniconda_path%\Scripts\activate.bat" @@ -326,37 +309,66 @@ goto :home :update title SillyTavern [UPDATE] +REM Update SillyTavern-Launcher +set max_retries=3 +set retry_count=0 + +:retry_update_st_launcher +echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Updating SillyTavern-Launcher... +cd /d "%~dp0" +call git pull +if %errorlevel% neq 0 ( + set /A retry_count+=1 + echo %yellow_bg%[%time%]%reset% %yellow_fg_strong%[WARN] Retry %retry_count% of %max_retries%%reset% + if %retry_count% lss %max_retries% goto :retry_update_st_launcher + echo %red_bg%[%time%]%reset% %red_fg_strong%[ERROR] Failed to update SillyTavern-Launcher repository after %max_retries% retries.%reset% + pause + goto :home +) + +echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%SillyTavern-Launcher updated successfully.%reset% + +REM Update SillyTavern +set max_retries=3 +set retry_count=0 + +:retry_update_st echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Updating SillyTavern... cd /d "%~dp0SillyTavern" -REM Check if git is installed -git --version > nul 2>&1 +call git pull if %errorlevel% neq 0 ( - echo %red_bg%[%time%]%reset% %red_fg_strong%[ERROR] git command not found in PATH. Skipping update.%reset% - echo %red_bg%Please make sure Git is installed and added to your PATH.%reset% -) else ( - call git pull --rebase --autostash - if %errorlevel% neq 0 ( - REM incase there is still something wrong - echo %red_bg%[%time%]%reset% %red_fg_strong%[ERROR] Errors while updating.%reset% - ) else ( - echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%SillyTavern updated successfully.%reset% - ) + set /A retry_count+=1 + echo %yellow_bg%[%time%]%reset% %yellow_fg_strong%[WARN] Retry %retry_count% of %max_retries%%reset% + if %retry_count% lss %max_retries% goto :retry_update_st + echo %red_bg%[%time%]%reset% %red_fg_strong%[ERROR] Failed to update SillyTavern repository after %max_retries% retries.%reset% + pause + goto :home ) +echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%SillyTavern updated successfully.%reset% + + REM Check if SillyTavern-extras directory exists if not exist "%~dp0SillyTavern-extras" ( echo %yellow_bg%[%time%]%reset% %yellow_fg_strong%[WARN] SillyTavern-extras directory not found. Skipping extras update.%reset% goto :update_xtts ) -cd /d "%~dp0SillyTavern-extras" + +REM Update SillyTavern-extras +set max_retries=3 +set retry_count=0 + +:retry_update_extras echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Updating SillyTavern-extras... +cd /d "%~dp0SillyTavern-extras" call git pull if %errorlevel% neq 0 ( - REM in case there is still something wrong - echo %red_bg%[%time%]%reset% %red_fg_strong%[ERROR] Errors while updating.%reset% -) else ( - echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%SillyTavern-extras updated successfully.%reset% - goto :update_xtts + set /A retry_count+=1 + echo %yellow_bg%[%time%]%reset% %yellow_fg_strong%[WARN] Retry %retry_count% of %max_retries%%reset% + if %retry_count% lss %max_retries% goto :retry_update_extras + echo %red_bg%[%time%]%reset% %red_fg_strong%[ERROR] Failed to update SillyTavern-extras repository after %max_retries% retries.%reset% + pause + goto :home ) :update_xtts diff --git a/install.sh b/install.sh index e6e2068..5397ab3 100755 --- a/install.sh +++ b/install.sh @@ -309,6 +309,7 @@ install_st_extras() { echo -e "1. NVIDIA" echo -e "2. AMD" echo -e "3. None (CPU-only mode)" + echo -e "0. Cancel install" # Get GPU information gpu_info="" @@ -341,6 +342,8 @@ install_st_extras() { elif [ "$gpu_choice" == "3" ]; then log_message "INFO" "Using CPU-only mode" install_st_extras_pre + elif [ "$gpu_choice" == "0" ]; then + installer else log_message "ERROR" "${red_fg_strong}Invalid number. Please enter a valid number.${reset}" read -p "Press Enter to continue..." @@ -417,70 +420,70 @@ install_st_extras_pre() { # Function to install_xtts install_xtts() { - log_message "INFO" "Installing XTTS..." + log_message "INFO" "Installing XTTS..." - # Activate the Miniconda installation - log_message "INFO" "Activating Miniconda environment..." - source "$miniconda_path/bin/activate" + # Activate the Miniconda installation + log_message "INFO" "Activating Miniconda environment..." + source "$miniconda_path/bin/activate" - # Create a Conda environment named xtts - log_message "INFO" "Creating Conda environment xtts..." - conda create -n xtts -y + # Create a Conda environment named xtts + log_message "INFO" "Creating Conda environment xtts..." + conda create -n xtts -y - # Activate the xtts environment - log_message "INFO" "Activating Conda environment xtts..." - source activate xtts + # Activate the xtts environment + log_message "INFO" "Activating Conda environment xtts..." + source activate xtts - # Check if xtts activation was successful - if [ $? -eq 0 ]; then - log_message "INFO" "Conda environment xtts activated successfully." - else - log_message "ERROR" "${red_fg_strong}Failed to activate Conda environment: xtts${reset}" - log_message "INFO" "Press Enter to try again otherwise close the installer and restart." - read -p "Press Enter to try again..." - install_xtts - fi + # Check if xtts activation was successful + if [ $? -eq 0 ]; then + log_message "INFO" "Conda environment xtts activated successfully." + else + log_message "ERROR" "${red_fg_strong}Failed to activate Conda environment: xtts${reset}" + log_message "INFO" "Press Enter to try again otherwise close the installer and restart." + read -p "Press Enter to try again..." + install_xtts + fi - # Install Python 3.10 in the xtts environment - log_message "INFO" "Installing Python in the Conda environment..." - conda install python=3.10 -y + # Install Python 3.10 in the xtts environment + log_message "INFO" "Installing Python in the Conda environment..." + conda install python=3.10 -y - # Create folders for xtts - log_message "INFO" "Creating xtts folders..." - mkdir "$PWD/xtts" - mkdir "$PWD/xtts/speakers" - mkdir "$PWD/xtts/output" + # Create folders for xtts + log_message "INFO" "Creating xtts folders..." + mkdir "$PWD/xtts" + mkdir "$PWD/xtts/speakers" + mkdir "$PWD/xtts/output" - # Clone the xtts-api-server repository for voice examples - log_message "INFO" "Cloning xtts-api-server repository..." - git clone https://github.com/daswer123/xtts-api-server.git + # Clone the xtts-api-server repository for voice examples + log_message "INFO" "Cloning xtts-api-server repository..." + git clone https://github.com/daswer123/xtts-api-server.git - log_message "INFO" "Adding voice examples to speakers directory..." - cp -r "$PWD/xtts-api-server/example/"* "$PWD/xtts/speakers/" + log_message "INFO" "Adding voice examples to speakers directory..." + cp -r "$PWD/xtts-api-server/example/"* "$PWD/xtts/speakers/" - log_message "INFO" "Removing the xtts-api-server directory..." - rm -rf "$PWD/xtts-api-server" + log_message "INFO" "Removing the xtts-api-server directory..." + rm -rf "$PWD/xtts-api-server" - # Install pip3 requirements - log_message "INFO" "Installing pip3 requirements for xtts..." - pip3 install xtts-api-server - pip3 install pydub - pip3 install stream2sentence + # Install pip3 requirements + log_message "INFO" "Installing pip3 requirements for xtts..." + pip3 install xtts-api-server + pip3 install pydub + pip3 install stream2sentence - # Use the GPU choice made earlier to set the correct PyTorch index-url - if [ "$GPU_CHOICE" == "1" ]; then - log_message "INFO" "Installing NVIDIA version of PyTorch" - pip3 install torch==2.1.1+cu118 torchvision torchaudio==2.1.1+cu118 --index-url https://download.pytorch.org/whl/cu118 - install_st_extras_post - elif [ "$GPU_CHOICE" == "2" ]; then - log_message "INFO" "Installing AMD version of PyTorch" - pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.6 - install_st_extras_post - elif [ "$GPU_CHOICE" == "3" ]; then - log_message "INFO" "Installing CPU-only version of PyTorch" - pip3 install torch torchvision torchaudio - install_st_extras_post - fi + # Use the GPU choice made earlier to set the correct PyTorch index-url + if [ "$GPU_CHOICE" == "1" ]; then + log_message "INFO" "Installing NVIDIA version of PyTorch" + pip3 install torch==2.1.1+cu118 torchvision torchaudio==2.1.1+cu118 --index-url https://download.pytorch.org/whl/cu118 + install_st_extras_post + elif [ "$GPU_CHOICE" == "2" ]; then + log_message "INFO" "Installing AMD version of PyTorch" + pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.6 + install_st_extras_post + elif [ "$GPU_CHOICE" == "3" ]; then + log_message "INFO" "Installing CPU-only version of PyTorch" + pip3 install torch torchvision torchaudio + install_st_extras_post + fi } install_st_extras_post() { @@ -609,6 +612,7 @@ install_extras() { echo -e "1. NVIDIA" echo -e "2. AMD" echo -e "3. None (CPU-only mode)" + echo -e "0. Cancel install" # Get GPU information gpu_info="" @@ -641,6 +645,8 @@ install_extras() { elif [ "$gpu_choice" == "3" ]; then log_message "INFO" "Using CPU-only mode" install_extras_pre + elif [ "$gpu_choice" == "0" ]; then + installer else log_message "ERROR" "${red_fg_strong}Invalid number. Please enter a valid number.${reset}" read -p "Press Enter to continue..." @@ -815,7 +821,7 @@ install_extras_post() { installer } -# Function for the installer menu +# Installer Menu - Frontend installer() { echo -e "\033]0;SillyTavern [INSTALLER]\007" clear diff --git a/launcher.sh b/launcher.sh index f544551..93c9adb 100644 --- a/launcher.sh +++ b/launcher.sh @@ -154,7 +154,7 @@ home() { echo "What would you like to do?" echo "1. Start SillyTavern" echo "2. Start Extras" - echo "3. Start SillyTavern + Extras " + echo "3. Start XTTS" echo "4. Update" echo "5. Backup" echo "6. Switch branch" @@ -179,7 +179,7 @@ home() { case $home_choice in 1) start_st ;; 2) start_extras ;; - 3) start_st_extras ;; + 3) start_xtts ;; 4) update ;; 5) backup_menu ;; 6) switch_branch_menu ;; @@ -281,40 +281,38 @@ start_extras() { # Start SillyTavern in the detected terminal if [ "$(uname)" == "Darwin" ]; then log_message "INFO" "Detected macOS. Opening new Terminal window." - open -a Terminal "$(dirname "$0")/SillyTavern-extras/start.sh" + open -a Terminal --args --title="SillyTavern Extras" --working-directory="$(dirname "$0")/SillyTavern-extras" --command "conda activate xtts; python server.py --listen --rvc-save-file --max-content-length=1000 --enable-modules=rvc,caption; exec bash" else - exec "$detected_terminal" -e "cd $(dirname "$0")./SillyTavern-extras && ./start.sh" & + exec "$detected_terminal" -e "cd '$(dirname "$0")/SillyTavern-extras' && conda activate extras && python server.py --listen --rvc-save-file --max-content-length=1000 --enable-modules=rvc,caption; bash" fi fi home -} +} -# Function to start SillyTavern with Extras -start_st_extras() { +# Function to start xtts +start_xtts() { check_nodejs - if [ "$LAUNCH_NEW_WIN" = "0" ]; then - log_message "INFO" "SillyTavern launched" - ./start.sh & - local main_pid=$! - log_message "INFO" "Extras launched under pid $main_pid" - { - #has to be after the first one, so we are 1 directory up - cd "$(dirname "$0")./SillyTavern-extras" || { - log_message "ERROR" "SillyTavern-extras directory not found. Please make sure you have installed SillyTavern-extras." - kill $main_pid - exit 1 - } - log_message "INFO" "Wordking dir: $(pwd)" - ./start.sh - } & - local extras_pid=$! - log_message "INFO" "Extras launched under pid $extras_pid" - wait $main_pid - kill $extras_pid + if [ "$LAUNCH_NEW_WIN" = "0" ]; then + local main_pid=$! + log_message "INFO" "xtts launched under pid $main_pid" + + # Move to xtts directory + cd "$(dirname "$0")/xtts" || { + log_message "ERROR" "xtts directory not found. Please make sure you have installed xtts" + kill "$main_pid" + exit 1 + } + + log_message "INFO" "Working dir: $(pwd)" + ./start.sh & + local xtts_pid=$! + log_message "INFO" "xtts launched under pid $xtts_pid" + + wait "$main_pid" + kill "$xtts_pid" else - log_message "INFO" "SillyTavern launched in a new window." - log_message "INFO" "Extras launched in a new window." + log_message "INFO" "xtts launched in a new window." # Find a suitable terminal local detected_terminal detected_terminal=$(find_terminal) @@ -322,17 +320,14 @@ start_st_extras() { # Enable read p command for troubleshooting # read -p "Press Enter to continue..." - # Start SillyTavern in the detected terminal + # Start XTTS in the detected terminal if [ "$(uname)" == "Darwin" ]; then log_message "INFO" "Detected macOS. Opening new Terminal window." - open -a Terminal "$(dirname "$0")/start.sh" - open -a Terminal "$(dirname "$0")/SillyTavern-extras/start.sh" + open -a Terminal --args --title="XTTSv2 API Server" --working-directory="$(dirname "$0")/xtts" --command "conda activate xtts; python -m xtts_api_server; exec bash" else - exec "$detected_terminal" -e "cd $(dirname "$0")./SillyTavern && ./start.sh" & - exec "$detected_terminal" -e "cd $(dirname "$0")./SillyTavern-extras && ./start.sh" & + exec "$detected_terminal" -e "cd '$(dirname "$0")/xtts' && conda activate xtts && python -m xtts_api_server; bash" fi fi - home } @@ -600,6 +595,14 @@ edit_extras_modules() { edit_extras_modules } +# Function to remove node modules folder +remove_node_modules() { + log_message "INFO" "Removing node_modules folder..." + cd "$(dirname "$0")./SillyTavern" + rm -rf node_modules + + toolbox +} # Function to reinstall SillyTavern reinstall_sillytavern() { @@ -617,7 +620,7 @@ reinstall_sillytavern() { read confirmation if [ "$confirmation" = "Y" ] || [ "$confirmation" = "y" ]; then - cd "$PWD/SillyTavern" + cd "$(dirname "$0")./SillyTavern" # Remove non-excluded folders for dir in *; do @@ -681,7 +684,7 @@ reinstall_extras() { read confirmation if [ "$confirmation" = "Y" ] || [ "$confirmation" = "y" ]; then - cd "$PWD/SillyTavern-extras" + cd "$(dirname "$0")./SillyTavern-extras" # Remove non-excluded folders for dir in *; do @@ -783,7 +786,7 @@ uninstall_st_extras() { read confirmation if [ "$confirmation" = "Y" ] || [ "$confirmation" = "y" ]; then - cd "$PWD" + cd "$(dirname "$0")" log_message "INFO" "Removing the SillyTavern + Sillytavern-extras directory..." rm -rf SillyTavern SillyTavern-extras log_message "INFO" "Removing the Conda environment 'extras'..." @@ -809,9 +812,10 @@ toolbox() { echo "3. Install Node.js" echo "4. Edit Environment" echo "5. Edit Extras Modules" - echo "6. Reinstall SillyTavern" - echo "7. Reinstall Extras" - echo "8. Uninstall SillyTavern + Extras" + echo "6. Remove node_modules folder" + echo "7. Reinstall SillyTavern" + echo "8. Reinstall Extras" + echo "9. Uninstall SillyTavern + Extras" echo "0. Back to Home" read -p "Choose Your Destiny: " toolbox_choice @@ -823,9 +827,10 @@ toolbox() { 3) install_nodejs ;; 4) edit_environment ;; 5) edit_extras_modules ;; - 6) reinstall_sillytavern ;; - 7) reinstall_extras ;; - 8) uninstall_st_extras ;; + 6) remove_node_modules ;; + 7) reinstall_sillytavern ;; + 8) reinstall_extras ;; + 9) uninstall_st_extras ;; 0) home ;; *) echo -e "${yellow_fg_strong}WARNING: Invalid number. Please insert a valid number.${reset}" read -p "Press Enter to continue..."