nathanglm commited on
Commit
995f52c
·
verified ·
1 Parent(s): fbed643

Upload wan.sh

Browse files
Files changed (1) hide show
  1. wan.sh +331 -0
wan.sh ADDED
@@ -0,0 +1,331 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #"package-1"
10
+ #"package-2"
11
+ )
12
+
13
+ PIP_PACKAGES=(
14
+ "google-genai"
15
+ "xai-sdk"
16
+ )
17
+
18
+ NODES=(
19
+ "https://github.com/ltdrdata/ComfyUI-Manager"
20
+ "https://github.com/rgthree/rgthree-comfy"
21
+ "https://github.com/ltdrdata/ComfyUI-Impact-Pack"
22
+ "https://github.com/yolain/ComfyUI-Easy-Use"
23
+ "https://github.com/ssitu/ComfyUI_UltimateSDUpscale"
24
+ "https://github.com/sipherxyz/comfyui-art-venture"
25
+ "https://github.com/ltdrdata/ComfyUI-Impact-Subpack"
26
+ "https://github.com/moonwhaler/comfyui-moonpack"
27
+ "https://github.com/gseth/ControlAltAI-Nodes"
28
+ "https://github.com/vrgamegirl19/comfyui-vrgamedevgirl"
29
+ "https://github.com/numz/ComfyUI-SeedVR2_VideoUpscaler"
30
+ "https://github.com/robertvoy/ComfyUI-Flux-Continuum"
31
+ "https://github.com/ltdrdata/was-node-suite-comfyui"
32
+ "https://github.com/ChangeTheConstants/SeedVarianceEnhancer"
33
+ "https://github.com/city96/ComfyUI-GGUF"
34
+ "https://github.com/kijai/ComfyUI-KJNodes"
35
+ "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes"
36
+ "https://github.com/pythongosssss/ComfyUI-Custom-Scripts"
37
+ )
38
+
39
+ WORKFLOWS=(
40
+ )
41
+
42
+ SAMS=(
43
+ )
44
+
45
+
46
+ CHECKPOINT_MODELS=(
47
+ )
48
+
49
+ BBOX=(
50
+ )
51
+
52
+ UNET_MODELS=(
53
+ )
54
+
55
+ # Format: "URL|filename.safetensors"
56
+ LORA_MODELS=(
57
+ )
58
+
59
+ VAE_MODELS=(
60
+ "https://huggingface.co/Comfy-Org/Qwen-Image-Edit_ComfyUI/blob/main/split_files/vae/qwen_image_vae.safetensors"
61
+ "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged/blob/main/split_files/vae/wan2.2_vae.safetensors"
62
+ )
63
+
64
+ DIFFUSION_MODELS=(
65
+ "https://huggingface.co/Comfy-Org/Qwen-Image-Edit_ComfyUI/blob/main/split_files/diffusion_models/qwen_image_edit_fp8_e4m3fn.safetensors"
66
+ "https://huggingface.co/Kijai/WanVideo_comfy_fp8_scaled/blob/main/Wan22Animate/Wan2_2-Animate-14B_fp8_e4m3fn_scaled_KJ.safetensors"
67
+ "https://huggingface.co/numz/SeedVR2_comfyUI/blob/main/seedvr2_ema_3b_fp8_e4m3fn.safetensors"
68
+ )
69
+
70
+ TEXT_ENCODERS=(
71
+ "https://huggingface.co/Comfy-Org/Qwen-Image-Edit_ComfyUI/blob/main/split_files/text_encoders/qwen_2.5_vl_7b_fp8_scaled.safetensors"
72
+ "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/blob/main/split_files/text_encoders/umt5_xxl_fp8_e4m3fn_scaled.safetensors"
73
+ )
74
+
75
+ ESRGAN_MODELS=(
76
+ )
77
+
78
+ CONTROLNET_MODELS=(
79
+ )
80
+
81
+ ### DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ###
82
+
83
+ function provisioning_start() {
84
+ provisioning_print_header
85
+ provisioning_get_apt_packages
86
+ provisioning_get_nodes
87
+ provisioning_get_pip_packages
88
+ provisioning_get_files \
89
+ "${COMFYUI_DIR}/models/sams" \
90
+ "${SAMS[@]}"
91
+ provisioning_get_files \
92
+ "${COMFYUI_DIR}/models/checkpoints" \
93
+ "${CHECKPOINT_MODELS[@]}"
94
+ provisioning_get_files \
95
+ "${COMFYUI_DIR}/models/ultralytics/bbox" \
96
+ "${BBOX[@]}"
97
+ provisioning_get_files \
98
+ "${COMFYUI_DIR}/models/unet" \
99
+ "${UNET_MODELS[@]}"
100
+ provisioning_get_files \
101
+ "${COMFYUI_DIR}/models/loras" \
102
+ "${LORA_MODELS[@]}"
103
+ provisioning_get_files \
104
+ "${COMFYUI_DIR}/models/diffusion_models" \
105
+ "${DIFFUSION_MODELS[@]}"
106
+ provisioning_get_files \
107
+ "${COMFYUI_DIR}/models/text_encoders" \
108
+ "${TEXT_ENCODERS[@]}"
109
+ provisioning_get_files \
110
+ "${COMFYUI_DIR}/models/controlnet" \
111
+ "${CONTROLNET_MODELS[@]}"
112
+ provisioning_get_files \
113
+ "${COMFYUI_DIR}/models/vae" \
114
+ "${VAE_MODELS[@]}"
115
+ provisioning_get_files \
116
+ "${COMFYUI_DIR}/user/default/workflows" \
117
+ "${WORKFLOWS[@]}"
118
+ provisioning_get_files \
119
+ "${COMFYUI_DIR}/models/esrgan" \
120
+ "${ESRGAN_MODELS[@]}"
121
+ provisioning_print_end
122
+ }
123
+
124
+ function provisioning_get_apt_packages() {
125
+ if [[ -n $APT_PACKAGES ]]; then
126
+ sudo $APT_INSTALL ${APT_PACKAGES[@]}
127
+ fi
128
+ }
129
+
130
+ function provisioning_get_pip_packages() {
131
+ if [[ -n $PIP_PACKAGES ]]; then
132
+ pip install --no-cache-dir ${PIP_PACKAGES[@]}
133
+ fi
134
+ }
135
+
136
+ function provisioning_get_nodes() {
137
+ for repo in "${NODES[@]}"; do
138
+ dir="${repo##*/}"
139
+ path="${COMFYUI_DIR}/custom_nodes/${dir}"
140
+ requirements="${path}/requirements.txt"
141
+ if [[ -d $path ]]; then
142
+ if [[ ${AUTO_UPDATE,,} != "false" ]]; then
143
+ printf "Updating node: %s...\n" "${repo}"
144
+ ( cd "$path" && git pull )
145
+ if [[ -e $requirements ]]; then
146
+ pip install --no-cache-dir -r "$requirements"
147
+ fi
148
+ fi
149
+ else
150
+ printf "Downloading node: %s...\n" "${repo}"
151
+ git clone "${repo}" "${path}" --recursive
152
+ if [[ -e $requirements ]]; then
153
+ pip install --no-cache-dir -r "${requirements}"
154
+ fi
155
+ fi
156
+ done
157
+ }
158
+
159
+ function provisioning_get_files() {
160
+ if [[ -z $2 ]]; then return 1; fi
161
+
162
+ dir="$1"
163
+ mkdir -p "$dir"
164
+ shift
165
+ arr=("$@")
166
+ printf "Downloading %s model(s) to %s...\n" "${#arr[@]}" "$dir"
167
+ for entry in "${arr[@]}"; do
168
+ # Support "URL|filename" format for custom filenames
169
+ if [[ "$entry" == *"|"* ]]; then
170
+ url="${entry%%|*}"
171
+ filename="${entry##*|}"
172
+ else
173
+ url="$entry"
174
+ filename=""
175
+ fi
176
+ printf "Downloading: %s\n" "${url}"
177
+ provisioning_download "${url}" "${dir}" "${filename}"
178
+ printf "\n"
179
+ done
180
+ }
181
+
182
+ function provisioning_print_header() {
183
+ 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"
184
+ }
185
+
186
+ function provisioning_print_end() {
187
+ printf "\nProvisioning complete: Application will start now\n\n"
188
+ }
189
+
190
+ function provisioning_has_valid_hf_token() {
191
+ [[ -n "$HF_TOKEN" ]] || return 1
192
+ url="https://huggingface.co/api/whoami-v2"
193
+
194
+ response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
195
+ -H "Authorization: Bearer $HF_TOKEN" \
196
+ -H "Content-Type: application/json")
197
+
198
+ if [ "$response" -eq 200 ]; then
199
+ return 0
200
+ else
201
+ return 1
202
+ fi
203
+ }
204
+
205
+ function provisioning_has_valid_civitai_token() {
206
+ [[ -n "$CIVITAI_TOKEN" ]] || return 1
207
+ url="https://civitai.com/api/v1/models?hidden=1&limit=1"
208
+
209
+ response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
210
+ -H "Authorization: Bearer $CIVITAI_TOKEN" \
211
+ -H "Content-Type: application/json")
212
+
213
+ if [ "$response" -eq 200 ]; then
214
+ return 0
215
+ else
216
+ return 1
217
+ fi
218
+ }
219
+
220
+ # Download CivitAI models with curl (pure bash)
221
+ function download_civitai_bash() {
222
+ local url="$1"
223
+ local output_dir="$2"
224
+ local forced_filename="$3"
225
+ local model_id=""
226
+
227
+ if [[ $url =~ /models/([0-9]+) ]]; then
228
+ model_id="${BASH_REMATCH[1]}"
229
+ else
230
+ printf "ERROR: Could not extract model ID from URL\n"
231
+ return 1
232
+ fi
233
+
234
+ printf "Downloading CivitAI model %s...\n" "$model_id"
235
+
236
+ if [[ -n "$forced_filename" ]]; then
237
+ local output_file="${output_dir}/${forced_filename}"
238
+ if [[ -f "$output_file" ]]; then
239
+ printf "File already exists: %s\n" "$forced_filename"
240
+ return 0
241
+ fi
242
+ printf "Downloading to: %s\n" "$forced_filename"
243
+ if [[ -n "$CIVITAI_TOKEN" ]]; then
244
+ curl -L -o "$output_file" --progress-bar -H "Authorization: Bearer $CIVITAI_TOKEN" "$url"
245
+ else
246
+ curl -L -o "$output_file" --progress-bar "$url"
247
+ fi
248
+ if [[ $? -eq 0 ]]; then
249
+ printf "Download completed: %s\n" "$forced_filename"
250
+ return 0
251
+ else
252
+ printf "ERROR: Download failed for model %s\n" "$model_id"
253
+ return 1
254
+ fi
255
+ fi
256
+
257
+ local redirect_url=""
258
+ if [[ -n "$CIVITAI_TOKEN" ]]; then
259
+ 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')
260
+ else
261
+ redirect_url=$(curl -s -I -L "$url" | grep -i "^location:" | tail -1 | sed 's/location: //i' | tr -d '\r\n')
262
+ fi
263
+
264
+ if [[ -z "$redirect_url" ]]; then
265
+ printf "ERROR: Could not get redirect URL for model %s\n" "$model_id"
266
+ return 1
267
+ fi
268
+
269
+ local filename=""
270
+
271
+ if [[ $redirect_url =~ response-content-disposition=attachment.*filename%3D%22([^%\"]+) ]]; then
272
+ filename="${BASH_REMATCH[1]}"
273
+ filename=$(echo "$filename" | sed 's/%20/ /g; s/%2D/-/g; s/%2E/./g; s/%5F/_/g')
274
+ elif [[ $redirect_url =~ filename=\"([^\"]+)\" ]]; then
275
+ filename="${BASH_REMATCH[1]}"
276
+ elif [[ $redirect_url =~ filename=([^&]+) ]]; then
277
+ filename="${BASH_REMATCH[1]}"
278
+ else
279
+ local path_part=$(echo "$redirect_url" | sed 's/?.*//')
280
+ filename=$(basename "$path_part")
281
+ if [[ ! "$filename" =~ \.(safetensors|pt|pth|ckpt|bin)$ ]]; then
282
+ filename="${filename}.safetensors"
283
+ fi
284
+ fi
285
+
286
+ filename=$(printf '%b' "${filename//%/\\x}")
287
+
288
+ if [[ -z "$filename" ]] || [[ "$filename" == "." ]] || [[ "$filename" == ".safetensors" ]]; then
289
+ filename="civitai_${model_id}.safetensors"
290
+ fi
291
+
292
+ local output_file="${output_dir}/${filename}"
293
+
294
+ if [[ -f "$output_file" ]]; then
295
+ printf "File already exists: %s\n" "$filename"
296
+ return 0
297
+ fi
298
+
299
+ printf "Downloading to: %s\n" "$filename"
300
+ curl -L -o "$output_file" --progress-bar "$redirect_url"
301
+
302
+ if [[ $? -eq 0 ]]; then
303
+ printf "Download completed: %s\n" "$filename"
304
+ return 0
305
+ else
306
+ printf "ERROR: Download failed for model %s\n" "$model_id"
307
+ return 1
308
+ fi
309
+ }
310
+
311
+ # Download from $1 URL to $2 file path, with optional $3 forced filename
312
+ function provisioning_download() {
313
+ local url="$1"
314
+ local dir="$2"
315
+ local forced_filename="$3"
316
+
317
+ if [[ $url =~ ^https://civitai\.com/api/download/models/([0-9]+) ]]; then
318
+ download_civitai_bash "$url" "$dir" "$forced_filename"
319
+ else
320
+ if [[ -n "$forced_filename" ]]; then
321
+ wget -qnc --show-progress -e dotbytes="${4:-4M}" -O "${dir}/${forced_filename}" "$url"
322
+ else
323
+ wget -qnc --content-disposition --show-progress -e dotbytes="${4:-4M}" -P "$dir" "$url"
324
+ fi
325
+ fi
326
+ }
327
+
328
+ # Allow user to disable provisioning if they started with a script they didn't want
329
+ if [[ ! -f /.noprovisioning ]]; then
330
+ provisioning_start
331
+ fi