1
1
# This version offers to reuse last prompt
2
2
# this version can evaluate the contents of /home/deck/stable-diffusion.cpp/Checkpoints and prompt the user to select a checkpoint from that dir. logic to differentiate SD vs SDXL to be added
3
3
# This version saves output files as . To change back to Output_#.png, set line 11 to base_filename="output" and 15 to while [[ -e "$output_dir/${base_filename}_${i}.png" ]]; do
4
- # This version will query the user for which LORA , if any, they want to use and the strength of the LORA . The script assumes LORAS are at /home/deck/stable-diffusion.cpp/LORAs /
4
+ # This version will query the user for which LoRA , if any, to use and the strength of the LoRA . The script assumes LoRAs are at /home/deck/stable-diffusion.cpp/loras /
5
5
# This version has the capability to specify a neg prompt and will ask if you want to reuse the previous one
6
6
# This version will verify SD vs SDXL prompt/parameter compliance with the selected model. If noncompliant, will offer to attempt to automatically comply the prompt/parameters with the SDXL model
7
7
#! /bin/bash
8
8
9
- #! /bin/bash
10
-
11
9
# Directory to save images
12
10
output_dir=" output_images"
13
11
mkdir -p " $output_dir "
14
12
13
+ checkpoint_dir=" /home/deck/stable-diffusion.cpp/checkpoints"
14
+ lora_dir=" /home/deck/stable-diffusion.cpp/loras"
15
+
15
16
# Base filename
16
17
base_filename=" output"
17
18
@@ -48,19 +49,21 @@ list_checkpoints() {
48
49
list_loras () {
49
50
local dir=$1
50
51
local files=(" $dir " /* )
52
+ echo " ${files} "
51
53
echo " LoRAs found in $dir :"
52
54
for idx in " ${! files[@]} " ; do
53
55
echo " $(( idx + 1 )) ) ${files[$idx]##*/ } "
54
56
done
55
- read -p " Please input the number corresponding to the LORA to be used in this generation: " choice
57
+ read -p " Please input the number corresponding to the LoRA to be used in this generation: " choice
56
58
if [[ $choice -gt 0 && $choice -le ${# files[@]} ]]; then
57
59
selected_lora=" ${files[$((choice - 1))]##*/ } "
58
60
echo " You've chosen: $choice ) $selected_lora "
59
61
60
- # Prompt the user to indicate the strength of the LORA
61
- read -p " Enter the strength of the LORA (e.g., 1): " lora_strength
62
+ # Prompt the user to indicate the strength of the LoRA
63
+ read -p " Enter the strength of the LoRA (default 1): " lora_strength
64
+ lora_strength=${lora_strength:- 1}
62
65
63
- # Amend the user's prompt to include the selected LORA and its strength
66
+ # Amend the user's prompt to include the selected LoRA and its strength
64
67
prompt=" $prompt <lora:${selected_lora% .safetensors} :$lora_strength >"
65
68
else
66
69
echo " Invalid choice. Exiting."
@@ -69,21 +72,14 @@ list_loras() {
69
72
}
70
73
71
74
# List checkpoints and prompt the user to choose one
72
- checkpoint_dir=" /home/deck/stable-diffusion.cpp/Checkpoints"
73
75
list_checkpoints " $checkpoint_dir "
74
76
75
- # Change directory to Checkpoints to look for the model
76
- cd /home/deck/stable-diffusion.cpp/Checkpoints
77
-
78
77
# Check if the selected checkpoint exists in the Checkpoints directory
79
- if [[ ! -f " $selected_checkpoint " ]]; then
80
- echo " Model $selected_checkpoint not found in /home/deck/stable-diffusion.cpp/Checkpoints "
78
+ if [[ ! -f " $checkpoint_dir / $ selected_checkpoint" ]]; then
79
+ echo " Model $selected_checkpoint not found in $checkpoint_dir "
81
80
exit 1
82
81
fi
83
82
84
- # Return to the base working directory
85
- cd /home/deck/stable-diffusion.cpp/
86
-
87
83
# Prompt the user for a new prompt or reuse the previous one
88
84
if [[ -f " last_prompt.txt" ]]; then
89
85
echo " Do you want to reuse the previous prompt? (y/n)"
@@ -116,13 +112,12 @@ else
116
112
echo " $negative_prompt " > last_negative_prompt.txt
117
113
fi
118
114
119
- # Prompt the user if they want to use a LORA for generating this image
120
- echo " Would you like to use a LORA for generating this image? (y/n)"
115
+ # Prompt the user whether to use a LoRA for generating this image
116
+ echo " Would you like to use a LoRA for generating this image? (y/n)"
121
117
read use_lora
122
118
123
119
if [[ " $use_lora " == " y" ]]; then
124
120
# List LoRAs and prompt the user to choose one
125
- lora_dir=" /home/deck/stable-diffusion.cpp/LORAs"
126
121
list_loras " $lora_dir "
127
122
fi
128
123
@@ -163,16 +158,68 @@ case $resolution_choice in
163
158
;;
164
159
esac
165
160
161
+ read -p " Enter the CFG scale (default is 1): " cfg_scale
162
+ cfg_scale=${cfg_scale:- 1}
163
+
164
+ echo " Choose a sampling method:"
165
+ echo " 1) euler"
166
+ echo " 2) euler_a"
167
+ echo " 3) heun"
168
+ echo " 4) dpm2"
169
+ echo " 5) dpm++2s_a"
170
+ echo " 6) dpm++2m"
171
+ echo " 7) dpm++2mv2"
172
+ echo " 8) ipndm"
173
+ echo " 9) ipndm_v"
174
+ echo " 10) lcm"
175
+ read -p " Enter the number corresponding to your choice (default is lcm): " sampling_method_choice
176
+
177
+ case $sampling_method_choice in
178
+ 1)
179
+ sampling_method=euler
180
+ ;;
181
+ 2)
182
+ sampling_method=euler_a
183
+ ;;
184
+ 3)
185
+ sampling_method=heun
186
+ ;;
187
+ 4)
188
+ sampling_method=dpm2
189
+ ;;
190
+ 5)
191
+ sampling_method=dpm++2s_a
192
+ ;;
193
+ 6)
194
+ sampling_method=dpm++2m
195
+ ;;
196
+ 7)
197
+ sampling_method=dpm++2mv2
198
+ ;;
199
+ 8)
200
+ sampling_method=ipndm
201
+ ;;
202
+ 9)
203
+ sampling_method=ipndm_v
204
+ ;;
205
+ 10)
206
+ sampling_method=lcm
207
+ ;;
208
+ * )
209
+ sampling_method=lcm
210
+ ;;
211
+ esac
212
+
166
213
# Prompt the user to specify the number of steps (default to 8)
167
214
read -p " Enter the number of steps (default is 8): " steps
168
215
steps=${steps:- 8}
169
216
170
217
# Prompt the user to enter the number of pictures to generate
171
218
read -p " Enter the number of pictures to generate: " num_pictures
172
219
173
- # Check if model is SDXL and warn user if true, ask if they want automatic adjustment for SDXL compliance
174
- if [[ " $selected_checkpoint " == * " SDXL " * ]]; then
175
- echo " WARNING: The model being used is SDXL."
220
+ # Check if model is SDXL and warn user if true, ask if automatic adjustment for SDXL compliance wanted
221
+ if [[ " $( stat -L -c %s " $checkpoint_dir / $selected_checkpoint " ) " > 2500000000 ]]; then
222
+ echo " WARNING: You seem to be using an SDXL model ."
176
223
read -p " Would you like your prompt automatically adjusted for SDXL compliance? (y/n): " adjust_sdxl
177
224
if [[ " $adjust_sdxl " == " y" ]]; then
178
225
sdxl_compliance=" --vae-on-cpu"
@@ -194,7 +241,7 @@ for ((j=1; j<=num_pictures; j++)); do
194
241
output_filename=" ${safe_prompt} -${safe_checkpoint} _${i} .png"
195
242
196
243
# Run the stable-diffusion command with the new filename and random seed, using the selected checkpoint from Checkpoints directory
197
- ./sd -m " /home/deck/stable-diffusion.cpp/Checkpoints/ $selected_checkpoint " -H " $height " -W " $width " --vae-on-cpu -- sampling-method lcm --steps " $steps " --cfg-scale 1 --seed " $seed " --prompt " $prompt " --negative-prompt " $negative_prompt " $sdxl_compliance -o " $output_dir /$output_filename "
244
+ ./sd -m " $checkpoint_dir / $selected_checkpoint " -H " $height " -W " $width " -- sampling-method lcm --steps " $steps " --cfg-scale " $cfg_scale " --seed " $seed " --prompt " $prompt " --negative-prompt " $negative_prompt " $sdxl_compliance -o " $output_dir /$output_filename " | tee output.log
198
245
199
246
# Check for memory allocation error
200
247
if grep -q " ErrorOutOfDeviceMemory" <<< " $(tail -n 10 output.log)" ; then
210
257
211
258
# create dir with
212
259
# cd /home/deck/stable-diffusion.cpp/
213
- # chmod +x imgen .sh
260
+ # chmod +x imagen .sh
214
261
215
262
# run this script to generate multiple images in 1 command
216
- # ./imgen
263
+ # ./imagen.sh
0 commit comments