File size: 8,288 Bytes
ec17b8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash

# This file will be sourced in init.sh

# https://raw.githubusercontent.com/ai-dock/comfyui/main/config/provisioning/default.sh

# Packages are installed after nodes so we can fix them...

PYTHON_PACKAGES=(
    #"opencv-python==4.7.0.72"
)

NODES=(
    "https://github.com/ltdrdata/ComfyUI-Manager"
    "https://github.com/WASasquatch/was-node-suite-comfyui"
    "https://github.com/cubiq/ComfyUI_essentials"
    "https://github.com/ltdrdata/ComfyUI-Impact-Pack"
    "https://github.com/Fannovel16/comfyui_controlnet_aux"
    "https://github.com/Gourieff/comfyui-reactor-node"
    "https://github.com/cubiq/ComfyUI_InstantID"
    "https://github.com/cubiq/ComfyUI_IPAdapter_plus"
)

CHECKPOINT_MODELS=(
    "https://huggingface.co/Lykon/dreamshaper-xl-lightning/resolve/main/DreamShaperXL_Lightning.safetensors"
)

LORA_MODELS=(
)

VAE_MODELS=(
)

ESRGAN_MODELS=(
)

CONTROLNET_MODELS=(
    "https://huggingface.co/InstantX/InstantID/resolve/main/ControlNetModel/diffusion_pytorch_model.safetensors"
    "https://huggingface.co/Kuvshin/models/resolve/main/pose_sdxl.safetensors"
)

INSIGHTFACE=(
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/insightface/inswapper_128.onnx"
)

BUFALO=(
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/insightface/models/buffalo_l/1k3d68.onnx"
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/insightface/models/buffalo_l/2d106det.onnx"
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/insightface/models/buffalo_l/det_10g.onnx"
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/insightface/models/buffalo_l/genderage.onnx"
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/insightface/models/buffalo_l/w600k_r50.onnx"
)

ANTELOPEV=(
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/insightface/models/antelopev2/1k3d68.onnx"
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/insightface/models/antelopev2/2d106det.onnx"
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/insightface/models/antelopev2/genderage.onnx"
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/insightface/models/antelopev2/glintr100.onnx"
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/insightface/models/antelopev2/scrfd_10g_bnkps.onnx"
)

BBOX=(
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/ultralytics/bbox/face_yolov8m.pt"
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/ultralytics/bbox/hand_yolov8s.pt"
)

SEGM=(
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/ultralytics/segm/person_yolov8m-seg.pt"
)

SAMS=(
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/sam_vit_b_01ec64.pth"
)

CLIP=(
    "https://huggingface.co/Kuvshin/models/resolve/main/CLIP-ViT-H-14-laion2B-s32B-b79K.safetensors"
)

FACEDETECTION=(
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/detection_Resnet50_Final.pth"
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/parsing_parsenet.pth"
)

FACERESTORE=(
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/GFPGANv1.3.pth"
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/GFPGANv1.4.pth"
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/GPEN-BFR-512.onnx"
    "https://huggingface.co/Kuvshin/kuvshin8/resolve/main/codeformer-v0.1.0.pth"
)

INSTANTID=(
    "https://huggingface.co/InstantX/InstantID/resolve/main/ip-adapter.bin"
)
### DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ###

function provisioning_start() {
    DISK_GB_AVAILABLE=$(($(df --output=avail -m "${WORKSPACE}" | tail -n1) / 1000))
    DISK_GB_USED=$(($(df --output=used -m "${WORKSPACE}" | tail -n1) / 1000))
    DISK_GB_ALLOCATED=$(($DISK_GB_AVAILABLE + $DISK_GB_USED))
    provisioning_print_header
    provisioning_get_nodes
    provisioning_install_python_packages
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/ckpt" \
        "${CHECKPOINT_MODELS[@]}"
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/lora" \
        "${LORA_MODELS[@]}"
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/controlnet" \
        "${CONTROLNET_MODELS[@]}"
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/vae" \
        "${VAE_MODELS[@]}"
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/esrgan" \
        "${ESRGAN_MODELS[@]}"
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/insightface" \
        "${INSIGHTFACE[@]}"
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/insightface/models/buffalo_l" \
        "${BUFALO[@]}"
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/insightface/models/antelopev2" \
        "${ANTELOPEV[@]}"
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/ultralytics/bbox" \
        "${BBOX[@]}"
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/ultralytics/segm" \
        "${SEGM[@]}"
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/sams" \
        "${SAMS[@]}"
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/clip_vision" \
        "${CLIP[@]}"
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/facedetection" \
        "${FACEDETECTION[@]}"
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/facerestore_models" \
        "${FACERESTORE[@]}"
    provisioning_get_models \
        "${WORKSPACE}/storage/stable_diffusion/models/instantid" \
        "${INSTANTID[@]}"
    provisioning_print_end
}

function provisioning_get_nodes() {
    for repo in "${NODES[@]}"; do
        dir="${repo##*/}"
        path="/opt/ComfyUI/custom_nodes/${dir}"
        requirements="${path}/requirements.txt"
        if [[ -d $path ]]; then
            if [[ ${AUTO_UPDATE,,} != "false" ]]; then
                printf "Updating node: %s...\n" "${repo}"
                ( cd "$path" && git pull )
                if [[ -e $requirements ]]; then
                    micromamba -n comfyui run ${PIP_INSTALL} -r "$requirements"
                fi
            fi
        else
            printf "Downloading node: %s...\n" "${repo}"
            git clone "${repo}" "${path}" --recursive
            if [[ -e $requirements ]]; then
                micromamba -n comfyui run ${PIP_INSTALL} -r "${requirements}"
            fi
        fi
    done
}

function provisioning_install_python_packages() {
    if [ ${#PYTHON_PACKAGES[@]} -gt 0 ]; then
        micromamba -n comfyui run ${PIP_INSTALL} ${PYTHON_PACKAGES[*]}
    fi
}

function provisioning_get_models() {
    if [[ -z $2 ]]; then return 1; fi
    dir="$1"
    mkdir -p "$dir"
    shift
    if [[ $DISK_GB_ALLOCATED -ge $DISK_GB_REQUIRED ]]; then
        arr=("$@")
    else
        printf "WARNING: Low disk space allocation - Only the first model will be downloaded!\n"
        arr=("$1")
    fi
    
    printf "Downloading %s model(s) to %s...\n" "${#arr[@]}" "$dir"
    for url in "${arr[@]}"; do
        printf "Downloading: %s\n" "${url}"
        provisioning_download "${url}" "${dir}"
        printf "\n"
    done
}

function provisioning_print_header() {
    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"
    if [[ $DISK_GB_ALLOCATED -lt $DISK_GB_REQUIRED ]]; then
        printf "WARNING: Your allocated disk size (%sGB) is below the recommended %sGB - Some models will not be downloaded\n" "$DISK_GB_ALLOCATED" "$DISK_GB_REQUIRED"
    fi
}

function provisioning_print_end() {
    printf "\nProvisioning complete:  Web UI will start now\n\n"
}

# Download from $1 URL to $2 file path
function provisioning_download() {
    wget -qnc --content-disposition --show-progress -e dotbytes="${3:-4M}" -P "$2" "$1"
}

provisioning_start