nathanglm commited on
Commit
87a4cd1
·
verified ·
1 Parent(s): 9b38937

Upload synthid.sh

Browse files
Files changed (1) hide show
  1. synthid.sh +343 -0
synthid.sh ADDED
@@ -0,0 +1,343 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ source /venv/main/bin/activate
4
+ COMFYUI_DIR=${WORKSPACE}/ComfyUI
5
+
6
+ # Packages are installed after nodes so we can fix them...
7
+
8
+ APT_PACKAGES=(
9
+ )
10
+
11
+ PIP_PACKAGES=(
12
+ )
13
+
14
+ NODES=(
15
+ "https://github.com/ltdrdata/ComfyUI-Manager"
16
+ "https://github.com/city96/ComfyUI-GGUF"
17
+ "https://github.com/ltdrdata/ComfyUI-Impact-Pack"
18
+ "https://github.com/rgthree/rgthree-comfy"
19
+ "https://github.com/Fannovel16/comfyui_controlnet_aux"
20
+ "https://github.com/kijai/ComfyUI-KJNodes"
21
+ "https://github.com/lquesada/ComfyUI-Inpaint-CropAndStitch"
22
+ "https://github.com/ClownsharkBatwing/RES4LYF"
23
+ "https://github.com/wildminder/ComfyUI-DyPE"
24
+ "https://github.com/BadCafeCode/masquerade-nodes-comfyui"
25
+ "https://github.com/numz/ComfyUI-SeedVR2_VideoUpscaler"
26
+ )
27
+
28
+ WORKFLOWS=(
29
+ )
30
+
31
+ SAMS=(
32
+ "https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth"
33
+ )
34
+
35
+
36
+ CHECKPOINT_MODELS=(
37
+ )
38
+
39
+ BBOX=(
40
+ "https://huggingface.co/deepghs/yolo-face/resolve/739664f2d00e436a8882238f83175ab0f6497578/yolov8n-face/model.pt"
41
+ )
42
+
43
+ UNET_MODELS=(
44
+ )
45
+
46
+ # Format: "URL|filename.safetensors"
47
+ LORA_MODELS=(
48
+ "https://huggingface.co/lightx2v/Qwen-Image-2512-Lightning/resolve/main/Qwen-Image-2512-Lightning-4steps-V1.0-fp32.safetensors"
49
+ )
50
+
51
+ VAE_MODELS=(
52
+ "https://huggingface.co/Comfy-Org/z_image_turbo/resolve/main/split_files/vae/ae.safetensors"
53
+ "https://huggingface.co/Comfy-Org/Qwen-Image_ComfyUI/resolve/main/split_files/vae/qwen_image_vae.safetensors"
54
+ )
55
+
56
+ DIFFUSION_MODELS=(
57
+ "https://huggingface.co/Comfy-Org/z_image_turbo/resolve/main/split_files/diffusion_models/z_image_turbo_bf16.safetensors"
58
+ "https://huggingface.co/unsloth/Qwen-Image-2512-GGUF/resolve/main/qwen-image-2512-Q4_K_M.gguf"
59
+ )
60
+
61
+ TEXT_ENCODERS=(
62
+ "https://huggingface.co/Comfy-Org/z_image_turbo/resolve/main/split_files/text_encoders/qwen_3_4b.safetensors"
63
+ )
64
+
65
+ ESRGAN_MODELS=(
66
+ )
67
+
68
+ CONTROLNET_MODELS=(
69
+ )
70
+
71
+ BBOX=(
72
+ "https://huggingface.co/Bingsu/adetailer/resolve/main/face_yolov8n.pt"
73
+ )
74
+
75
+ CLIP=(
76
+ "https://huggingface.co/unsloth/Qwen2.5-VL-7B-Instruct-GGUF/resolve/main/Qwen2.5-VL-7B-Instruct-Q4_K_M.gguf"
77
+ "https://huggingface.co/worstplayer/Z-Image_Qwen_3_4b_text_encoder_GGUF/resolve/main/Qwen_3_4b-imatrix-IQ4_XS.gguf"
78
+ )
79
+
80
+ MODEL_PATCHES=(
81
+ "https://huggingface.co/Comfy-Org/Qwen-Image-DiffSynth-ControlNets/resolve/main/split_files/model_patches/qwen_image_canny_diffsynth_controlnet.safetensors"
82
+ )
83
+
84
+ ### DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ###
85
+
86
+ function provisioning_start() {
87
+ provisioning_print_header
88
+ provisioning_get_apt_packages
89
+ provisioning_get_nodes
90
+ provisioning_get_pip_packages
91
+ provisioning_get_files \
92
+ "${COMFYUI_DIR}/models/sams" \
93
+ "${SAMS[@]}"
94
+ provisioning_get_files \
95
+ "${COMFYUI_DIR}/models/checkpoints" \
96
+ "${CHECKPOINT_MODELS[@]}"
97
+ provisioning_get_files \
98
+ "${COMFYUI_DIR}/models/ultralytics/bbox" \
99
+ "${BBOX[@]}"
100
+ provisioning_get_files \
101
+ "${COMFYUI_DIR}/models/unet" \
102
+ "${UNET_MODELS[@]}"
103
+ provisioning_get_files \
104
+ "${COMFYUI_DIR}/models/clip" \
105
+ "${CLIP[@]}"
106
+ provisioning_get_files \
107
+ "${COMFYUI_DIR}/models/diffusion_model_patches" \
108
+ "${MODEL_PATCHES[@]}"
109
+ provisioning_get_files \
110
+ "${COMFYUI_DIR}/models/loras" \
111
+ "${LORA_MODELS[@]}"
112
+ provisioning_get_files \
113
+ "${COMFYUI_DIR}/models/diffusion_models" \
114
+ "${DIFFUSION_MODELS[@]}"
115
+ provisioning_get_files \
116
+ "${COMFYUI_DIR}/models/text_encoders" \
117
+ "${TEXT_ENCODERS[@]}"
118
+ provisioning_get_files \
119
+ "${COMFYUI_DIR}/models/ultralytics/bbox" \
120
+ "${BBOX[@]}"
121
+ provisioning_get_files \
122
+ "${COMFYUI_DIR}/models/controlnet" \
123
+ "${CONTROLNET_MODELS[@]}"
124
+ provisioning_get_files \
125
+ "${COMFYUI_DIR}/models/vae" \
126
+ "${VAE_MODELS[@]}"
127
+ provisioning_get_files \
128
+ "${COMFYUI_DIR}/user/default/workflows" \
129
+ "${WORKFLOWS[@]}"
130
+ provisioning_get_files \
131
+ "${COMFYUI_DIR}/models/esrgan" \
132
+ "${ESRGAN_MODELS[@]}"
133
+ provisioning_print_end
134
+ }
135
+
136
+ function provisioning_get_apt_packages() {
137
+ if [[ -n $APT_PACKAGES ]]; then
138
+ sudo $APT_INSTALL ${APT_PACKAGES[@]}
139
+ fi
140
+ }
141
+
142
+ function provisioning_get_pip_packages() {
143
+ if [[ -n $PIP_PACKAGES ]]; then
144
+ pip install --no-cache-dir ${PIP_PACKAGES[@]}
145
+ fi
146
+ }
147
+
148
+ function provisioning_get_nodes() {
149
+ for repo in "${NODES[@]}"; do
150
+ dir="${repo##*/}"
151
+ path="${COMFYUI_DIR}/custom_nodes/${dir}"
152
+ requirements="${path}/requirements.txt"
153
+ if [[ -d $path ]]; then
154
+ if [[ ${AUTO_UPDATE,,} != "false" ]]; then
155
+ printf "Updating node: %s...\n" "${repo}"
156
+ ( cd "$path" && git pull )
157
+ if [[ -e $requirements ]]; then
158
+ pip install --no-cache-dir -r "$requirements"
159
+ fi
160
+ fi
161
+ else
162
+ printf "Downloading node: %s...\n" "${repo}"
163
+ git clone "${repo}" "${path}" --recursive
164
+ if [[ -e $requirements ]]; then
165
+ pip install --no-cache-dir -r "${requirements}"
166
+ fi
167
+ fi
168
+ done
169
+ }
170
+
171
+ function provisioning_get_files() {
172
+ if [[ -z $2 ]]; then return 1; fi
173
+
174
+ dir="$1"
175
+ mkdir -p "$dir"
176
+ shift
177
+ arr=("$@")
178
+ printf "Downloading %s model(s) to %s...\n" "${#arr[@]}" "$dir"
179
+ for entry in "${arr[@]}"; do
180
+ # Support "URL|filename" format for custom filenames
181
+ if [[ "$entry" == *"|"* ]]; then
182
+ url="${entry%%|*}"
183
+ filename="${entry##*|}"
184
+ else
185
+ url="$entry"
186
+ filename=""
187
+ fi
188
+ printf "Downloading: %s\n" "${url}"
189
+ provisioning_download "${url}" "${dir}" "${filename}"
190
+ printf "\n"
191
+ done
192
+ }
193
+
194
+ function provisioning_print_header() {
195
+ printf "\n##############################################\n# #\n# Provisioning container #\n# #\n# This will take some time #\n# #\n# Your container will be ready on completion #\n# #\n##############################################\n\n"
196
+ }
197
+
198
+ function provisioning_print_end() {
199
+ printf "\nProvisioning complete: Application will start now\n\n"
200
+ }
201
+
202
+ function provisioning_has_valid_hf_token() {
203
+ [[ -n "$HF_TOKEN" ]] || return 1
204
+ url="https://huggingface.co/api/whoami-v2"
205
+
206
+ response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
207
+ -H "Authorization: Bearer $HF_TOKEN" \
208
+ -H "Content-Type: application/json")
209
+
210
+ if [ "$response" -eq 200 ]; then
211
+ return 0
212
+ else
213
+ return 1
214
+ fi
215
+ }
216
+
217
+ function provisioning_has_valid_civitai_token() {
218
+ [[ -n "$CIVITAI_TOKEN" ]] || return 1
219
+ url="https://civitai.com/api/v1/models?hidden=1&limit=1"
220
+
221
+ response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
222
+ -H "Authorization: Bearer $CIVITAI_TOKEN" \
223
+ -H "Content-Type: application/json")
224
+
225
+ if [ "$response" -eq 200 ]; then
226
+ return 0
227
+ else
228
+ return 1
229
+ fi
230
+ }
231
+
232
+ # Download CivitAI models with curl (pure bash)
233
+ function download_civitai_bash() {
234
+ local url="$1"
235
+ local output_dir="$2"
236
+ local forced_filename="$3"
237
+ local model_id=""
238
+
239
+ if [[ $url =~ /models/([0-9]+) ]]; then
240
+ model_id="${BASH_REMATCH[1]}"
241
+ else
242
+ printf "ERROR: Could not extract model ID from URL\n"
243
+ return 1
244
+ fi
245
+
246
+ printf "Downloading CivitAI model %s...\n" "$model_id"
247
+
248
+ if [[ -n "$forced_filename" ]]; then
249
+ local output_file="${output_dir}/${forced_filename}"
250
+ if [[ -f "$output_file" ]]; then
251
+ printf "File already exists: %s\n" "$forced_filename"
252
+ return 0
253
+ fi
254
+ printf "Downloading to: %s\n" "$forced_filename"
255
+ if [[ -n "$CIVITAI_TOKEN" ]]; then
256
+ curl -L -o "$output_file" --progress-bar -H "Authorization: Bearer $CIVITAI_TOKEN" "$url"
257
+ else
258
+ curl -L -o "$output_file" --progress-bar "$url"
259
+ fi
260
+ if [[ $? -eq 0 ]]; then
261
+ printf "Download completed: %s\n" "$forced_filename"
262
+ return 0
263
+ else
264
+ printf "ERROR: Download failed for model %s\n" "$model_id"
265
+ return 1
266
+ fi
267
+ fi
268
+
269
+ local redirect_url=""
270
+ if [[ -n "$CIVITAI_TOKEN" ]]; then
271
+ redirect_url=$(curl -s -I -L -H "Authorization: Bearer $CIVITAI_TOKEN" "$url" | grep -i "^location:" | tail -1 | sed 's/location: //i' | tr -d '\r\n')
272
+ else
273
+ redirect_url=$(curl -s -I -L "$url" | grep -i "^location:" | tail -1 | sed 's/location: //i' | tr -d '\r\n')
274
+ fi
275
+
276
+ if [[ -z "$redirect_url" ]]; then
277
+ printf "ERROR: Could not get redirect URL for model %s\n" "$model_id"
278
+ return 1
279
+ fi
280
+
281
+ local filename=""
282
+
283
+ if [[ $redirect_url =~ response-content-disposition=attachment.*filename%3D%22([^%\"]+) ]]; then
284
+ filename="${BASH_REMATCH[1]}"
285
+ filename=$(echo "$filename" | sed 's/%20/ /g; s/%2D/-/g; s/%2E/./g; s/%5F/_/g')
286
+ elif [[ $redirect_url =~ filename=\"([^\"]+)\" ]]; then
287
+ filename="${BASH_REMATCH[1]}"
288
+ elif [[ $redirect_url =~ filename=([^&]+) ]]; then
289
+ filename="${BASH_REMATCH[1]}"
290
+ else
291
+ local path_part=$(echo "$redirect_url" | sed 's/?.*//')
292
+ filename=$(basename "$path_part")
293
+ if [[ ! "$filename" =~ \.(safetensors|pt|pth|ckpt|bin)$ ]]; then
294
+ filename="${filename}.safetensors"
295
+ fi
296
+ fi
297
+
298
+ filename=$(printf '%b' "${filename//%/\\x}")
299
+
300
+ if [[ -z "$filename" ]] || [[ "$filename" == "." ]] || [[ "$filename" == ".safetensors" ]]; then
301
+ filename="civitai_${model_id}.safetensors"
302
+ fi
303
+
304
+ local output_file="${output_dir}/${filename}"
305
+
306
+ if [[ -f "$output_file" ]]; then
307
+ printf "File already exists: %s\n" "$filename"
308
+ return 0
309
+ fi
310
+
311
+ printf "Downloading to: %s\n" "$filename"
312
+ curl -L -o "$output_file" --progress-bar "$redirect_url"
313
+
314
+ if [[ $? -eq 0 ]]; then
315
+ printf "Download completed: %s\n" "$filename"
316
+ return 0
317
+ else
318
+ printf "ERROR: Download failed for model %s\n" "$model_id"
319
+ return 1
320
+ fi
321
+ }
322
+
323
+ # Download from $1 URL to $2 file path, with optional $3 forced filename
324
+ function provisioning_download() {
325
+ local url="$1"
326
+ local dir="$2"
327
+ local forced_filename="$3"
328
+
329
+ if [[ $url =~ ^https://civitai\.com/api/download/models/([0-9]+) ]]; then
330
+ download_civitai_bash "$url" "$dir" "$forced_filename"
331
+ else
332
+ if [[ -n "$forced_filename" ]]; then
333
+ wget -qnc --show-progress -e dotbytes="${4:-4M}" -O "${dir}/${forced_filename}" "$url"
334
+ else
335
+ wget -qnc --content-disposition --show-progress -e dotbytes="${4:-4M}" -P "$dir" "$url"
336
+ fi
337
+ fi
338
+ }
339
+
340
+ # Allow user to disable provisioning if they started with a script they didn't want
341
+ if [[ ! -f /.noprovisioning ]]; then
342
+ provisioning_start
343
+ fi