forked from JoshuaKimsey/Linux-StableDiffusion-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinux-sd.sh
More file actions
151 lines (137 loc) · 7.76 KB
/
linux-sd.sh
File metadata and controls
151 lines (137 loc) · 7.76 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
150
151
#!/bin/bash -i
# Linux Stable Diffusion Script
# Version: 2.0
# MIT License
# Copyright (c) 2022 Joshua Kimsey
##### Please See My Guide For Running This Script Here: https://rentry.org/linux-sd #####
# Confirmed working as of September 22nd, 2022. May be subject to breakage at a later date due to bleeding-edge updates in the Stable Diffusion WebUI repo
# Please see my GitHub for updates on this script: https://github.com/JoshuaKimsey/Linux-StableDiffusion-Script
printf "\n\n\n"
printf "WELCOME TO THE ULTIMATE STABLE DIFFUSION WEB GUI ON LINUX"
printf "\n\n"
printf "The definitive Stable Diffusion experience™ Now 100% Linux Compatible!"
printf "\n"
printf "Please ensure you have Anaconda installed properly on your Linux system before running this."
printf "\n"
printf "Please refer to the original guide for more info and additional links for this project: https://rentry.org/guitard"
printf "\n\n"
DIRECTORY=./stable-diffusion-webui
REPO=https://github.com/sd-webui/stable-diffusion-webui.git
ENV=ldm
ultimate_stable_diffusion_repo () {
# Check to see if Ultimate Stable Diffusion repo is cloned
if [ -d "$DIRECTORY" ]; then
printf "\n\n########## CHECK FOR UPDATES ##########\n\n"
printf "Ultimate Stable Diffusion already exists. Do you want to update Ultimate Stable Diffusion?\n"
printf "(This will reset your launch arguments and they will need to be set again after updating)\n"
select yn in "Yes" "No"; do
case $yn in
Yes ) printf "Pulling updates for the Stable Diffusion WebUI. Please wait...\n"; ultimate_stable_diffusion_repo_update; break;;
No ) printf "Stable Diffusion WebUI will not be updated. Continuing...\n"; break;;
esac
done
else
printf "Cloning Ultimate Stable Diffusion. Please wait..."
git clone $REPO
cp $DIRECTORY/scripts/relauncher.py $DIRECTORY/scripts/relauncher-backup.py
fi
}
ultimate_stable_diffusion_repo_update () {
cd $DIRECTORY
git fetch --all
git reset --hard origin/master
cp ./scripts/relauncher.py ./scripts/relauncher-backup.py
cd ..;
}
linux_setup_script () {
cd $DIRECTORY
printf "Running webui.sh...\n\n"
bash -i ./webui.sh
}
# Checks to see which mode Ultimate Stable Diffusion is running in: STANDARD or OPTIMIZED
# Then asks the user which mode they wish to use
gradio_stable_diffusion_arguments () {
if [ "$1" = "customize" ]; then
printf "Do you want extra upscaling models to be run on the CPU instead of the GPU to save on VRAM at the cost of speed?\n"
select yn in "Yes" "No"; do
case $yn in
Yes ) printf "Setting extra upscaling models to use the CPU...\n"; sed -i 's/extra_models_cpu = False/extra_models_cpu = True/g' $DIRECTORY/scripts/relauncher.py; break;;
No ) printf "Extra upscaling models will run on the GPU. Continuing...\n"; sed -i 's/extra_models_cpu = True/extra_models_cpu = False/g' $DIRECTORY/scripts/relauncher.py; break;;
esac
done
printf "\n\n"
printf "Do you want for Ultimate Stable Diffusion to automatically launch a new browser window or tab on first launch?\n"
select yn in "Yes" "No"; do
case $yn in
Yes ) printf "Setting Ultimate Stable Diffusion to open a new browser window/tab at first launch...\n"; sed -i 's/open_in_browser = False/open_in_browser = True/g' $DIRECTORY/scripts/relauncher.py; break;;
No ) printf "Ultimate Stable Diffusion will not open automatically in a new browser window/tab. Continuing...\n"; sed -i 's/open_in_browser = True/open_in_browser = False/g' $DIRECTORY/scripts/relauncher.py; break;;
esac
done
printf "\n\n"
printf "Do you want to run Ultimate Stable Diffusion in Optimized mode - Requires only 4GB of VRAM, but is significantly slower?\n"
select yn in "Yes" "No"; do
case $yn in
Yes ) printf "Setting Ultimate Stable Diffusion to run in Optimized Mode...\n"; sed -i 's/optimized = False/optimized = True/g' $DIRECTORY/scripts/relauncher.py; break;;
No ) printf "Ultimate Stable Diffusion will launch in Standard Mode. Continuing...\n"; sed -i 's/optimized = True/optimized = False/g' $DIRECTORY/scripts/relauncher.py; break;;
esac
done
printf "\n\n"
printf "Do you want to start Ultimate Stable Diffusion in Optimized Turbo mode - Requires more VRAM than regular optimized, but is faster (incompatible with Optimized Mode)?\n"
select yn in "Yes" "No"; do
case $yn in
Yes ) printf "Setting Ultimate Stable Diffusion to run in Optimized Turbo mode...\n"; sed -i 's/optimized_turbo = False/optimized_turbo = True/g' $DIRECTORY/scripts/relauncher.py; break;;
No ) printf "Ultimate Stable Diffusion will launch in Standard Mode. Continuing...\n"; sed -i 's/optimized_turbo = True/optimized_turbo = False/g' $DIRECTORY/scripts/relauncher.py; break;;
esac
done
printf "\n\n"
printf "Do you want to create a public xxxxx.gradi.app URL to allow others to uses your interface? (Requires properly forwarded ports)\n"
select yn in "Yes" "No"; do
case $yn in
Yes ) printf "Setting Ultimate Stable Diffusion to open a public share URL...\n"; sed -i 's/share = False/share = True/g' $DIRECTORY/scripts/relauncher.py; break;;
No ) printf "Setting Ultimate Stable Diffusion to not open a public share URL. Continuing...\n"; sed -i 's/share = True/share = False/g' $DIRECTORY/scripts/relauncher.py; break;;
esac
done
printf "\n\nCustomization of Ultimate Stable Diffusion is complete. Continuing...\n\n"
else
printf "\n\n########## GRADIO CUSTOMIZATION ##########\nPlease Note: These Arguments Only Affect The Gradio Interface Version Of The Stable Diffusion Webui.\n\n"
printf "Do you wish to customize the launch arguments for the Gradio Webui Interface?\n"
printf "(This will be where you select Optimized mode, auto open in browser, share to public, and more.)\n"
select yn in "Yes" "No"; do
case $yn in
Yes ) printf "Starting customization of Gradio Interface launch arguments...\n"; gradio_stable_diffusion_arguments customize; break;;
No ) printf "Maintaining current Gradio Interface launch arguments...\n"; break;;
esac
done
fi
}
# Function to install and run the Ultimate Stable Diffusion fork
ultimate_stable_diffusion () {
if [ "$1" = "initial" ]; then
ultimate_stable_diffusion_repo
gradio_stable_diffusion_arguments
linux_setup_script
else
if [[ $(conda env list | grep "$ENV") = $ENV* ]]; then
printf "\n\n########## RUN PREVIOUS SETUP ##########\n\n"
printf "Do you wish to run Ultimate Stable Diffusion with the previous parameters?\n"
printf "(Select NO to customize or update your Ultimate Stable Diffusion setup)\n"
select yn in "Yes" "No"; do
case $yn in
Yes ) printf "Starting Ultimate Stable Diffusion using previous parameters. Please wait..."; linux_setup_script; break;;
No ) printf "Beginning customization of Ultimate Stable Diffusion..."; ultimate_stable_diffusion initial; break;;
esac
done
else
printf "ERROR: Conda Env not found. Will attempt to rebuild, please go through the update steps below...\n"
ultimate_stable_diffusion initial
fi
fi
}
# Initialization
if [ ! -d "$DIRECTORY" ]; then
printf "Starting Ultimate Stable Diffusion installation..."
printf "\n"
ultimate_stable_diffusion initial
else
ultimate_stable_diffusion
fi