Skip to content

Instantly share code, notes, and snippets.

@twinnedAI
Last active July 30, 2024 07:20
Show Gist options
  • Save twinnedAI/98a1acfe548c649a643def2317ac7e05 to your computer and use it in GitHub Desktop.
Save twinnedAI/98a1acfe548c649a643def2317ac7e05 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This file will be sourced in init.sh
# Namespace functions with provisioning_
# https://raw.githubusercontent.com/ai-dock/fooocus/main/config/provisioning/default.sh
### Edit the following arrays to suit your workflow - values must be quoted and separated by newlines or spaces.
DISK_GB_REQUIRED=30
DEFAULT_TOKEN="123456789"
PIP_PACKAGES=(
)
CHECKPOINT_MODELS=(
"https://civitai.com/api/download/models/672019?type=Model&format=SafeTensor&token=${CIVIT_AI_TOKEN:-$DEFAULT_TOKEN}"
"https://civitai.com/api/download/models/594400?type=Model&format=SafeTensor&token=${CIVIT_AI_TOKEN:-$DEFAULT_TOKEN}"
#"https://civitai.com/api/download/models/646523?type=Model&format=SafeTensor&token=${CIVIT_AI_TOKEN:-$DEFAULT_TOKEN}"
#"https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.ckpt"
#"https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.ckpt"
#"https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors"
#"https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors"
)
LORA_MODELS=(
"https://civitai.com/api/download/models/539032?type=Model&format=SafeTensor&token=${CIVIT_AI_TOKEN:-$DEFAULT_TOKEN}"
#"https://civitai.com/api/download/models/16576"
)
### DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ###
function provisioning_start() {
source /opt/ai-dock/etc/environment.sh
source /opt/ai-dock/bin/venv-set.sh fooocus
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_pip_packages
provisioning_get_models \
"${WORKSPACE}/storage/stable_diffusion/models/ckpt" \
"${CHECKPOINT_MODELS[@]}"
provisioning_get_models \
"${WORKSPACE}/storage/stable_diffusion/models/lora" \
"${LORA_MODELS[@]}"
provisioning_print_end
}
function provisioning_get_pip_packages() {
if [[ -n $PIP_PACKAGES ]]; then
"$FOOOCUS_VENV_PIP" install --no-cache-dir ${PIP_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: Fooocus will start now\n\n"
}
# Download from $1 URL to $2 file path
function provisioning_download() {
printf "START: Download model into %s\n" "$2"
wget -qnc --content-disposition --show-progress -e dotbytes=1000M -P "$2" "$1"
printf "END: Download model into %s\n" "$2"
}
provisioning_start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment