R1000 commited on
Commit
0d2ff04
·
verified ·
1 Parent(s): f9425a7

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +34 -41
start.sh CHANGED
@@ -2,18 +2,17 @@
2
  set -Eeuo pipefail
3
 
4
  COMFY="${COMFYUI_PATH:-/app/ComfyUI}"
 
5
 
6
  # ------------------------------------------------------------
7
  # Runtime directories
8
  # ------------------------------------------------------------
9
- # This is intentionally done before ComfyUI starts.
10
- # ComfyUI 0.35.x creates /app/ComfyUI/user itself.
11
  mkdir -p \
12
  "$COMFY/user" \
 
13
  "$COMFY/input" \
14
  "$COMFY/output" \
15
  "$COMFY/temp" \
16
- "$COMFY/workflows" \
17
  "$COMFY/models/unet" \
18
  "$COMFY/models/checkpoints" \
19
  "$COMFY/models/diffusion_models" \
@@ -21,24 +20,10 @@ mkdir -p \
21
  "$COMFY/models/text_encoders" \
22
  "$COMFY/models/vae"
23
 
24
- # ------------------------------------------------------------
25
- # ComfyUI Manager Security Setup
26
- # ------------------------------------------------------------
27
- MANAGER_CONFIG_DIR="$COMFY/user/default/ComfyUI-Manager"
28
- # mkdir -p "$MANAGER_CONFIG_DIR"
29
- # cat << 'EOF' > "$MANAGER_CONFIG_DIR/config.ini"
30
- # [ComfyUI-Manager]
31
- # security_level = weak
32
- # privacy_mode = false
33
- # EOF
34
- # echo "[INFO] ComfyUI Manager security level set to weak."
35
-
36
  # ------------------------------------------------------------
37
  # Persistent storage
38
  # ------------------------------------------------------------
39
  # If HF Storage is mounted at /data, models survive Space restarts.
40
- # Without persistent storage, downloaded models live in the container
41
- # filesystem and may have to be downloaded again after a rebuild/restart.
42
  PERSIST_ROOT="/data/comfyui"
43
 
44
  if [ -d "/data" ] && [ -w "/data" ]; then
@@ -52,13 +37,8 @@ MODEL_ROOT="$PERSIST_ROOT/models"
52
  # ------------------------------------------------------------
53
  # Model configuration
54
  # ------------------------------------------------------------
55
- # Define models to download.
56
  # Format: "repo_id|filename|dest_subdir"
57
- # dest_subdir should be one of: unet, text_encoders, vae, loras, controlnet, workflows, etc.
58
- #
59
- # You can override this list by setting the MODELS_TO_DOWNLOAD environment variable.
60
- # Example: export MODELS_TO_DOWNLOAD="repo1|file1|unet;repo2|file2|vae"
61
-
62
  if [ -n "${MODELS_TO_DOWNLOAD:-}" ]; then
63
  IFS=';' read -r -a MODEL_LIST <<< "$MODELS_TO_DOWNLOAD"
64
  else
@@ -83,17 +63,15 @@ else
83
 
84
  # Workflow
85
  "realrebelai/KREA-2_GGUFs|Rebels KREA-2-TURBO.json|workflows"
86
-
87
- # เพิ่มโมเดลอื่นๆ ได้ที่นี่ เช่น:
88
- # "some-repo/some-model|path/to/model.safetensors|loras"audio_encoders
89
  )
90
  fi
91
 
92
  # ------------------------------------------------------------
93
- # Model directory links
94
  # ------------------------------------------------------------
95
- # Only replace an empty ComfyUI model directory.
96
- # This avoids deleting any models supplied in the Space image.
97
  link_model_dir() {
98
  local name="$1"
99
  local target="$COMFY/models/$name"
@@ -119,8 +97,7 @@ link_model_dir() {
119
  fi
120
  }
121
 
122
- # Dynamically link model directories based on MODEL_LIST
123
- UNIQUE_SUBDIRS=$(printf "%s\n" "${MODEL_LIST[@]}" | awk -F'|' '$3 != "" {print $3}' | grep -v "^workflows$" | sort -u)
124
  for subdir in $UNIQUE_SUBDIRS; do
125
  link_model_dir "$subdir"
126
  done
@@ -178,25 +155,41 @@ print("[OK] downloaded:", dest)
178
  PY
179
  }
180
 
181
- # ------------------------------------------------------------
182
- # Download models
183
- # ------------------------------------------------------------
184
- if [ "${KREA2_DOWNLOAD_MODELS:-1}" = "1" ]; then
185
  for model_entry in "${MODEL_LIST[@]}"; do
186
  [ -z "$model_entry" ] && continue
187
  IFS='|' read -r repo file subdir <<< "$model_entry"
188
-
189
  if [ "$subdir" = "workflows" ]; then
190
- dest_dir="$COMFY/workflows"
191
  else
192
  dest_dir="$COMFY/models/$subdir"
193
  fi
194
-
195
  mkdir -p "$dest_dir"
196
  dest_path="$dest_dir/$(basename "$file")"
