adbrasi commited on
Commit
1b4ee18
·
verified ·
1 Parent(s): 82e01b7

Update wanForProduction.sh

Browse files
Files changed (1) hide show
  1. wanForProduction.sh +193 -427
wanForProduction.sh CHANGED
@@ -1,12 +1,13 @@
1
  #!/usr/bin/env bash
2
- # setup_comfyui_combined.sh
3
- # Script baseado no CODE1 com melhorias e modelos/nodes do CODE2
 
 
 
4
 
5
  set -euo pipefail
6
 
7
- # -----------------------------
8
- # Cores para output
9
- # -----------------------------
10
  RED='\033[0;31m'
11
  GREEN='\033[0;32m'
12
  YELLOW='\033[1;33m'
@@ -18,69 +19,66 @@ log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
18
  log_warn() { echo -e "${YELLOW}[!]${NC} $1"; }
19
  log_error() { echo -e "${RED}[✗]${NC} $1"; }
20
 
21
- command_exists() { command -v "$1" >/dev/null 2>&1; }
22
-
23
- # -----------------------------
24
  # Configuração
25
- # -----------------------------
26
- COMFY_DIR="${COMFY_DIR:-/root/comfy/ComfyUI}"
27
  MODELS_DIR="$COMFY_DIR/models"
28
- COMFY_HOST="${COMFY_HOST:-0.0.0.0}"
29
- COMFY_PORT="${COMFY_PORT:-8818}"
30
- CIVITAI_TOKEN="${CIVITAI_TOKEN:-4fcb2834969399006a736ee402b061e5}"
31
- HF_TOKEN="${HF_TOKEN:-}"
32
-
33
- # Configurações de performance
34
- export MAX_JOBS=${MAX_JOBS:-32}
35
- export NVCC_APPEND_FLAGS="${NVCC_APPEND_FLAGS:---threads 8}"
36
- export UV_SYSTEM_PYTHON=1
37
- export PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True"
38
  export HF_HUB_ENABLE_HF_TRANSFER=1
39
- export HF_TRANSFER_CONCURRENCY=${HF_TRANSFER_CONCURRENCY:-16}
40
- export EXT_PARALLEL=${EXT_PARALLEL:-4}
41
-
42
- # -----------------------------
43
- # Listas de downloads (modelos do CODE2)
44
- # -----------------------------
45
- readonly DOWNLOAD_FILES=(
46
- "hf://Kijai/WanVideo_comfy/Wan22-Lightning/Wan2.2-Lightning_T2V-v1.1-A14B-4steps-lora_HIGH_fp16.safetensors|loras|Wan2.2-Lightning_T2V-v1.1-A14B-4steps-lora_HIGH_fp16.safetensors"
47
- "hf://Kijai/WanVideo_comfy/Wan22-Lightning/Wan2.2-Lightning_T2V-v1.1-A14B-4steps-lora_LOW_fp16.safetensors|loras|Wan2.2-Lightning_T2V-v1.1-A14B-4steps-lora_LOW_fp16.safetensors"
48
- "hf://Kijai/WanVideo_comfy_fp8_scaled/I2V/Wan2_2-I2V-A14B-HIGH_fp8_e5m2_scaled_KJ.safetensors|diffusion_models|Wan2_2-I2V-A14B-HIGH_fp8_e5m2_scaled_KJ.safetensors"
49
- "hf://Kijai/WanVideo_comfy_fp8_scaled/I2V/Wan2_2-I2V-A14B-LOW_fp8_e5m2_scaled_KJ.safetensors|diffusion_models|Wan2_2-I2V-A14B-LOW_fp8_e5m2_scaled_KJ.safetensors"
50
- "hf://Kijai/WanVideo_comfy/Wan22-Lightning/Wan2.2-Lightning_I2V-A14B-4steps-lora_HIGH_fp16.safetensors|loras|Wan2.2-Lightning_I2V-A14B-4steps-lora_HIGH_fp16.safetensors"
51
- "hf://Kijai/WanVideo_comfy/Wan22-Lightning/Wan2.2-Lightning_I2V-A14B-4steps-lora_LOW_fp16.safetensors|loras|Wan2.2-Lightning_I2V-A14B-4steps-lora_LOW_fp16.safetensors"
52
- "hf://Kijai/WanVideo_comfy/Wan2_1_VAE_fp32.safetensors|vae|Wan2_1_VAE_fp32.safetensors"
53
- "hf://Kijai/WanVideo_comfy/umt5-xxl-enc-bf16.safetensors|text_encoders|umt5-xxl-enc-bf16.safetensors"
54
- "hf://Kijai/WanVideo_comfy/Lightx2v/lightx2v_I2V_14B_480p_cfg_step_distill_rank256_bf16.safetensors|loras|lightx2v_I2V_14B_480p_cfg_step_distill_rank256_bf16.safetensors"
55
- "hf://Comfy-Org/Wan_2.2_ComfyUI_Repackaged/split_files/vae/wan_2.1_vae.safetensors|vae|wan_2.1_vae.safetensors"
56
- "hf://Comfy-Org/Wan_2.2_ComfyUI_Repackaged/split_files/text_encoders/umt5_xxl_fp16.safetensors|text_encoders|umt5_xxl_fp16.safetensors"
57
- "hf://Kijai/WanVideo_comfy/open-clip-xlm-roberta-large-vit-huge-14_visual_fp32.safetensors|clip_vision|open-clip-xlm-roberta-large-vit-huge-14_visual_fp32.safetensors"
58
- "hf://Comfy-Org/Wan_2.1_ComfyUI_repackaged/split_files/clip_vision/clip_vision_h.safetensors|clip_vision|clip_vision_h.safetensors"
59
- "https://huggingface.co/ABDALLALSWAITI/Upscalers/resolve/main/anime/2x-AnimeSharpV2_MoSR_Soft.pth|upscale_models|2x-AnimeSharpV2_MoSR_Soft.pth"
60
- )
61
 
