YaroslavLinder commited on
Commit
223480b
·
verified ·
1 Parent(s): 6d26d67

Upload flux_new.sh

Browse files
Files changed (1) hide show
  1. flux_new.sh +237 -0
flux_new.sh ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #"package-1"
15
+ #"package-2"
16
+ )
17
+
18
+ NODES=(
19
+ "https://github.com/Fannovel16/comfyui_controlnet_aux"
20
+ "https://github.com/cubiq/ComfyUI_essentials"
21
+ "https://github.com/lldacing/ComfyUI_PuLID_Flux_ll"
22
+ "https://github.com/Derfuu/Derfuu_ComfyUI_ModdedNodes"
23
+ "https://github.com/Shakker-Labs/ComfyUI-IPAdapter-Flux"
24
+ )
25
+
26
+ WORKFLOWS=(
27
+ "https://gist.githubusercontent.com/robballantyne/f8cb692bdcd89c96c0bd1ec0c969d905/raw/2d969f732d7873f0e1ee23b2625b50f201c722a5/flux_dev_example.json"
28
+ )
29
+
30
+ STYLE_MODELS=(
31
+ "https://huggingface.co/black-forest-labs/FLUX.1-Redux-dev/resolve/main/flux1-redux-dev.safetensors"
32
+ )
33
+
34
+ CLIP_VISION_MODELS=(
35
+ #"https://huggingface.co/google/siglip-so400m-patch14-384/resolve/main/model.safetensors"
36
+ )
37
+
38
+ CLIP_MODELS=(
39
+ #"https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/clip_l.safetensors"
40
+ #"https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/t5xxl_fp16.safetensors"
41
+ )
42
+
43
+ UNET_MODELS=(
44
+ )
45
+
46
+ VAE_MODELS=(
47
+ )
48
+
49
+ LORA_MODELS=(
50
+ "https://huggingface.co/YaroslavLinder/ISKA/resolve/main/iska.safetensors"
51
+ "https://huggingface.co/YaroslavLinder/Lucy/resolve/main/lucy-model.safetensors"
52
+ "https://huggingface.co/enhanceaiteam/Flux-Uncensored-V2/resolve/main/lora.safetensors"
53
+ )
54
+
55
+ ESRGAN_MODELS=(
56
+ "https://huggingface.co/ai-forever/Real-ESRGAN/resolve/main/RealESRGAN_x2.pth"
57
+ "https://huggingface.co/ai-forever/Real-ESRGAN/resolve/main/RealESRGAN_x4.pth"
58
+ "https://huggingface.co/FacehugmanIII/4x_foolhardy_Remacri/resolve/main/4x_foolhardy_Remacri.pth"
59
+ "https://huggingface.co/Akumetsu971/SD_Anime_Futuristic_Armor/resolve/main/4x_NMKD-Siax_200k.pth"
60
+ )
61
+
62
+ CONTROLNET_MODELS=(
63
+ "https://huggingface.co/Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro/resolve/main/diffusion_pytorch_model.safetensors"
64
+ )
65
+
66
+ PULID_MODELS=(
67
+ "https://huggingface.co/guozinan/PuLID/resolve/main/pulid_flux_v0.9.1.safetensors"
68
+ )
69
+
70
+ FLUX_IPADAPTER_MODELS=(
71
+ #"https://huggingface.co/InstantX/FLUX.1-dev-IP-Adapter/resolve/main/ip-adapter.bin"
72
+ )
73
+
74
+
75
+ ### DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ###
76
+
77
+ function provisioning_start() {
78
+ provisioning_print_header
79
+ provisioning_get_apt_packages
80
+ provisioning_get_nodes
81
+ provisioning_get_pip_packages
82
+ workflows_dir="${COMFYUI_DIR}/user/default/workflows"
83
+ mkdir -p "${workflows_dir}"
84
+ provisioning_get_files \
85
+ "${workflows_dir}" \
86
+ "${WORKFLOWS[@]}"
87
+ # Get licensed models if HF_TOKEN set & valid
88
+ if provisioning_has_valid_hf_token; then
89
+ UNET_MODELS+=("https://huggingface.co/Comfy-Org/flux1-dev/resolve/main/flux1-dev-fp8.safetensors")
90
+ VAE_MODELS+=("https://huggingface.co/black-forest-labs/FLUX.1-dev/resolve/main/ae.safetensors")
91
+ else
92
+ UNET_MODELS+=("https://huggingface.co/black-forest-labs/FLUX.1-schnell/resolve/main/flux1-schnell.safetensors")
93
+ VAE_MODELS+=("https://huggingface.co/black-forest-labs/FLUX.1-schnell/resolve/main/ae.safetensors")
94
+ sed -i 's/flux1-dev\.safetensors/flux1-schnell.safetensors/g' "${workflows_dir}/flux_dev_example.json"
95
+ fi
96
+ provisioning_get_files \
97
+ "${COMFYUI_DIR}/models/checkpoints" \
98
+ "${UNET_MODELS[@]}"
99
+ provisioning_get_files \
100
+ "${COMFYUI_DIR}/models/vae" \
101
+ "${VAE_MODELS[@]}"
102
+ provisioning_get_files \
103
+ "${COMFYUI_DIR}/models/clip" \
104
+ "${CLIP_MODELS[@]}"
105
+ provisioning_get_files \
106
+ "${COMFYUI_DIR}/models/pulid" \
107
+ "${PULID_MODELS[@]}"
108
+ provisioning_get_files \
109
+ "${COMFYUI_DIR}/models/clip_vision" \
110
+ "${CLIP_VISION_MODELS[@]}"
111
+ provisioning_get_files \
112
+ "${COMFYUI_DIR}/models/style_models" \
113
+ "${STYLE_MODELS[@]}"
114
+ provisioning_get_files \
115
+ "${COMFYUI_DIR}/models/controlnet" \
116
+ "${CONTROLNET_MODELS[@]}"
117
+ provisioning_get_files \
118
+ "${COMFYUI_DIR}/models/upscale_models" \
119
+ "${ESRGAN_MODELS[@]}"
120
+ provisioning_get_files \
121
+ "${COMFYUI_DIR}/models/loras" \
122
+ "${LORA_MODELS[@]}"
123
+ provisioning_get_files \
124
+ "${COMFYUI_DIR}/models/ipadapter-flux" \
125
+ "${FLUX_IPADAPTER_MODELS[@]}"
126
+ provisioning_print_end
127
+ }
128
+
129
+ function provisioning_get_apt_packages() {
130
+ if [[ -n $APT_PACKAGES ]]; then
131
+ sudo $APT_INSTALL ${APT_PACKAGES[@]}
132
+ fi
133
+ }
134
+
135
+ function provisioning_get_pip_packages() {
136
+ if [[ -n $PIP_PACKAGES ]]; then
137
+ pip install --no-cache-dir ${PIP_PACKAGES[@]}
138
+ fi
139
+ }
140
+
141
+ function provisioning_get_nodes() {
142
+ for repo in "${NODES[@]}"; do
143
+ dir="${repo##*/}"
144
+ path="${COMFYUI_DIR}/custom_nodes/${dir}"
145
+ requirements="${path}/requirements.txt"
146
+ if [[ -d $path ]]; then
147
+ if [[ ${AUTO_UPDATE,,} != "false" ]]; then
148
+ printf "Updating node: %s...\n" "${repo}"
149
+ ( cd "$path" && git pull )
150
+ if [[ -e $requirements ]]; then
151
+ pip install --no-cache-dir -r "$requirements"
152
+ fi
153
+ fi
154
+ else
155
+ printf "Downloading node: %s...\n" "${repo}"
156
+ git clone "${repo}" "${path}" --recursive
157
+ if [[ -e $requirements ]]; then
158
+ pip install --no-cache-dir -r "${requirements}"
159
+ fi
160
+ fi
161
+ done
162
+ }
163
+
164
+ function provisioning_get_files() {
165
+ if [[ -z $2 ]]; then return 1; fi
166
+
167
+ dir="$1"
168
+ mkdir -p "$dir"
169
+ shift
170
+ arr=("$@")
171
+ printf "Downloading %s model(s) to %s...\n" "${#arr[@]}" "$dir"
172
+ for url in "${arr[@]}"; do
173
+ printf "Downloading: %s\n" "${url}"
174
+ provisioning_download "${url}" "${dir}"
175
+ printf "\n"
176
+ done
177
+ }
178
+
179
+ function provisioning_print_header() {
180
+ 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"
181
+ }
182
+
183
+ function provisioning_print_end() {
184
+ printf "\nProvisioning complete: Application will start now\n\n"
185
+ }
186
+
187
+ function provisioning_has_valid_hf_token() {
188
+ [[ -n "$HF_TOKEN" ]] || return 1
189
+ url="https://huggingface.co/api/whoami-v2"
190
+
191
+ response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
192
+ -H "Authorization: Bearer $HF_TOKEN" \
193
+ -H "Content-Type: application/json")
194
+
195
+ # Check if the token is valid
196
+ if [ "$response" -eq 200 ]; then
197
+ return 0
198
+ else
199
+ return 1
200
+ fi
201
+ }
202
+
203
+ function provisioning_has_valid_civitai_token() {
204
+ [[ -n "$CIVITAI_TOKEN" ]] || return 1
205
+ url="https://civitai.com/api/v1/models?hidden=1&limit=1"
206
+
207
+ response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
208
+ -H "Authorization: Bearer $CIVITAI_TOKEN" \
209
+ -H "Content-Type: application/json")
210
+
211
+ # Check if the token is valid
212
+ if [ "$response" -eq 200 ]; then
213
+ return 0
214
+ else
215
+ return 1
216
+ fi
217
+ }
218
+
219
+ # Download from $1 URL to $2 file path
220
+ function provisioning_download() {
221
+ if [[ -n $HF_TOKEN && $1 =~ ^https://([a-zA-Z0-9_-]+\.)?huggingface\.co(/|$|\?) ]]; then
222
+ auth_token="$HF_TOKEN"
223
+ elif
224
+ [[ -n $CIVITAI_TOKEN && $1 =~ ^https://([a-zA-Z0-9_-]+\.)?civitai\.com(/|$|\?) ]]; then
225
+ auth_token="$CIVITAI_TOKEN"
226
+ fi
227
+ if [[ -n $auth_token ]];then
228
+ wget --header="Authorization: Bearer $auth_token" -qnc --content-disposition --show-progress -e dotbytes="${3:-4M}" -P "$2" "$1"
229
+ else
230
+ wget -qnc --content-disposition --show-progress -e dotbytes="${3:-4M}" -P "$2" "$1"
231
+ fi
232
+ }
233
+
234
+ # Allow user to disable provisioning if they started with a script they didn't want
235
+ if [[ ! -f /.noprovisioning ]]; then
236
+ provisioning_start
237
+ fi