From d9f2e1e2529d290c8401a7e3634da1c1f8064bef Mon Sep 17 00:00:00 2001 From: Haoming <73768377+Haoming02@users.noreply.github.com> Date: Sun, 29 Mar 2026 20:51:24 +0700 Subject: [PATCH] unix --- webui-user.sh | 13 +++++++ webui.sh | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 webui-user.sh create mode 100644 webui.sh diff --git a/webui-user.sh b/webui-user.sh new file mode 100644 index 00000000..7a2b3e19 --- /dev/null +++ b/webui-user.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# export PYTHON= +# export GIT= +# export VENV_DIR= + +export TORCH_COMMAND="pip install torch==2.10.0 torchvision==0.25.0" + +export COMMANDLINE_ARGS="--uv" + +# --skip-python-version-check --skip-torch-cuda-test --skip-version-check --skip-prepare-environment --skip-install + +exec "$(dirname "$0")/webui.sh" diff --git a/webui.sh b/webui.sh new file mode 100644 index 00000000..881d8113 --- /dev/null +++ b/webui.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash + +set -e + +# Load optional settings +if [ -f "webui.settings.sh" ]; then + source webui.settings.sh +fi + +# Defaults +PYTHON="${PYTHON:-python3}" +VENV_DIR="${VENV_DIR:-$(cd "$(dirname "$0")" && pwd)/venv}" +SD_WEBUI_RESTART="tmp/restart" +ERROR_REPORTING="FALSE" + +mkdir -p tmp + +# Check python +if uv help python >tmp/stdout.txt 2>tmp/stderr.txt; then + : +elif "$PYTHON" -c "" >tmp/stdout.txt 2>tmp/stderr.txt; then + : +else + echo "Couldn't launch python" + goto_show_logs=1 +fi + +# Check pip +if [ -z "$goto_show_logs" ]; then + if uv help pip >tmp/stdout.txt 2>tmp/stderr.txt; then + : + elif "$PYTHON" -m pip --help >tmp/stdout.txt 2>tmp/stderr.txt; then + : + else + echo "Couldn't launch pip" + goto_show_logs=1 + fi +fi + +# Venv handling +if [ -z "$goto_show_logs" ]; then + if [ "$VENV_DIR" = "-" ] || [ "$SKIP_VENV" = "1" ]; then + : + else + if [ -x "$VENV_DIR/bin/python" ]; then + : + else + PYTHON_FULLNAME=$("$PYTHON" -c "import sys; print(sys.executable)") + echo "Creating venv in directory $VENV_DIR using python $PYTHON_FULLNAME" + + "$PYTHON_FULLNAME" -m venv "$VENV_DIR" >tmp/stdout.txt 2>tmp/stderr.txt || { + echo "Unable to create venv in directory \"$VENV_DIR\"" + goto_show_logs=1 + } + fi + + if [ -z "$goto_show_logs" ]; then + "$VENV_DIR/bin/python" -m pip install --upgrade pip || \ + echo "Warning: Failed to upgrade PIP version" + + # Activate venv + # shellcheck disable=SC1091 + source "$VENV_DIR/bin/activate" + PYTHON="$VENV_DIR/bin/python" + echo "venv $PYTHON" + fi + fi +fi + +# Launch +if [ -z "$goto_show_logs" ]; then + "$PYTHON" launch.py "$@" + + if [ -f "$SD_WEBUI_RESTART" ]; then + exec "$0" "$@" + fi + + exit 0 +fi + +# Show logs +echo +echo "exit code: $?" + +if [ -s tmp/stdout.txt ]; then + echo + echo "stdout:" + cat tmp/stdout.txt +fi + +if [ -s tmp/stderr.txt ]; then + echo + echo "stderr:" + cat tmp/stderr.txt +fi + +echo +echo "Launch Unsuccessful! Exiting..." +exit 1