62
- readonly MEGA_LORAS=(
63
- "https://mega.nz/file/QFxREJpZ#0dge8TyRgb52lMFKdsk-Ac-rwcoG49hvBHvaqNsZkuk"
64
- "https://mega.nz/file/lIhQETjT#nKlQ01Euw6fUxo8P5bfwlQrxAkWEedXQQOqHv5u4yrM"
65
- "https://mega.nz/file/UIAESACY#Qlei1Pj5Nwno3Sz-wsTekvD-YgCkN1A5QbFKoRHXG9E"
66
- "https://mega.nz/file/cdAg1Q7D#tQVrer2sB-M7XdYiKAqr7kRRfJw4pXCdliOg2aPJUGE"
67
- "https://mega.nz/file/5RQFiAAJ#QCWrHkuJjXlFufR18g5R9YXJGqJ1pQp7xbqNRgSYUjc"
68
- "https://mega.nz/file/tABgxLTS#NNlPV8NPc7R52MIjABMFUb41EOFDxFoszBxOrPMN13Q"
69
- "https://mega.nz/file/4MxBgJ5Y#R8OSby0u-t-QFBnpnOtdjN3xuiVRvHa4_OEzTwWoGKQ"
70
- "https://mega.nz/file/dJJxiSRR#o3XsYfSvb04xg7gNVdfHb3XTVHgvx0ZyXe9N8VQ9Lfw"
71
- "https://mega.nz/file/wcAFhRJZ#ifZcckts0wPq1FG693tYLkpFrvjXvab1ZQeL6DuL1T8"
72
- "https://mega.nz/file/wNIgmRwb#vn6rKM3QuTDpWVTLEBDsKjIkNkaX2wLKeauKNeVkcFs"
73
- "https://mega.nz/file/hZhhhCQS#4je0Im2g1kEvTCuPotjVWkA-g6XICkqMb-mKxMt6R3Y"
74
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
- readonly MEGA_UPSCALE=(
77
- "https://mega.nz/file/qdQwAJSC#rPY2Hg4x-_RbHiHUBFW-YU8xZUqPpq5Gpl1uPFiJvW4"
78
- "https://mega.nz/file/KIh2marA#CehVNXxQhGfp1bqUL0K1YPWNqrCUoLPCZGq2W6XqmWo"
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  )
80
 
81
- readonly RIFE_MODELS=()
82
-
83
- readonly CUSTOM_NODES=(
 
84
  "https://github.com/kijai/ComfyUI-Florence2"
85
  "https://github.com/adbrasi/groqrouter"
86
  "https://github.com/kijai/ComfyUI-WanVideoWrapper"
@@ -107,452 +105,220 @@ readonly CUSTOM_NODES=(
107
  "https://github.com/grmchn/ComfyUI-ProportionChanger"
108
  )
109
 
110
- # -----------------------------
111
- # Funções auxiliares
112
- # -----------------------------
113
- apt_update_safe() {
114
- if command_exists apt-get; then
115
- export DEBIAN_FRONTEND=noninteractive
116
- apt-get update -y || log_warn "apt-get update falhou; seguindo mesmo assim."
117
- else
118
- log_warn "apt-get não disponível; pulando update."
119
- fi
120
- }
121
-
122
- apt_install_safe() {
123
- if command_exists apt-get; then
124
- export DEBIAN_FRONTEND=noninteractive
125
- apt-get install -y "$@" || log_warn "Falha ao instalar pacote(s): $*"
126
- else
127
- log_warn "apt-get não disponível; não foi possível instalar: $*"
128
- fi
129
- }
130
-
131
- stat_bytes() {
132
- local path="$1"
133
- stat -c%s "$path" 2>/dev/null || echo 0
134
- }
135
-
136
- add_civitai_token() {
137
- local url="$1"
138
- if [[ "$url" == *"civitai.com/api/download"* ]] && [[ "$url" != *"token="* ]] && [[ -n "$CIVITAI_TOKEN" ]]; then
139
- if [[ "$url" == *"?"* ]]; then
140
- printf '%s&token=%s' "$url" "$CIVITAI_TOKEN"
141
- else
142
- printf '%s?token=%s' "$url" "$CIVITAI_TOKEN"
143
- fi
144
- else
145
- printf '%s' "$url"
146
- fi
147
- }
148
 
149
  download_hf() {
150
- local repo="$1"
151
- local file_path="$2"
152
- local target_dir="$3"
153
- local filename="$4"
154
-
155
- if [[ -z "$filename" ]]; then
156
- filename="$(basename "$file_path")"
157
- fi
158
 
159
- local target_file="$target_dir/$filename"
160
- if [[ -f "$target_file" ]] && (( $(stat_bytes "$target_file") > 1000000 )); then
161
- log_success "Arquivo já existe: $filename"
162
  return 0
163
  fi
164
 
165
- log_info "Baixando de HF: $filename"
166
- local temp_dir
167
- temp_dir="$(mktemp -d)"
168
- local success=false
169
-
170
- if command_exists hf; then
171
- if HF_HUB_ENABLE_HF_TRANSFER=1 hf download "$repo" "$file_path" --local-dir "$temp_dir" --local-dir-use-symlinks False; then
172
- success=true
173
- else
174
- log_warn "hf download falhou; tentando fallback."
175
- fi
176
- fi
177
 
178
- if [[ "$success" == false ]] && command_exists huggingface-cli; then
179
- if HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download "$repo" "$file_path" --local-dir "$temp_dir" --local-dir-use-symlinks False; then
180
- success=true
181
- else
182
- log_warn "huggingface-cli falhou; tentando download direto."
183
- fi
184
  fi
185
 
186
- if [[ "$success" == false ]]; then
187
- local direct_url="https://huggingface.co/${repo}/resolve/main/${file_path}"
188
- local header=""
189
- if [[ -n "$HF_TOKEN" ]]; then
190
- header="Authorization: Bearer ${HF_TOKEN}"
191
- fi
192
- if command_exists aria2c; then
193
- local aria_cmd=(aria2c -c -s 16 -x 16 -k 1M --console-log-level=warn --summary-interval=10)
194
- if [[ -n "$header" ]]; then
195
- aria_cmd+=(--header="$header")
196
- fi
197
- aria_cmd+=(--dir="$temp_dir" --out="$filename" "$direct_url")
198
- if "${aria_cmd[@]}"; then
199
- success=true
200
- else
201
- log_warn "aria2c direto falhou; tentando curl/wget."
202
- fi
203
- fi
204
- if [[ "$success" == false ]] && command_exists curl; then
205
- local curl_cmd=(curl -L -# -o "$temp_dir/$filename")
206
- if [[ -n "$header" ]]; then
207
- curl_cmd+=(-H "$header")
208
- fi
209
- curl_cmd+=("$direct_url")
210
- if "${curl_cmd[@]}"; then
211
- success=true
212
- fi
213
- fi
214
- if [[ "$success" == false ]] && command_exists wget; then
215
- local wget_cmd=(wget -q --show-progress -c -O "$temp_dir/$filename")
216
- if [[ -n "$header" ]]; then
217
- wget_cmd+=(--header="$header")
218
- fi
219
- wget_cmd+=("$direct_url")
220
- if "${wget_cmd[@]}"; then
221
- success=true
222
- fi
223
- fi
224
- fi
225
 
226
- if [[ "$success" == true ]]; then
227
- local downloaded_file
228
- downloaded_file="$(find "$temp_dir" -maxdepth 1 -type f | head -n 1)"
229
- if [[ -n "$downloaded_file" ]]; then
230
- mkdir -p "$target_dir"
231
- mv "$downloaded_file" "$target_file"
232
- rm -rf "$temp_dir"
233
- log_success "Download concluído: $filename"
234
- return 0
235
- fi
 
236
  fi
237
-
238
- rm -rf "$temp_dir"
239
- log_error "Falha ao baixar: $filename"
240
- return 1
241
  }
242
 
243
- download_file() {
244
  local url="$1"
245
  local target_dir="$2"
246
- local filename="$3"
247
-
248
- url="$(add_civitai_token "$url")"
249
- mkdir -p "$target_dir"
250
-
251
- local final_name="$filename"
252
- if [[ -z "$final_name" ]]; then
253
- final_name="$(basename "${url%%\?*}")"
254
- fi
255
 
256
- if [[ -f "$target_dir/$final_name" ]] && (( $(stat_bytes "$target_dir/$final_name") > 500000 )); then
257
- log_success "Arquivo já existe: $final_name"
258
- return 0
259
- fi
260
 
261
- log_info "Baixando: $final_name"
262
 
263
- if command_exists aria2c; then
264
- local aria_opts=(-c -s 16 -x 16 -k 1M --console-log-level=warn --summary-interval=10)
265
- if aria2c "${aria_opts[@]}" --dir="$target_dir" --out="$final_name" "$url"; then
266
- return 0
267
- fi
268
- log_warn "aria2c falhou; tentando wget/curl."
269
- fi
270
-
271
- if command_exists wget; then
272
- if wget -q --show-progress -c -O "$target_dir/$final_name" "$url"; then
273
- return 0
274
- fi
275
- log_warn "wget falhou; tentando curl."
276
- fi
277
-
278
- if command_exists curl; then
279
- if curl -L -# -C - -o "$target_dir/$final_name" "$url"; then
280
- return 0
281
- fi
282
  fi
283
-
284
- log_error "Falha ao baixar: $url"
285
- return 1
286
  }
287
 
288
- download_mega() {
289
  local url="$1"
290
  local target_dir="$2"
 
291
 
292
- url="${url#mega://}"
293
- mkdir -p "$target_dir"
 
 
294
 
295
- if ! command_exists megadl; then
296
- log_warn "megadl não encontrado; tentando instalar megatools."
297
- apt_update_safe
298
- apt_install_safe megatools
299
  fi
300
 
301
- if command_exists megadl; then
302
- log_info "Baixando de Mega.nz: $url"
303
- if (cd "$target_dir" && megadl "$url"); then
304
- log_success "Download Mega.nz concluído"
305
- return 0
 
 
 
 
 
 
306
  fi
 
 
 
 
 
 
307
  fi
308
-
309
- log_error "Falha ao baixar de Mega.nz: $url"
310
- return 1
311
  }
312
 
313
  process_downloads() {
314
- local failed=0
315
  for entry in "${DOWNLOAD_FILES[@]}"; do
316
- IFS='|' read -r raw_url type filename <<< "$entry"
317
- raw_url="$(echo "$raw_url" | xargs)"
318
- type="$(echo "$type" | xargs)"
319
- filename="$(echo "$filename" | xargs)"
320
 
321
  local target_dir="$MODELS_DIR/$type"
322
  mkdir -p "$target_dir"
323
 
324
- local attempt success=false
325
- local label="$filename"
326
- if [[ -z "$label" ]]; then
327
- label="$(basename "${raw_url%%\?*}")"
328
- fi
329
- if [[ -z "$label" || "$label" == "." ]]; then
330
- label="$raw_url"
331
- fi
332
- for attempt in 1 2 3; do
333
- if [[ "$raw_url" == mega://* ]]; then
334
- if download_mega "$raw_url" "$target_dir"; then
335
- success=true
336
- fi
337
- elif [[ "$raw_url" == hf://* ]]; then
338
- local trimmed="${raw_url#hf://}"
339
- local repo="$(echo "$trimmed" | cut -d'/' -f1-2)"
340
- local file_path="$(echo "$trimmed" | cut -d'/' -f3-)"
341
- if download_hf "$repo" "$file_path" "$target_dir" "$filename"; then
342
- success=true
343
- fi
344
- else
345
- if download_file "$raw_url" "$target_dir" "$filename"; then
346
- success=true
347
- fi
348
- fi
349
-
350
- if [[ "$success" == true ]]; then
351
- break
352
- fi
353
-
354
- log_warn "Tentativa $attempt falhou para $label; aguardando antes de tentar novamente."
355
- sleep $((2 * attempt))
356
- done
357
-
358
- if [[ "$success" == false ]]; then
359
- log_error "Falhou após múltiplas tentativas: $label"
360
- ((failed++))
361
  fi
362
  done
363
-
364
- return $failed
365
  }
366
 
367
- clone_or_update() {
368
  local url="$1"
369
  local dest="$2"
370
- local node_name
371
- node_name="$(basename "$dest")"
372
-
373
- mkdir -p "$(dirname "$dest")"
374
 
375
- if [[ -d "$dest/.git" ]]; then
376
- log_info "Atualizando $node_name..."
377
- if ! timeout 120 git -C "$dest" pull --ff-only --rebase=false; then
378
- log_warn "Timeout/erro ao atualizar $node_name"
379
- fi
380
  else
381
- log_info "Clonando $node_name..."
382
- if ! timeout 120 git clone --recursive --depth 1 "$url" "$dest"; then
383
- log_warn "Falha ao clonar $node_name"
384
- return
385
- fi
386
  fi
387
 
388
- if [[ -f "$dest/requirements.txt" ]]; then
389
- if ! timeout 180 python3 -m pip install --no-warn-script-location -q -r "$dest/requirements.txt"; then
390
- log_warn "Falha ao instalar requirements para $node_name"
391
- fi
392
  fi
393
  }
394
 
395
- install_sageattention() {
396
- log_info "[5/9] Instalando SageAttention..."
397
- if python3 - <<'PY' 2>/dev/null | grep -q True; then
398
- import torch
399
- print(torch.cuda.is_available())
400
- PY
401
- if python3 -m pip install "https://huggingface.co/adbrasi/comfywheel/resolve/main/sageattention-2.2.0-cp311-cp311-linux_x86_64.whl" -q; then
402
- if python3 - <<'PY' >/dev/null 2>&1; then
403
- import sageattention
404
- PY
405
- log_success "SageAttention instalado"
406
- else
407
- log_warn "SageAttention instalado mas não pôde ser importado"
408
- fi
409
- else
410
- log_warn "Falha ao instalar SageAttention"
411
- fi
412
- else
413
- log_warn "CUDA não detectado; pulando SageAttention"
414
- fi
415
- }
416
 
417
- # -----------------------------
418
- # Instalação principal
419
- # -----------------------------
420
  log_info "========================================="
421
- log_info " ComfyUI + Wan 2.2 Setup (Merged)"
422
  log_info "========================================="
423
 
424
- log_info "[1/9] Preparando dependências do sistema..."
425
- if ! command_exists aria2c || ! command_exists megadl; then
426
- apt_update_safe
427
- command_exists aria2c || apt_install_safe aria2
428
- command_exists megadl || apt_install_safe megatools
429
- fi
430
- for cmd in python3 git wget curl; do
431
- if ! command_exists "$cmd"; then
432
- log_error "Dependência faltando: $cmd"
433
- exit 1
434
- fi
435
- done
436
- log_success "Dependências de sistema OK"
437
 
438
- log_info "[2/9] Atualizando pip e ferramentas Python..."
439
- python3 -m pip install --upgrade pip wheel setuptools -q
440
- python3 -m pip install --upgrade "huggingface_hub[cli,hf_transfer]>=0.26.0" comfy-cli -q
441
- if [[ -n "$HF_TOKEN" ]] && command_exists huggingface-cli; then
442
- huggingface-cli login --token "$HF_TOKEN" --add-to-git-credential || log_warn "Falha ao autenticar no HuggingFace"
443
- fi
444
- if command_exists hf; then
445
- log_success "Ferramenta 'hf' disponível"
446
- elif command_exists huggingface-cli; then
447
- log_warn "Usando 'huggingface-cli' para downloads"
448
- else
449
- log_warn "Sem CLI oficial do HuggingFace; tentaremos fallback HTTP"
450
- fi
451
 
452
- log_info "[3/9] Instalando PyTorch CUDA 12.8..."
453
- python3 -m pip install --upgrade torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
454
- log_success "PyTorch com CUDA 12.8 instalado"
455
 
456
- log_info "[4/9] Instalando ComfyUI..."
457
- if [[ -f "$COMFY_DIR/main.py" ]]; then
458
- log_warn "ComfyUI já existe; pulando instalação base"
 
 
 
 
459
  else
460
  comfy --skip-prompt install --fast-deps --nvidia
461
- if [[ ! -f "$COMFY_DIR/main.py" ]]; then
462
- log_error "ComfyUI não foi instalado corretamente"
463
- exit 1
464
- fi
465
  fi
466
- log_success "ComfyUI disponível em $COMFY_DIR"
467
 
468
- install_sageattention
469
 
470
- log_info "[6/9] Baixando modelos principais..."
471
- mkdir -p "$MODELS_DIR"/{diffusion_models,loras,vae,vae_approx,text_encoders,clip_vision,controlnet,upscale_models,checkpoints}
472
- if process_downloads; then
473
- log_success "Modelos baixados (ou presentes)"
474
- else
475
- log_warn "Alguns modelos falharam. Consulte logs acima e tente novamente."
476
- fi
477
 
478
- log_info "[7/9] Baixando modelos RIFE (opcional)..."
479
- if (( ${#RIFE_MODELS[@]} )); then
480
- RIFE_DIR="$MODELS_DIR/tensorrt/rife"
481
- mkdir -p "$RIFE_DIR"
482
- for url in "${RIFE_MODELS[@]}"; do
483
- fname="$(basename "${url%%\?*}")"
484
- download_file "$url" "$RIFE_DIR" "$fname" || log_warn "Falha ao baixar RIFE: $fname"
485
- done
486
- log_success "Modelos RIFE processados"
 
 
 
 
487
  else
488
- log_warn "Lista RIFE vazia pulando"
489
  fi
490
 
491
- log_info "[8/9] Baixando arquivos do Mega.nz..."
492
- if (( ${#MEGA_LORAS[@]} )); then
493
- LORA_DIR="$MODELS_DIR/loras"
494
- mkdir -p "$LORA_DIR"
495
- for url in "${MEGA_LORAS[@]}"; do
496
- download_mega "$url" "$LORA_DIR" || log_warn "Mega.nz falhou: $url"
497
- done
498
- fi
499
- if (( ${#MEGA_UPSCALE[@]} )); then
500
- UPSCALE_DIR="$MODELS_DIR/upscale_models"
501
- mkdir -p "$UPSCALE_DIR"
502
- for url in "${MEGA_UPSCALE[@]}"; do
503
- download_mega "$url" "$UPSCALE_DIR" || log_warn "Mega.nz falhou: $url"
504
- done
505
- fi
506
- log_success "Downloads Mega.nz concluídos (quando disponíveis)"
507
 
508
- log_info "[9/9] Instalando custom nodes..."
509
  CN_DIR="$COMFY_DIR/custom_nodes"
510
  mkdir -p "$CN_DIR"
 
511
  total_nodes=${#CUSTOM_NODES[@]}
512
  current_node=0
 
513
  for repo in "${CUSTOM_NODES[@]}"; do
514
  ((current_node++))
515
- log_info "[$current_node/$total_nodes] Processando $(basename "$repo")"
516
- clone_or_update "$repo" "$CN_DIR/$(basename "$repo")"
 
517
  done
518
- log_success "Custom nodes instalados"
519
 
520
- check_critical_files() {
521
- local files=(
522
- "$COMFY_DIR/main.py"
523
- "$MODELS_DIR/vae/wan_2.1_vae.safetensors"
524
- "$MODELS_DIR/vae/Wan2_1_VAE_fp32.safetensors"
525
- "$MODELS_DIR/text_encoders/umt5_xxl_fp16.safetensors"
526
- "$MODELS_DIR/text_encoders/umt5-xxl-enc-bf16.safetensors"
527
- "$MODELS_DIR/clip_vision/clip_vision_h.safetensors"
528
- )
529
- local missing=0
530
- for file in "${files[@]}"; do
531
- if [[ -f "$file" ]]; then
532
- log_success "✓ $(basename "$file")"
533
- else
534
- log_warn "✗ $(basename "$file") não encontrado"
535
- ((missing++))
536
- fi
537
- done
538
- return $missing
539
- }
540
 
 
 
 
 
 
541
  log_info "========================================="
542
- if check_critical_files; then
543
- log_success "Instalação concluída com sucesso!"
544
- else
545
- log_warn "Alguns arquivos essenciais não foram encontrados. Veja avisos acima."
546
- fi
547
- log_info "Preparando para iniciar ComfyUI..."
548
 
 
 
 
549
  SAGE_FLAG=""
550
- if python3 - <<'PY' >/dev/null 2>&1; then
551
- import sageattention
552
- PY
553
  SAGE_FLAG="--use-sage-attention"
554
  fi
555
 
556
- cd "$COMFY_DIR"
557
- log_info "Iniciando ComfyUI em http://$COMFY_HOST:$COMFY_PORT"
558
  exec comfy launch -- ${SAGE_FLAG:+$SAGE_FLAG} --listen "$COMFY_HOST" --port "$COMFY_PORT"
 
1
  #!/usr/bin/env bash
2
+ # setup_comfyui_simple.sh (base do CODE1, ajustado)
3
+ # - troca de modelos/nodes pelos do CODE2
4
+ # - adiciona SageAttention
5
+ # - remove tratamento 5090/Blackwell
6
+ # - melhora download_hf para paths com subpastas e /resolve/
7
 
8
  set -euo pipefail
9
 
10
+ # Cores
 
 
11
  RED='\033[0;31m'
12
  GREEN='\033[0;32m'
13
  YELLOW='\033[1;33m'
 
19
  log_warn() { echo -e "${YELLOW}[!]${NC} $1"; }
20
  log_error() { echo -e "${RED}[✗]${NC} $1"; }
21
 
 
 
 
22
  # Configuração
23
+ COMFY_DIR="/root/comfy/ComfyUI"
 
24
  MODELS_DIR="$COMFY_DIR/models"
25
+ COMFY_HOST="0.0.0.0"
26
+ COMFY_PORT="8818"
27
+ CIVITAI_TOKEN="4fcb2834969399006a736ee402b061e5"
28
+
29
+ # Performance
30
+ export MAX_JOBS=32
 
 
 
 
31
  export HF_HUB_ENABLE_HF_TRANSFER=1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ # ===============================
34
+ # Lista de downloads (do CODE2)
35
+ # ===============================
36
+ # Formato: "URL|TIPO|NOME_OPCIONAL"
37
+ DOWNLOAD_FILES=(
38
+ # Wan 2.2 (Kijai) - use URLs SEM /resolve/ para usar o CLI da HF
39
+ "https://huggingface.co/Kijai/WanVideo_comfy/Wan22-Lightning/Wan2.2-Lightning_T2V-v1.1-A14B-4steps-lora_HIGH_fp16.safetensors|loras|Wan2.2-Lightning_T2V-v1.1-A14B-4steps-lora_HIGH_fp16.safetensors"
40
+ "https://huggingface.co/Kijai/WanVideo_comfy/Wan22-Lightning/Wan2.2-Lightning_T2V-v1.1-A14B-4steps-lora_LOW_fp16.safetensors|loras|Wan2.2-Lightning_T2V-v1.1-A14B-4steps-lora_LOW_fp16.safetensors"
41
+ "https://huggingface.co/Kijai/WanVideo_comfy_fp8_scaled/I2V/Wan2_2-I2V-A14B-HIGH_fp8_e5m2_scaled_KJ.safetensors|diffusion_models|Wan2_2-I2V-A14B-HIGH_fp8_e5m2_scaled_KJ.safetensors"
42
+ "https://huggingface.co/Kijai/WanVideo_comfy_fp8_scaled/I2V/Wan2_2-I2V-A14B-LOW_fp8_e5m2_scaled_KJ.safetensors|diffusion_models|Wan2_2-I2V-A14B-LOW_fp8_e5m2_scaled_KJ.safetensors"
43
+ "https://huggingface.co/Kijai/WanVideo_comfy/Wan22-Lightning/Wan2.2-Lightning_I2V-A14B-4steps-lora_HIGH_fp16.safetensors|loras|Wan2.2-Lightning_I2V-A14B-4steps-lora_HIGH_fp16.safetensors"
44
+ "https://huggingface.co/Kijai/WanVideo_comfy/Wan22-Lightning/Wan2.2-Lightning_I2V-A14B-4steps-lora_LOW_fp16.safetensors|loras|Wan2.2-Lightning_I2V-A14B-4steps-lora_LOW_fp16.safetensors"
45
+ "https://huggingface.co/Kijai/WanVideo_comfy/Wan2_1_VAE_fp32.safetensors|vae|Wan2_1_VAE_fp32.safetensors"
46
+ "https://huggingface.co/Kijai/WanVideo_comfy/umt5-xxl-enc-bf16.safetensors|text_encoders|umt5-xxl-enc-bf16.safetensors"
47
+
48
+ # Wan 2.1
49
+ "https://huggingface.co/Kijai/WanVideo_comfy/Lightx2v/lightx2v_I2V_14B_480p_cfg_step_distill_rank256_bf16.safetensors|loras|lightx2v_I2V_14B_480p_cfg_step_distill_rank256_bf16.safetensors"
50
+ "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged/split_files/vae/wan_2.1_vae.safetensors|vae|wan_2.1_vae.safetensors"
51
+ "https://huggingface.co/Comfy-Org/Wan_2.2_ComfyUI_Repackaged/split_files/text_encoders/umt5_xxl_fp16.safetensors|text_encoders|umt5_xxl_fp16.safetensors"
52
+
53
+ # Wan 2.1 clip vision
54
+ "https://huggingface.co/Kijai/WanVideo_comfy/open-clip-xlm-roberta-large-vit-huge-14_visual_fp32.safetensors|clip_vision|open-clip-xlm-roberta-large-vit-huge-14_visual_fp32.safetensors"
55
+ "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/split_files/clip_vision/clip_vision_h.safetensors|clip_vision|clip_vision_h.safetensors"
56
+
57
+ # Upscaler extra (com /resolve/ para baixar via HTTP direto)
58
+ "https://huggingface.co/ABDALLALSWAITI/Upscalers/resolve/main/anime/2x-AnimeSharpV2_MoSR_Soft.pth|upscale_models|2x-AnimeSharpV2_MoSR_Soft.pth"
59
 
60
+ # LoRAs via Mega.nz (do CODE2) — prefixo mega:// para usar função existente
61
+ "mega://https://mega.nz/file/QFxREJpZ#0dge8TyRgb52lMFKdsk-Ac-rwcoG49hvBHvaqNsZkuk|loras|"
62
+ "mega://https://mega.nz/file/lIhQETjT#nKlQ01Euw6fUxo8P5bfwlQrxAkWEedXQQOqHv5u4yrM|loras|"
63
+ "mega://https://mega.nz/file/UIAESACY#Qlei1Pj5Nwno3Sz-wsTekvD-YgCkN1A5QbFKoRHXG9E|loras|"
64
+ "mega://https://mega.nz/file/cdAg1Q7D#tQVrer2sB-M7XdYiKAqr7kRRfJw4pXCdliOg2aPJUGE|loras|"
65
+ "mega://https://mega.nz/file/5RQFiAAJ#QCWrHkuJjXlFufR18g5R9YXJGqJ1pQp7xbqNRgSYUjc|loras|"
66
+ "mega://https://mega.nz/file/tABgxLTS#NNlPV8NPc7R52MIjABMFUb41EOFDxFoszBxOrPMN13Q|loras|"
67
+ "mega://https://mega.nz/file/4MxBgJ5Y#R8OSby0u-t-QFBnpnOtdjN3xuiVRvHa4_OEzTwWoGKQ|loras|"
68
+ "mega://https://mega.nz/file/dJJxiSRR#o3XsYfSvb04xg7gNVdfHb3XTVHgvx0ZyXe9N8VQ9Lfw|loras|"
69
+ "mega://https://mega.nz/file/wcAFhRJZ#ifZcckts0wPq1FG693tYLkpFrvjXvab1ZQeL6DuL1T8|loras|"
70
+ "mega://https://mega.nz/file/wNIgmRwb#vn6rKM3QuTDpWVTLEBDsKjIkNkaX2wLKeauKNeVkcFs|loras|"
71
+ "mega://https://mega.nz/file/hZhhhCQS#4je0Im2g1kEvTCuPotjVWkA-g6XICkqMb-mKxMt6R3Y|loras|"
72
+
73
+ # Upscale via Mega.nz (do CODE2)
74
+ "mega://https://mega.nz/file/qdQwAJSC#rPY2Hg4x-_RbHiHUBFW-YU8xZUqPpq5Gpl1uPFiJvW4|upscale_models|"
75
+ "mega://https://mega.nz/file/KIh2marA#CehVNXxQhGfp1bqUL0K1YPWNqrCUoLPCZGq2W6XqmWo|upscale_models|"
76
  )
77
 
78
+ # ===============================
79
+ # Custom nodes (do CODE2)
80
+ # ===============================
81
+ CUSTOM_NODES=(
82
  "https://github.com/kijai/ComfyUI-Florence2"
83
  "https://github.com/adbrasi/groqrouter"
84
  "https://github.com/kijai/ComfyUI-WanVideoWrapper"
 
105
  "https://github.com/grmchn/ComfyUI-ProportionChanger"
106
  )
107
 
108
+ # ===============================
109
+ # Funções de download (mesmas do CODE1, porém download_hf melhorado)
110
+ # ===============================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
  download_hf() {
113
+ local url="$1"
114
+ local target_dir="$2"
115
+ local filename="$3"
 
 
 
 
 
116
 
117
+ if [ -n "$filename" ] && [ -f "$target_dir/$filename" ]; then
118
+ log_success " existe: $filename"
 
119
  return 0
120
  fi
121
 
122
+ log_info "Baixando HF: ${filename:-$(basename "$url")}"
 
 
 
 
 
 
 
 
 
 
 
123
 
124
+ # Se a URL vier com /resolve/, usa HTTP direto (evita problemas com 'hf download')
125
+ if [[ "$url" == *"/resolve/"* ]]; then
126
+ mkdir -p "$target_dir"
127
+ wget -q --show-progress -c -O "$target_dir/$filename" "https://huggingface.co/$url"
128
+ return $?
 
129
  fi
130
 
131
+ # Parse correto: repo_id = 2 primeiros segmentos; file_path = resto
132
+ local repo_id file_path
133
+ repo_id="$(echo "$url" | cut -d'/' -f1-2)"
134
+ file_path="$(echo "$url" | cut -d'/' -f3-)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
+ if command -v hf >/dev/null 2>&1; then
137
+ mkdir -p "$target_dir"
138
+ (cd "$target_dir" && HF_HUB_ENABLE_HF_TRANSFER=1 hf download "$repo_id" "$file_path" --local-dir . >/dev/null 2>&1) || {
139
+ log_warn "hf download falhou; tentando HTTP"
140
+ wget -q --show-progress -c -O "$target_dir/$filename" "https://huggingface.co/$repo_id/resolve/main/$file_path" || \
141
+ log_error "Download falhou: $filename"
142
+ }
143
+ else
144
+ mkdir -p "$target_dir"
145
+ wget -q --show-progress -c -O "$target_dir/$filename" "https://huggingface.co/$repo_id/resolve/main/$file_path" || \
146
+ log_error "Download falhou: $filename"
147
  fi
 
 
 
 
148
  }
149
 
150
+ download_mega() {
151
  local url="$1"
152
  local target_dir="$2"
 
 
 
 
 
 
 
 
 
153
 
154
+ url="${url#mega://}" # remove prefixo
 
 
 
155
 
156
+ log_info "Baixando do Mega..."
157
 
158
+ cd "$target_dir"
159
+ if megadl "$url" 2>/dev/null; then
160
+ log_success "Mega download OK"
161
+ else
162
+ log_warn "Mega download falhou"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  fi
164
+ cd - >/dev/null
 
 
165
  }
166
 
167
+ download_file() {
168
  local url="$1"
169
  local target_dir="$2"
170
+ local filename="$3"
171
 
172
+ # Adicionar token Civitai se necessário
173
+ if [[ "$url" == *"civitai.com"* ]] && [[ "$url" != *"token="* ]]; then
174
+ url="${url}&token=${CIVITAI_TOKEN}"
175
+ fi
176
 
177
+ if [ -n "$filename" ] && [ -f "$target_dir/$filename" ]; then
178
+ log_success " existe: $filename"
179
+ return 0
 
180
  fi
181
 
182
+ log_info "Baixando: ${filename:-arquivo}"
183
+
184
+ if command -v aria2c >/dev/null 2>&1; then
185
+ if [ -n "$filename" ]; then
186
+ aria2c -c -x 4 -s 4 --console-log-level=warn --dir="$target_dir" --out="$filename" "$url" || \
187
+ wget -q --show-progress -c -O "$target_dir/$filename" "$url" || \
188
+ log_error "Download falhou: $filename"
189
+ else
190
+ aria2c -c -x 4 -s 4 --console-log-level=warn --dir="$target_dir" "$url" || \
191
+ (cd "$target_dir" && wget -q --show-progress -c "$url") || \
192
+ log_error "Download falhou: $url"
193
  fi
194
+ elif [ -n "$filename" ]; then
195
+ wget -q --show-progress -c -O "$target_dir/$filename" "$url" || \
196
+ log_error "Download falhou: $filename"
197
+ else
198
+ (cd "$target_dir" && wget -q --show-progress -c "$url") || \
199
+ log_error "Download falhou: $url"
200
  fi
 
 
 
201
  }
202
 
203
  process_downloads() {
 
204
  for entry in "${DOWNLOAD_FILES[@]}"; do
205
+ IFS='|' read -r url type filename <<< "$entry"
 
 
 
206
 
207
  local target_dir="$MODELS_DIR/$type"
208
  mkdir -p "$target_dir"
209
 
210
+ if [[ "$url" == mega://* ]]; then
211
+ download_mega "$url" "$target_dir"
212
+ elif [[ "$url" == *.huggingface.co/* ]]; then
213
+ local hf_path="${url#*huggingface.co/}"
214
+ download_hf "$hf_path" "$target_dir" "$filename"
215
+ else
216
+ download_file "$url" "$target_dir" "$filename"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  fi
218
  done
 
 
219
  }
220
 
221
+ clone_repo() {
222
  local url="$1"
223
  local dest="$2"
 
 
 
 
224
 
225
+ if [ -d "$dest/.git" ]; then
226
+ git -C "$dest" pull --ff-only 2>/dev/null || true
 
 
 
227
  else
228
+ git clone --depth 1 "$url" "$dest" 2>/dev/null || true
 
 
 
 
229
  fi
230
 
231
+ if [ -f "$dest/requirements.txt" ]; then
232
+ pip install -q -r "$dest/requirements.txt" 2>/dev/null || true
 
 
233
  fi
234
  }
235
 
236
+ # ========== INSTALAÇÃO ==========
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
 
 
 
 
238
  log_info "========================================="
239
+ log_info " ComfyUI Setup"
240
  log_info "========================================="
241
 
242
+ # 1. Dependências
243
+ log_info "[1/6] Instalando dependências..."
 
 
 
 
 
 
 
 
 
 
 
244
 
245
+ apt-get update -qq
246
+ apt-get install -y -qq aria2 megatools git wget curl 2>/dev/null
 
 
 
 
 
 
 
 
 
 
 
247
 
248
+ pip install --upgrade pip wheel setuptools -q
249
+ pip install --upgrade "huggingface_hub[cli,hf_transfer]" comfy-cli -q
 
250
 
251
+ log_success "Dependências instaladas"
252
+
253
+ # 2. ComfyUI
254
+ log_info "[2/6] Instalando ComfyUI..."
255
+
256
+ if [ -f "$COMFY_DIR/main.py" ]; then
257
+ log_warn "ComfyUI já existe"
258
  else
259
  comfy --skip-prompt install --fast-deps --nvidia
 
 
 
 
260
  fi
 
261
 
262
+ log_success "ComfyUI instalado"
263
 
264
+ # 3. PyTorch CUDA 12.8 (substitui o bloco de Blackwell/5090 do CODE1)
265
+ log_info "[3/6] Instalando PyTorch (CUDA 12.8)..."
266
+ pip install --upgrade torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128 -q
267
+ log_success "PyTorch com CUDA 12.8 instalado"
 
 
 
268
 
269
+ # 4. SageAttention (do CODE2)
270
+ log_info "[4/6] Instalando SageAttention..."
271
+ if python3 - <<'PY' 2>/dev/null; then
272
+ import torch, sys
273
+ sys.exit(0 if torch.cuda.is_available() else 1)
274
+ PY
275
+ then
276
+ pip install -q "https://huggingface.co/adbrasi/comfywheel/resolve/main/sageattention-2.2.0-cp311-cp311-linux_x86_64.whl" || log_warn "Falha ao instalar SageAttention"
277
+ if python3 -c 'import sageattention' >/dev/null 2>&1; then
278
+ log_success "SageAttention instalado"
279
+ else
280
+ log_warn "SageAttention não pôde ser importado (seguindo sem)"
281
+ fi
282
  else
283
+ log_warn "CUDA não detectada, pulando SageAttention"
284
  fi
285
 
286
+ # 5. Modelos
287
+ log_info "[5/6] Baixando modelos..."
288
+ process_downloads
289
+ log_success "Downloads processados"
290
+
291
+ # 6. Custom nodes
292
+ log_info "[6/6] Instalando custom nodes..."
 
 
 
 
 
 
 
 
 
293
 
 
294
  CN_DIR="$COMFY_DIR/custom_nodes"
295
  mkdir -p "$CN_DIR"
296
+
297
  total_nodes=${#CUSTOM_NODES[@]}
298
  current_node=0
299
+
300
  for repo in "${CUSTOM_NODES[@]}"; do
301
  ((current_node++))
302
+ node_name=$(basename "$repo")
303
+ log_info "[$current_node/$total_nodes] Instalando: $node_name"
304
+ clone_repo "$repo" "$CN_DIR/$node_name"
305
  done
 
306
 
307
+ log_success "Custom nodes instalados"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
 
309
+ # Iniciar
310
+ log_info "========================================="
311
+ log_success "Instalação concluída!"
312
+ log_info "Iniciando ComfyUI..."
313
+ log_info "URL: http://localhost:$COMFY_PORT"
314
  log_info "========================================="
 
 
 
 
 
 
315
 
316
+ cd "$COMFY_DIR"
317
+
318
+ # Habilita SageAttention se presente
319
  SAGE_FLAG=""
320
+ if python3 -c 'import sageattention' >/dev/null 2>&1; then
 
 
321
  SAGE_FLAG="--use-sage-attention"
322
  fi
323
 
 
 
324
  exec comfy launch -- ${SAGE_FLAG:+$SAGE_FLAG} --listen "$COMFY_HOST" --port "$COMFY_PORT"