-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
145 lines (131 loc) · 5.03 KB
/
install.ps1
File metadata and controls
145 lines (131 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# PowerShell script for Windows installation
# Find a Python version that supports gradio 3.x (Python 3.8-3.11)
$PYTHON_CMD = $null
$pythonCandidates = @("python3.11", "python3.10", "python3.9", "python3.8", "py -3.11", "py -3.10", "py -3.9", "py -3.8", "python")
foreach ($cmd in $pythonCandidates) {
try {
$cmdParts = $cmd -split ' '
if ($cmdParts.Length -eq 2) {
$version = & $cmdParts[0] $cmdParts[1] -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>$null
} else {
$version = & $cmd -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>$null
}
if ($version) {
$major, $minor = $version -split '\.'
if ([int]$major -eq 3 -and [int]$minor -ge 8 -and [int]$minor -le 11) {
$PYTHON_CMD = $cmd
Write-Host "Found compatible Python: $cmd ($version)"
break
}
}
} catch {
continue
}
}
if (-not $PYTHON_CMD) {
Write-Host "ERROR: No compatible Python found (need 3.8-3.11 for gradio 3.x)"
Write-Host ""
$downloadPython = Read-Host "Would you like to download a portable Python 3.11? (y/n)"
if ($downloadPython -eq "y" -or $downloadPython -eq "Y") {
Write-Host "Downloading portable Python 3.11..."
$pyUrl = "https://github.com/indygreg/python-build-standalone/releases/download/20240224/cpython-3.11.8+20240224-x86_64-pc-windows-msvc-install_only.tar.gz"
Invoke-WebRequest -Uri $pyUrl -OutFile "python.tar.gz"
New-Item -ItemType Directory -Force -Path "portable_python" | Out-Null
tar -xzf python.tar.gz -C portable_python --strip-components=1
Remove-Item "python.tar.gz"
$PYTHON_CMD = "$PWD\portable_python\python.exe"
Write-Host "Portable Python installed: $PYTHON_CMD"
} else {
Write-Host "Please install Python 3.10, 3.11, or 3.12 from https://www.python.org/downloads/"
exit 1
}
}
# Try to detect GPU type
try {
$gpu = Get-CimInstance -ClassName Win32_VideoController | Select-Object -First 1 -ExpandProperty Name
if ($gpu -match "AMD") {
$GPU_TYPE = "AMD"
Write-Host "Detected GPU: AMD"
} elseif ($gpu -match "NVIDIA") {
$GPU_TYPE = "NVIDIA"
Write-Host "Detected GPU: NVIDIA"
} else {
throw "No match"
}
} catch {
Write-Host "Could not auto-detect GPU type."
Write-Host "Select your GPU type:"
Write-Host "1. AMD"
Write-Host "2. NVIDIA"
$choice = Read-Host "Enter choice (1 or 2)"
switch ($choice) {
1 { $GPU_TYPE = "AMD" }
2 { $GPU_TYPE = "NVIDIA" }
default {
Write-Host "Invalid choice. Exiting."
exit 1
}
}
}
# Fetch asset options from GitHub releases
Write-Host "Fetching asset options from GitHub..."
$RELEASE_URL = "https://api.github.com/repos/leejet/stable-diffusion.cpp/releases/latest"
try {
$release = Invoke-RestMethod -Uri $RELEASE_URL
$assets = $release.assets | Select-Object -ExpandProperty name
} catch {
Write-Host "Failed to fetch assets. Please ensure internet connection."
exit 1
}
if ($GPU_TYPE -eq "AMD") {
$ASSET_NAME = $assets | Where-Object { $_ -match "win" -and $_ -match "rocm" } | Select-Object -First 1
} elseif ($GPU_TYPE -eq "NVIDIA") {
$ASSET_NAME = $assets | Where-Object { $_ -match "win" -and $_ -match "cuda" } | Select-Object -First 1
}
if (-not $ASSET_NAME) {
Write-Host "No suitable asset found for $GPU_TYPE."
exit 1
}
$DOWLOAD_URL = "https://github.com/leejet/stable-diffusion.cpp/releases/latest/download/$ASSET_NAME"
if (Test-Path "stable-diffusion-cpp") {
Write-Host "stable-diffusion-cpp already exists, skipping download."
} else {
Write-Host "Downloading $GPU_TYPE release..."
Invoke-WebRequest -Uri $DOWLOAD_URL -OutFile $ASSET_NAME
if ($?) {
Write-Host "Download complete. Unzipping to stable-diffusion-cpp..."
Expand-Archive -Path $ASSET_NAME -DestinationPath "stable-diffusion-cpp"
Write-Host "Done."
Remove-Item $ASSET_NAME
} else {
Write-Host "Download failed."
exit 1
}
}
Write-Host "Creating virtual environment in .venv..."
if (Test-Path ".venv") {
Write-Host "Virtual environment already exists, skipping."
} else {
$cmdParts = $PYTHON_CMD -split ' '
if ($cmdParts.Length -eq 2) {
& $cmdParts[0] $cmdParts[1] -m venv .venv
} else {
& $PYTHON_CMD -m venv .venv
}
}
& ".venv\Scripts\Activate.ps1"
Write-Host "Installing required packages: pillow, gradio, requests..."
pip install pillow gradio==3.41.2 requests
deactivate
Write-Host "Creating model directories..."
New-Item -ItemType Directory -Force -Path checkpoints, vae, lora
@'
if (-not (Test-Path ".venv")) {
Write-Host "ERROR: Virtual environment not found. Run install.ps1 first."
exit 1
}
& ".venv\Scripts\Activate.ps1"
pip install --upgrade pillow gradio==3.41.2 requests
python -m sd_ui.app
'@ | Out-File -FilePath run.ps1 -Encoding UTF8
Write-Host "Setup complete, run with './run.ps1'"