Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- installer/installer.py +87 -0
- installer/windows_run.bat +99 -0
installer/installer.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import glob
|
| 3 |
+
import os
|
| 4 |
+
import shutil
|
| 5 |
+
import site
|
| 6 |
+
import subprocess
|
| 7 |
+
import sys
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
script_dir = os.getcwd()
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def run_cmd(cmd, capture_output=False, env=None):
|
| 14 |
+
# Run shell commands
|
| 15 |
+
return subprocess.run(cmd, shell=True, capture_output=capture_output, env=env)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def check_env():
|
| 19 |
+
# If we have access to conda, we are probably in an environment
|
| 20 |
+
conda_not_exist = run_cmd("conda", capture_output=True).returncode
|
| 21 |
+
if conda_not_exist:
|
| 22 |
+
print("Conda is not installed. Exiting...")
|
| 23 |
+
sys.exit()
|
| 24 |
+
|
| 25 |
+
# Ensure this is a new environment and not the base environment
|
| 26 |
+
if os.environ["CONDA_DEFAULT_ENV"] == "base":
|
| 27 |
+
print("Create an environment for this project and activate it. Exiting...")
|
| 28 |
+
sys.exit()
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def install_dependencies():
|
| 32 |
+
global MY_PATH
|
| 33 |
+
|
| 34 |
+
# Install Git and clone repo
|
| 35 |
+
run_cmd("conda install -y -k git")
|
| 36 |
+
run_cmd("git clone https://github.com/C0untFloyd/roop-unleashed.git")
|
| 37 |
+
os.chdir(MY_PATH)
|
| 38 |
+
run_cmd("git checkout 02195623349ee5b56b6d3653b7f97444d7d777f7")
|
| 39 |
+
# Installs dependencies from requirements.txt
|
| 40 |
+
run_cmd("python -m pip install -r requirements.txt")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def update_dependencies():
|
| 45 |
+
global MY_PATH
|
| 46 |
+
|
| 47 |
+
os.chdir(MY_PATH)
|
| 48 |
+
# do a hard reset for to update even if there are local changes
|
| 49 |
+
run_cmd("git fetch --all")
|
| 50 |
+
run_cmd("git reset --hard origin/main")
|
| 51 |
+
run_cmd("git pull")
|
| 52 |
+
# Installs/Updates dependencies from all requirements.txt
|
| 53 |
+
run_cmd("python -m pip install -r requirements.txt")
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def start_app():
|
| 57 |
+
global MY_PATH
|
| 58 |
+
|
| 59 |
+
os.chdir(MY_PATH)
|
| 60 |
+
# forward commandline arguments
|
| 61 |
+
sys.argv.pop(0)
|
| 62 |
+
args = ' '.join(sys.argv)
|
| 63 |
+
print("Launching App")
|
| 64 |
+
run_cmd(f'python run.py {args}')
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
global MY_PATH
|
| 69 |
+
|
| 70 |
+
MY_PATH = "roop-unleashed"
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
# Verifies we are in a conda environment
|
| 74 |
+
check_env()
|
| 75 |
+
|
| 76 |
+
# If webui has already been installed, skip and run
|
| 77 |
+
if not os.path.exists(MY_PATH):
|
| 78 |
+
install_dependencies()
|
| 79 |
+
else:
|
| 80 |
+
# moved update from batch to here, because of batch limitations
|
| 81 |
+
updatechoice = input("Check for Updates? [y/n]").lower()
|
| 82 |
+
if updatechoice == "y":
|
| 83 |
+
update_dependencies()
|
| 84 |
+
|
| 85 |
+
# Run the model with webui
|
| 86 |
+
os.chdir(script_dir)
|
| 87 |
+
start_app()
|
installer/windows_run.bat
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
|
| 3 |
+
REM No CLI arguments supported anymore
|
| 4 |
+
set COMMANDLINE_ARGS=
|
| 5 |
+
|
| 6 |
+
cd /D "%~dp0"
|
| 7 |
+
|
| 8 |
+
echo "%CD%"| findstr /C:" " >nul && echo This script relies on Miniconda which can not be silently installed under a path with spaces. && goto end
|
| 9 |
+
|
| 10 |
+
set PATH=%PATH%;%SystemRoot%\system32
|
| 11 |
+
|
| 12 |
+
@rem config
|
| 13 |
+
set INSTALL_DIR=%cd%\installer_files
|
| 14 |
+
set CONDA_ROOT_PREFIX=%cd%\installer_files\conda
|
| 15 |
+
set INSTALL_ENV_DIR=%cd%\installer_files\env
|
| 16 |
+
set MINICONDA_DOWNLOAD_URL=https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe
|
| 17 |
+
set FFMPEG_DOWNLOAD_URL=https://github.com/GyanD/codexffmpeg/releases/download/2023-06-21-git-1bcb8a7338/ffmpeg-2023-06-21-git-1bcb8a7338-essentials_build.zip
|
| 18 |
+
set INSTALL_FFMPEG_DIR=%cd%\installer_files\ffmpeg
|
| 19 |
+
set INSIGHTFACE_PACKAGE_URL=https://github.com/C0untFloyd/roop-unleashed/releases/download/3.6.6/insightface-0.7.3-cp310-cp310-win_amd64.whl
|
| 20 |
+
set INSIGHTFACE_PACKAGE_PATH=%INSTALL_DIR%\insightface-0.7.3-cp310-cp310-win_amd64.whl
|
| 21 |
+
|
| 22 |
+
set conda_exists=F
|
| 23 |
+
set ffmpeg_exists=F
|
| 24 |
+
|
| 25 |
+
@rem figure out whether git and conda needs to be installed
|
| 26 |
+
call "%CONDA_ROOT_PREFIX%\_conda.exe" --version >nul 2>&1
|
| 27 |
+
if "%ERRORLEVEL%" EQU "0" set conda_exists=T
|
| 28 |
+
|
| 29 |
+
@rem Check if FFmpeg is already in PATH
|
| 30 |
+
where ffmpeg >nul 2>&1
|
| 31 |
+
if "%ERRORLEVEL%" EQU "0" (
|
| 32 |
+
echo FFmpeg is already installed.
|
| 33 |
+
set ffmpeg_exists=T
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
@rem (if necessary) install git and conda into a contained environment
|
| 37 |
+
|
| 38 |
+
@rem download conda
|
| 39 |
+
if "%conda_exists%" == "F" (
|
| 40 |
+
echo Downloading Miniconda from %MINICONDA_DOWNLOAD_URL% to %INSTALL_DIR%\miniconda_installer.exe
|
| 41 |
+
mkdir "%INSTALL_DIR%"
|
| 42 |
+
call curl -Lk "%MINICONDA_DOWNLOAD_URL%" > "%INSTALL_DIR%\miniconda_installer.exe" || ( echo. && echo Miniconda failed to download. && goto end )
|
| 43 |
+
echo Installing Miniconda to %CONDA_ROOT_PREFIX%
|
| 44 |
+
start /wait "" "%INSTALL_DIR%\miniconda_installer.exe" /InstallationType=JustMe /NoShortcuts=1 /AddToPath=0 /RegisterPython=0 /NoRegistry=1 /S /D=%CONDA_ROOT_PREFIX%
|
| 45 |
+
|
| 46 |
+
@rem test the conda binary
|
| 47 |
+
echo Miniconda version:
|
| 48 |
+
call "%CONDA_ROOT_PREFIX%\_conda.exe" --version || ( echo. && echo Miniconda not found. && goto end )
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
@rem create the installer env
|
| 52 |
+
if not exist "%INSTALL_ENV_DIR%" (
|
| 53 |
+
echo Creating Conda Environment
|
| 54 |
+
call "%CONDA_ROOT_PREFIX%\_conda.exe" create --no-shortcuts -y -k --prefix "%INSTALL_ENV_DIR%" python=3.10 || ( echo. && echo Conda environment creation failed. && goto end )
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
@rem Download and install FFmpeg if not already installed
|
| 58 |
+
if "%ffmpeg_exists%" == "F" (
|
| 59 |
+
if not exist "%INSTALL_FFMPEG_DIR%" (
|
| 60 |
+
echo Downloading ffmpeg from %FFMPEG_DOWNLOAD_URL% to %INSTALL_DIR%
|
| 61 |
+
call curl -Lk "%FFMPEG_DOWNLOAD_URL%" > "%INSTALL_DIR%\ffmpeg.zip" || ( echo. && echo ffmpeg failed to download. && goto end )
|
| 62 |
+
call powershell -command "Expand-Archive -Force '%INSTALL_DIR%\ffmpeg.zip' '%INSTALL_DIR%\'"
|
| 63 |
+
cd "installer_files"
|
| 64 |
+
setlocal EnableExtensions EnableDelayedExpansion
|
| 65 |
+
for /f "tokens=*" %%f in ('dir /s /b /ad "ffmpeg\*"') do (
|
| 66 |
+
ren "%%f" "ffmpeg"
|
| 67 |
+
)
|
| 68 |
+
endlocal
|
| 69 |
+
setx PATH "%INSTALL_FFMPEG_DIR%\bin\;%PATH%"
|
| 70 |
+
echo To use videos, you need to restart roop after this installation.
|
| 71 |
+
cd ..
|
| 72 |
+
)
|
| 73 |
+
) else (
|
| 74 |
+
echo Skipping FFmpeg installation as it is already available.
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
@rem Download insightface package
|
| 78 |
+
echo Downloading insightface package from %INSIGHTFACE_PACKAGE_URL% to %INSIGHTFACE_PACKAGE_PATH%
|
| 79 |
+
call curl -Lk "%INSIGHTFACE_PACKAGE_URL%" > "%INSIGHTFACE_PACKAGE_PATH%" || ( echo. && echo Insightface package failed to download. && goto end )
|
| 80 |
+
|
| 81 |
+
@rem check if conda environment was actually created
|
| 82 |
+
if not exist "%INSTALL_ENV_DIR%\python.exe" ( echo. && echo ERROR: Conda environment is empty. && goto end )
|
| 83 |
+
|
| 84 |
+
@rem activate installer env
|
| 85 |
+
call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%" || ( echo. && echo Miniconda hook not found. && goto end )
|
| 86 |
+
|
| 87 |
+
@rem install insightface package using pip
|
| 88 |
+
echo Installing insightface package
|
| 89 |
+
call pip install "%INSIGHTFACE_PACKAGE_PATH%" || ( echo. && echo Insightface package installation failed. && goto end )
|
| 90 |
+
|
| 91 |
+
@rem setup installer env
|
| 92 |
+
echo Launching roop unleashed
|
| 93 |
+
call python installer.py %COMMANDLINE_ARGS%
|
| 94 |
+
|
| 95 |
+
echo.
|
| 96 |
+
echo Done!
|
| 97 |
+
|
| 98 |
+
:end
|
| 99 |
+
pause
|