197
-
198
- download_hf "$repo" "$file" "$dest_path"
 
 
199
  done
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  else
201
  echo "[INFO] KREA2_DOWNLOAD_MODELS=0; model download skipped."
202
  fi
@@ -221,4 +214,4 @@ exec python -u main.py \
221
  --use-split-cross-attention \
222
  --listen 0.0.0.0 \
223
  --port "${PORT:-7860}" \
224
- --output-directory "$COMFY/output"
 
2
  set -Eeuo pipefail
3
 
4
  COMFY="${COMFYUI_PATH:-/app/ComfyUI}"
5
+ WORKFLOW_DIR="$COMFY/user/default/workflows"
6
 
7
  # ------------------------------------------------------------
8
  # Runtime directories
9
  # ------------------------------------------------------------
 
 
10
  mkdir -p \
11
  "$COMFY/user" \
12
+ "$WORKFLOW_DIR" \
13
  "$COMFY/input" \
14
  "$COMFY/output" \
15
  "$COMFY/temp" \
 
16
  "$COMFY/models/unet" \
17
  "$COMFY/models/checkpoints" \
18
  "$COMFY/models/diffusion_models" \
 
20
  "$COMFY/models/text_encoders" \
21
  "$COMFY/models/vae"
22
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  # ------------------------------------------------------------
24
  # Persistent storage
25
  # ------------------------------------------------------------
26
  # If HF Storage is mounted at /data, models survive Space restarts.
 
 
27
  PERSIST_ROOT="/data/comfyui"
28
 
29
  if [ -d "/data" ] && [ -w "/data" ]; then
 
37
  # ------------------------------------------------------------
38
  # Model configuration
39
  # ------------------------------------------------------------
 
40
  # Format: "repo_id|filename|dest_subdir"
41
+ # Override with: MODELS_TO_DOWNLOAD="repo1|file1|unet;repo2|file2|vae"
 
 
 
 
42
  if [ -n "${MODELS_TO_DOWNLOAD:-}" ]; then
43
  IFS=';' read -r -a MODEL_LIST <<< "$MODELS_TO_DOWNLOAD"
44
  else
 
63
 
64
  # Workflow
65
  "realrebelai/KREA-2_GGUFs|Rebels KREA-2-TURBO.json|workflows"
66
+
67
+ # Add more models here, e.g.:
68
+ # "some-repo/some-model|path/to/model.safetensors|loras"
69
  )
70
  fi
71
 
72
  # ------------------------------------------------------------
73
+ # Model directory links (only replaces EMPTY directories)
74
  # ------------------------------------------------------------
 
 
75
  link_model_dir() {
76
  local name="$1"
77
  local target="$COMFY/models/$name"
 
97
  fi
98
  }
99
 
100
+ UNIQUE_SUBDIRS=$(printf "%s\n" "${MODEL_LIST[@]}" | awk -F'|' '$3 != "" {print $3}' | grep -v "^workflows$" | sort -u || true)
 
101
  for subdir in $UNIQUE_SUBDIRS; do
102
  link_model_dir "$subdir"
103
  done
 
155
  PY
156
  }
157
 
158
+ download_all_models() {
 
 
 
159
  for model_entry in "${MODEL_LIST[@]}"; do
160
  [ -z "$model_entry" ] && continue
161
  IFS='|' read -r repo file subdir <<< "$model_entry"
162
+
163
  if [ "$subdir" = "workflows" ]; then
164
+ dest_dir="$WORKFLOW_DIR"
165
  else
166
  dest_dir="$COMFY/models/$subdir"
167
  fi
168
+
169
  mkdir -p "$dest_dir"
170
  dest_path="$dest_dir/$(basename "$file")"
171
+
172
+ # One failed download (wrong repo/filename, 404, no token) must NOT
173
+ # kill the container, so it only logs a warning and continues.
174
+ download_hf "$repo" "$file" "$dest_path" || echo "[WARN] FAILED: $repo :: $file"
175
  done
176
+ echo "[INFO] Model download finished. Press 'r' in ComfyUI to refresh node lists."
177
+ }
178
+
179
+ # ------------------------------------------------------------
180
+ # Download models
181
+ # ------------------------------------------------------------
182
+ # KREA2_DOWNLOAD_MODELS=0 -> skip downloads
183
+ # KREA2_DOWNLOAD_BACKGROUND=1 (def.) -> download in background so the web UI
184
+ # comes up right away (HF Spaces has a
185
+ # startup timeout). Set 0 to download first.
186
+ if [ "${KREA2_DOWNLOAD_MODELS:-1}" = "1" ]; then
187
+ if [ "${KREA2_DOWNLOAD_BACKGROUND:-1}" = "1" ]; then
188
+ echo "[INFO] Downloading models in the background..."
189
+ download_all_models &
190
+ else
191
+ download_all_models
192
+ fi
193
  else
194
  echo "[INFO] KREA2_DOWNLOAD_MODELS=0; model download skipped."
195
  fi
 
214
  --use-split-cross-attention \
215
  --listen 0.0.0.0 \
216
  --port "${PORT:-7860}" \
217
+ --output-directory "$COMFY/output"