-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·149 lines (138 loc) · 4.85 KB
/
install.sh
File metadata and controls
executable file
·149 lines (138 loc) · 4.85 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
146
147
148
149
#!/bin/bash
# Find a Python version that supports gradio 3.x (Python 3.8-3.11)
PYTHON_CMD=""
for cmd in python3.11 python3.10 python3.9 python3.8 python3; do
if command -v $cmd &> /dev/null; then
version=$($cmd -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
major=$(echo $version | cut -d. -f1)
minor=$(echo $version | cut -d. -f2)
if [ "$major" -eq 3 ] && [ "$minor" -ge 8 ] && [ "$minor" -le 11 ]; then
PYTHON_CMD=$cmd
echo "Found compatible Python: $cmd ($version)"
break
fi
fi
done
if [ -z "$PYTHON_CMD" ]; then
echo "ERROR: No compatible Python found (need >3.8, <3.12 for gradio 3.x)"
echo "Available Python versions:"
for cmd in python3.11 python3.10 python3.9 python3.8 python3 python; do
if command -v $cmd &> /dev/null; then
echo " $cmd: $($cmd --version 2>&1)"
fi
done
echo ""
read -p "Would you like to download a portable Python 3.11? (y/n): " download_python
if [ "$download_python" = "y" ] || [ "$download_python" = "Y" ]; then
echo "Downloading portable Python 3.11..."
ARCH=$(uname -m)
if [ "$ARCH" = "x86_64" ]; then
PY_URL="https://github.com/indygreg/python-build-standalone/releases/download/20240224/cpython-3.11.8+20240224-x86_64-unknown-linux-gnu-install_only.tar.gz"
elif [ "$ARCH" = "aarch64" ]; then
PY_URL="https://github.com/indygreg/python-build-standalone/releases/download/20240224/cpython-3.11.8+20240224-aarch64-unknown-linux-gnu-install_only.tar.gz"
else
echo "Unsupported architecture: $ARCH"
exit 1
fi
curl -L -o python.tar.gz "$PY_URL"
mkdir -p portable_python
tar -xzf python.tar.gz -C portable_python --strip-components=1
rm python.tar.gz
PYTHON_CMD="$(pwd)/portable_python/bin/python3"
echo "Portable Python installed: $PYTHON_CMD"
else
echo "Please install Python >3.8, <3.12"
exit 1
fi
fi
# Try to detect GPU type
GPU_INFO=$(lspci 2>/dev/null | grep -i vga)
if echo "$GPU_INFO" | grep -i nvidia > /dev/null 2>&1; then
GPU_TYPE="NVIDIA"
echo "Detected GPU: NVIDIA"
else
GPU_TYPE="VULKAN"
echo "Detected GPU: Will use Vulkan (compatible with AMD, Intel, and most other GPUs)"
fi
# Allow manual override
echo "Is this correct? (y/n)"
read -p "Press Enter for yes, or type 'n' to choose manually: " confirm
if [ "$confirm" = "n" ]; then
echo "Select your GPU type:"
echo "1. Vulkan (AMD, Intel, or other)"
echo "2. NVIDIA CUDA"
read -p "Enter choice (1 or 2): " choice
case $choice in
1)
GPU_TYPE="VULKAN"
;;
2)
GPU_TYPE="NVIDIA"
;;
*)
echo "Invalid choice. Exiting."
exit 1
;;
esac
fi
# Fetch asset options from GitHub releases
echo "Fetching asset options from GitHub..."
RELEASE_URL="https://api.github.com/repos/JackBinary/stable-diffusion.cpp/releases/latest"
ASSETS=$(curl -s $RELEASE_URL | jq -r '.assets[].name' 2>/dev/null)
if [ $? -ne 0 ]; then
echo "Failed to fetch assets. Please ensure curl and jq are installed."
exit 1
fi
if [ "$GPU_TYPE" = "VULKAN" ]; then
ASSET_NAME=$(echo "$ASSETS" | grep -i linux | grep -i vulkan | head -1)
if [ -z "$ASSET_NAME" ]; then
echo "No suitable Linux Vulkan asset found."
exit 1
fi
elif [ "$GPU_TYPE" = "NVIDIA" ]; then
ASSET_NAME=$(echo "$ASSETS" | grep -i linux | grep -i cuda | head -1)
if [ -z "$ASSET_NAME" ]; then
echo "No suitable Linux CUDA asset found."
exit 1
fi
fi
if [ -d "stable-diffusion-cpp" ]; then
echo "stable-diffusion-cpp already exists, skipping download."
else
echo "Downloading $GPU_TYPE release..."
DOWNLOAD_URL="https://github.com/JackBinary/stable-diffusion.cpp/releases/latest/download/$ASSET_NAME"
curl -L -o $ASSET_NAME $DOWNLOAD_URL
if [ $? -eq 0 ]; then
echo "Download complete. Unzipping to stable-diffusion-cpp..."
unzip $ASSET_NAME -d stable-diffusion-cpp
echo "Done."
rm $ASSET_NAME
else
echo "Download failed."
exit 1
fi
fi
echo "Creating virtual environment in .venv..."
if [ -d ".venv" ]; then
echo "Virtual environment already exists, skipping."
else
$PYTHON_CMD -m venv .venv
fi
source .venv/bin/activate
echo "Installing required packages: pillow, gradio, requests..."
pip install pillow gradio==3.41.2 requests
deactivate
echo "Creating model directories..."
mkdir -p checkpoints vae lora
cat > run.sh << 'EOF'
#!/bin/bash
if [ ! -d ".venv" ]; then
echo "ERROR: Virtual environment not found. Run install.sh first."
exit 1
fi
source .venv/bin/activate
pip install --upgrade pillow gradio==3.41.2 requests
python -m sd_ui.app
EOF
chmod +x run.sh
echo "Setup complete, run with './run.sh'"