File size: 7,732 Bytes
feab030
 
 
 
 
 
 
 
 
 
 
 
 
d69e4d0
 
 
 
 
 
 
 
 
 
 
feab030
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash

source /venv/main/bin/activate
FORGE_DIR=${WORKSPACE}/stable-diffusion-webui-forge

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

APT_PACKAGES=(
    #"package-1"
    #"package-2"
)

PIP_PACKAGES=(
)
EXTENSIONS=(
    "https://github.com/Bing-su/adetailer.git"
    "https://github.com/adieyal/sd-dynamic-prompts"
    "https://github.com/Koishi-Star/Euler-Smea-Dyn-Sampler.git"
    "https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git"
    "https://github.com/BlafKing/sd-civitai-browser-plus.git"
    "https://github.com/zanllp/sd-webui-infinite-image-browsing.git"
    "https://github.com/altoiddealer/--sd-webui-ar-plusplus"
    "https://github.com/Haoming02/sd-webui-tabs-extension.git"
    "https://github.com/Haoming02/sd-forge-couple.git"
)

CHECKPOINT_MODELS=(
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/aniversePonyXL_v60.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/autismmixSDXL_autismmixConfetti_256991.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/babes_12p5.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/beautifulGirls_v10.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/bemypony_Semirealanime.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/celestiquerealmixAtomix_v10.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/cyberrealisticPony_semiRealV36.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/incursiosMemeDiffusion_v27PDXL.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/magicalpony_3_628661.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/pimpmypony-v1-fp16-clip-fix.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/ponyDiffusionV6XL_v6StartWithThisOne_228616.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/ponyRealism_V23ULTRA.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/prefectPonyXL_v50.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/snowpony_v10.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/ckpt/waiANINSFWPONYXL_v140.safetensors"
)

UNET_MODELS=(

)

LORA_MODELS=(
    "https://huggingface.co/huchukato/favs/resolve/main/loras/nsfw/Expressive_H-000001.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/loras/nsfw/incase_style_v3-1_ponyxl_ilff_356767.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/loras/pony/S1_Dramatic_Lighting_v3_1184559.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/loras/pony/d3t41l3dXLP_404816.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/loras/pony/43stl1ght1ngXLP2_348038.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/loras/pony/V3n3t14nXLP2_404377.safetensors"             
)

VAE_MODELS=(
    #"https://huggingface.co/stabilityai/sd-vae-ft-ema-original/resolve/main/vae-ft-ema-560000-ema-pruned.safetensors"
    "https://huggingface.co/huchukato/favs/resolve/main/VAE/ponyStandardVAE_v10.safetensors"
    "https://huggingface.co/stabilityai/sdxl-vae/resolve/main/sdxl_vae.safetensors"
)

ESRGAN_MODELS=(
    "https://huggingface.co/ai-forever/Real-ESRGAN/resolve/main/RealESRGAN_x4.pth"
    "https://huggingface.co/FacehugmanIII/4x_foolhardy_Remacri/resolve/main/4x_foolhardy_Remacri.pth"
    "https://huggingface.co/Akumetsu971/SD_Anime_Futuristic_Armor/resolve/main/4x_NMKD-Siax_200k.pth"
)

CONTROLNET_MODELS=(
)

### DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ###

function provisioning_start() {
    provisioning_print_header
    provisioning_get_apt_packages
    provisioning_get_extensions
    provisioning_get_pip_packages
    provisioning_get_files \
        "${FORGE_DIR}/models/Stable-diffusion" \
        "${CHECKPOINT_MODELS[@]}"

    # Avoid git errors because we run as root but files are owned by 'user'
    export GIT_CONFIG_GLOBAL=/tmp/temporary-git-config
    git config --file $GIT_CONFIG_GLOBAL --add safe.directory '*'
    
    # Start and exit because webui will probably require a restart
    cd "${FORGE_DIR}"
    LD_PRELOAD=libtcmalloc_minimal.so.4 \
        python launch.py \
            --skip-python-version-check \
            --no-download-sd-model \
            --do-not-download-clip \
            --no-half \
            --port 11404 \
            --exit

    provisioning_print_end
}

function provisioning_get_apt_packages() {
    if [[ -n $APT_PACKAGES ]]; then
            sudo $APT_INSTALL ${APT_PACKAGES[@]}
    fi
}

function provisioning_get_pip_packages() {
    if [[ -n $PIP_PACKAGES ]]; then
            pip install --no-cache-dir ${PIP_PACKAGES[@]}
    fi
}

function provisioning_get_extensions() {
    for repo in "${EXTENSIONS[@]}"; do
        dir="${repo##*/}"
        path="${FORGE_DIR}/extensions/${dir}"
        if [[ ! -d $path ]]; then
            printf "Downloading extension: %s...\n" "${repo}"
            git clone "${repo}" "${path}" --recursive
        fi
    done
}

function provisioning_get_files() {
    if [[ -z $2 ]]; then return 1; fi
    
    dir="$1"
    mkdir -p "$dir"
    shift
    arr=("$@")
    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"
}

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

function provisioning_has_valid_hf_token() {
    [[ -n "$HF_TOKEN" ]] || return 1
    url="https://huggingface.co/api/whoami-v2"

    response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
        -H "Authorization: Bearer $HF_TOKEN" \
        -H "Content-Type: application/json")

    # Check if the token is valid
    if [ "$response" -eq 200 ]; then
        return 0
    else
        return 1
    fi
}

function provisioning_has_valid_civitai_token() {
    [[ -n "$CIVITAI_TOKEN" ]] || return 1
    url="https://civitai.com/api/v1/models?hidden=1&limit=1"

    response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
        -H "Authorization: Bearer $CIVITAI_TOKEN" \
        -H "Content-Type: application/json")

    # Check if the token is valid
    if [ "$response" -eq 200 ]; then
        return 0
    else
        return 1
    fi
}

# Download from $1 URL to $2 file path
function provisioning_download() {
    if [[ -n $HF_TOKEN && $1 =~ ^https://([a-zA-Z0-9_-]+\.)?huggingface\.co(/|$|\?) ]]; then
        auth_token="$HF_TOKEN"
    elif 
        [[ -n $CIVITAI_TOKEN && $1 =~ ^https://([a-zA-Z0-9_-]+\.)?civitai\.com(/|$|\?) ]]; then
        auth_token="$CIVITAI_TOKEN"
    fi
    if [[ -n $auth_token ]];then
        wget --header="Authorization: Bearer $auth_token" -qnc --content-disposition --show-progress -e dotbytes="${3:-4M}" -P "$2" "$1"
    else
        wget -qnc --content-disposition --show-progress -e dotbytes="${3:-4M}" -P "$2" "$1"
    fi
}

# Allow user to disable provisioning if they started with a script they didn't want
if [[ ! -f /.noprovisioning ]]; then
    provisioning_start
fi