Add powershell launch scripts.

This commit is contained in:
d8ahazard 2022-12-15 17:07:28 -06:00
parent 685f9631b5
commit cd1fe6a77f
2 changed files with 137 additions and 0 deletions

43
webui-user.ps1 Normal file
View File

@ -0,0 +1,43 @@
$env:PYTHON= ''
$env:GIT= ''
$env:VENV_DIR= ''
# Commandline arguments for webui.py, for example: $env:COMMANDLINE_ARGS="--medvram --opt-split-attention"
$env:COMMANDLINE_ARGS=""
# script to launch to start the app
# $env:LAUNCH_SCRIPT="launch.py"
# install command for torch
# $env:TORCH_COMMAND="pip install torch==1.12.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113"
# Requirements file to use for stable-diffusion-webui
# $env:REQS_FILE="requirements_versions.txt"
# $env:GFPGAN_PACKAGE=""
# $env:CLIP_PACKAGE=""
# $env:OPENCLIP_PACKAGE=""
# URL to a WHL if you wish to override default xformers windows
# $env:XFORMERS_WINDOWS_PACKAGE=""
# Uncomment and set to enable an alternate repository URL
# $env:STABLE_DIFFUSION_REPO=""
# $env:TAMING_TRANSFORMERS_REPO=""
# $env:K_DIFFUSION_REPO=""
# $env:CODEFORMER_REPO=""
# $env:BLIP_REPO=""
# Uncomment and set to enable a specific revision of a repository
# $env:STABLE_DIFFUSION_COMMIT_HASH=""
# $env:TAMING_TRANSFORMERS_COMMIT_HASH=""
# $env:K_DIFFUSION_COMMIT_HASH=""
# $env:CODEFORMER_COMMIT_HASH=""
# $env:BLIP_COMMIT_HASH=""
# Uncomment to enable accelerated launch
# $env:ACCELERATE="True"
$SCRIPT = "$PSScriptRoot\webui.ps1"
Invoke-Expression "$SCRIPT"

94
webui.ps1 Normal file
View File

@ -0,0 +1,94 @@
if ($env:PYTHON -eq "" -or $env:PYTHON -eq $null) {
$PYTHON = "Python.exe"
} else {
$PYTHON = $env:PYTHON
}
if ($env:VENV_DIR -eq "" -or $env:VENV_DIR -eq $null) {
$VENV_DIR = "$PSScriptRoot\venv"
} else {
$VENV_DIR = $env:VENV_DIR
}
if ($env:LAUNCH_SCRIPT -eq "" -or $env:LAUNCH_SCRIPT -eq $null) {
$LAUNCH_SCRIPT = "$PSScriptRoot\launch.py"
} else {
$LAUNCH_SCRIPT = $env:LAUNCH_SCRIPT
}
$ERROR_REPORTING = $false
mkdir tmp 2>$null
function Start-Venv {
if ($VENV_DIR -eq '-') {
Skip-Venv
}
if (Test-Path -Path "$VENV_DIR\Scripts\$python") {
Activate-Venv
} else {
$PYTHON_FULLNAME = & $PYTHON -c "import sys; print(sys.executable)"
Write-Output "Creating venv in directory $VENV_DIR using python $PYTHON_FULLNAME"
Invoke-Expression "$PYTHON_FULLNAME -m venv $VENV_DIR > tmp/stdout.txt 2> tmp/stderr.txt"
if ($LASTEXITCODE -eq 0) {
Activate-Venv
} else {
Write-Output "Unable to create venv in directory $VENV_DIR"
}
}
}
function Activate-Venv {
$PYTHON = "$VENV_DIR\Scripts\Python.exe"
$ACTIVATE = "$VENV_DIR\Scripts\activate.bat"
Invoke-Expression "cmd.exe /c $ACTIVATE"
Write-Output "Venv set to $VENV_DIR."
if ($ACCELERATE -eq 'True') {
Check-Accelerate
} else {
Launch-App
}
}
function Skip-Venv {
Write-Output "Venv set to $VENV_DIR."
if ($ACCELERATE -eq 'True') {
Check-Accelerate
} else {
Launch-App
}
}
function Check-Accelerate {
Write-Output 'Checking for accelerate'
$ACCELERATE = "$VENV_DIR\Scripts\accelerate.exe"
if (Test-Path -Path $ACCELERATE) {
Accelerate-Launch
} else {
Launch-App
}
}
function Launch-App {
Write-Output "Launching with python"
Invoke-Expression "$PYTHON $LAUNCH_SCRIPT"
#pause
exit
}
function Accelerate-Launch {
Write-Output 'Accelerating'
Invoke-Expression "$ACCELERATE launch --num_cpu_threads_per_process=6 $LAUNCH_SCRIPT"
#pause
exit
}
try {
if(Get-Command $PYTHON){
Start-Venv
}
} Catch {
Write-Output "Couldn't launch python."
}