mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
174 lines
5.2 KiB
Bash
174 lines
5.2 KiB
Bash
#!/bin/bash
|
|
|
|
# MIT License
|
|
|
|
# Coauthored by Lincoln Stein, Eugene Brodsky and Joshua Kimsey
|
|
# Copyright 2023, The InvokeAI Development Team
|
|
|
|
####
|
|
# This launch script assumes that:
|
|
# 1. it is located in the runtime directory,
|
|
# 2. the .venv is also located in the runtime directory and is named exactly that
|
|
#
|
|
# If both of the above are not true, this script will likely not work as intended.
|
|
# Activate the virtual environment and run `invoke.py` directly.
|
|
####
|
|
|
|
set -eu
|
|
|
|
# Ensure we're in the correct folder in case user's CWD is somewhere else
|
|
scriptdir=$(dirname "$0")
|
|
cd "$scriptdir"
|
|
|
|
. .venv/bin/activate
|
|
|
|
export INVOKEAI_ROOT="$scriptdir"
|
|
PARAMS=$@
|
|
|
|
# Check to see if dialog is installed (it seems to be fairly standard, but good to check regardless) and if the user has passed the --no-tui argument to disable the dialog TUI
|
|
tui=true
|
|
if command -v dialog &>/dev/null; then
|
|
# This must use $@ to properly loop through the arguments passed by the user
|
|
for arg in "$@"; do
|
|
if [ "$arg" == "--no-tui" ]; then
|
|
tui=false
|
|
# Remove the --no-tui argument to avoid errors later on when passing arguments to InvokeAI
|
|
PARAMS=$(echo "$PARAMS" | sed 's/--no-tui//')
|
|
break
|
|
fi
|
|
done
|
|
else
|
|
tui=false
|
|
fi
|
|
|
|
# Set required env var for torch on mac MPS
|
|
if [ "$(uname -s)" == "Darwin" ]; then
|
|
export PYTORCH_ENABLE_MPS_FALLBACK=1
|
|
fi
|
|
|
|
# Avoid glibc memory fragmentation. See #6007, #4784 and docs/features/CONFIGURATION.md for details.
|
|
# Some systems may need this to be set to a different value, so we may override this via command-line argument below.
|
|
export MALLOC_MMAP_THRESHOLD_=1048576 # 1MB
|
|
|
|
# This will be passed on to `invokeai-web`
|
|
PARAMS=()
|
|
|
|
# Parse command-line arguments
|
|
for arg in "$@"; do
|
|
if [[ $arg == --malloc_threshold=* ]]; then
|
|
# Re-set MALLOC_MMAP_THRESHOLD_ from the argument if provided
|
|
value="${arg#*=}"
|
|
if [[ $value == "unset" ]]; then
|
|
unset MALLOC_MMAP_THRESHOLD_
|
|
elif [[ $value =~ ^[0-9]+$ ]]; then
|
|
export MALLOC_MMAP_THRESHOLD_="$value"
|
|
else
|
|
echo "Invalid value for --malloc_threshold. Please provide a valid positive integer or 'unset'."
|
|
exit 1
|
|
fi
|
|
else
|
|
# Add other arguments to PARAMS
|
|
PARAMS+=("$arg")
|
|
fi
|
|
done
|
|
|
|
# Primary function for the case statement to determine user input
|
|
do_choice() {
|
|
case $1 in
|
|
1)
|
|
clear
|
|
printf "Generate images with a browser-based interface\n"
|
|
invokeai-web "${PARAMS[@]}"
|
|
;;
|
|
2)
|
|
clear
|
|
printf "Open the developer console\n"
|
|
file_name=$(basename "${BASH_SOURCE[0]}")
|
|
bash --init-file "$file_name"
|
|
;;
|
|
3)
|
|
clear
|
|
printf "UPDATING FROM WITHIN THE APP IS BEING DEPRECATED\n"
|
|
printf "Please download the installer from https://github.com/invoke-ai/InvokeAI/releases/latest and run it to update your installation.\n"
|
|
sleep 4
|
|
python -m invokeai.frontend.install.invokeai_update
|
|
;;
|
|
4)
|
|
clear
|
|
printf "Running the db maintenance script\n"
|
|
invokeai-db-maintenance --root ${INVOKEAI_ROOT}
|
|
;;
|
|
5)
|
|
clear
|
|
printf "Command-line help\n"
|
|
invokeai-web --help
|
|
;;
|
|
*)
|
|
clear
|
|
printf "Exiting...\n"
|
|
exit
|
|
;;
|
|
esac
|
|
clear
|
|
}
|
|
|
|
# Dialog-based TUI for launcing Invoke functions
|
|
do_dialog() {
|
|
options=(
|
|
1 "Generate images with a browser-based interface"
|
|
2 "Open the developer console"
|
|
3 "Update InvokeAI (DEPRECATED - please use the installer)"
|
|
4 "Run the InvokeAI image database maintenance script"
|
|
5 "Command-line help"
|
|
)
|
|
|
|
choice=$(dialog --clear \
|
|
--backtitle "\Zb\Zu\Z3InvokeAI" \
|
|
--colors \
|
|
--title "What would you like to do?" \
|
|
--ok-label "Run" \
|
|
--cancel-label "Exit" \
|
|
--help-button \
|
|
--help-label "CLI Help" \
|
|
--menu "Select an option:" \
|
|
0 0 0 \
|
|
"${options[@]}" \
|
|
2>&1 >/dev/tty) || clear
|
|
do_choice "$choice"
|
|
clear
|
|
}
|
|
|
|
# Command-line interface for launching Invoke functions
|
|
do_line_input() {
|
|
clear
|
|
printf " ** For a more attractive experience, please install the 'dialog' utility using your package manager. **\n\n"
|
|
printf "What would you like to do?\n"
|
|
printf "1: Generate images using the browser-based interface\n"
|
|
printf "2: Open the developer console\n"
|
|
printf "3: Update InvokeAI\n"
|
|
printf "4: Run the InvokeAI image database maintenance script\n"
|
|
printf "5: Command-line help\n"
|
|
printf "Q: Quit\n\n"
|
|
read -p "Please enter 1-10, Q: [1] " yn
|
|
choice=${yn:='1'}
|
|
do_choice $choice
|
|
clear
|
|
}
|
|
|
|
# Main IF statement for launching Invoke with either the TUI or CLI, and for checking if the user is in the developer console
|
|
if [ "$0" != "bash" ]; then
|
|
while true; do
|
|
if $tui; then
|
|
# .dialogrc must be located in the same directory as the invoke.sh script
|
|
export DIALOGRC="./.dialogrc"
|
|
do_dialog
|
|
else
|
|
do_line_input
|
|
fi
|
|
done
|
|
else # in developer console
|
|
python --version
|
|
printf "Press ^D to exit\n"
|
|
export PS1="(InvokeAI) \u@\h \w> "
|
|
fi
|