2023-12-26 21:11:16 +08:00
|
|
|
#!/bin/sh
|
2023-07-13 15:05:35 +08:00
|
|
|
|
2023-12-26 21:11:16 +08:00
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
2023-07-13 15:05:35 +08:00
|
|
|
# macOS specific env:
|
|
|
|
export PYTORCH_ENABLE_MPS_FALLBACK=1
|
|
|
|
export PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0
|
2023-12-26 21:11:16 +08:00
|
|
|
elif [ "$(uname)" != "Linux" ]; then
|
2023-07-13 15:05:35 +08:00
|
|
|
echo "Unsupported operating system."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-08-27 01:21:18 +08:00
|
|
|
if [ -d ".venv" ]; then
|
|
|
|
echo "Activate venv..."
|
2023-12-26 21:11:16 +08:00
|
|
|
. .venv/bin/activate
|
2023-08-27 01:21:18 +08:00
|
|
|
else
|
|
|
|
echo "Create venv..."
|
|
|
|
requirements_file="requirements.txt"
|
|
|
|
|
|
|
|
# Check if Python 3.8 is installed
|
2023-12-26 21:11:16 +08:00
|
|
|
if ! command -v python3 >/dev/null 2>&1; then
|
2023-08-27 01:21:18 +08:00
|
|
|
echo "Python 3 not found. Attempting to install 3.8..."
|
2023-12-26 21:11:16 +08:00
|
|
|
if [ "$(uname)" = "Darwin" ] && command -v brew >/dev/null 2>&1; then
|
2023-08-27 01:21:18 +08:00
|
|
|
brew install python@3.8
|
2023-12-26 21:11:16 +08:00
|
|
|
elif [ "$(uname)" = "Linux" ] && command -v apt-get >/dev/null 2>&1; then
|
2023-08-27 01:21:18 +08:00
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install python3.8
|
|
|
|
else
|
|
|
|
echo "Please install Python 3.8 manually."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
python3 -m venv .venv
|
2023-12-26 21:11:16 +08:00
|
|
|
. .venv/bin/activate
|
2023-07-13 15:05:35 +08:00
|
|
|
|
2023-08-27 01:21:18 +08:00
|
|
|
# Check if required packages are installed and install them if not
|
|
|
|
if [ -f "${requirements_file}" ]; then
|
|
|
|
installed_packages=$(python3 -m pip freeze)
|
|
|
|
while IFS= read -r package; do
|
2023-12-26 21:11:16 +08:00
|
|
|
expr "${package}" : "^#.*" > /dev/null && continue
|
2023-08-27 01:21:18 +08:00
|
|
|
package_name=$(echo "${package}" | sed 's/[<>=!].*//')
|
|
|
|
if ! echo "${installed_packages}" | grep -q "${package_name}"; then
|
|
|
|
echo "${package_name} not found. Attempting to install..."
|
|
|
|
python3 -m pip install --upgrade "${package}"
|
|
|
|
fi
|
|
|
|
done < "${requirements_file}"
|
2023-07-13 15:05:35 +08:00
|
|
|
else
|
2023-08-27 01:21:18 +08:00
|
|
|
echo "${requirements_file} not found. Please ensure the requirements file with required packages exists."
|
2023-07-13 15:05:35 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-08-27 01:21:18 +08:00
|
|
|
# Download models
|
|
|
|
./tools/dlmodels.sh
|
2023-07-13 15:05:35 +08:00
|
|
|
|
2023-12-26 21:11:16 +08:00
|
|
|
if [ $? -ne 0 ]; then
|
2023-09-02 13:53:56 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-07-13 15:05:35 +08:00
|
|
|
# Run the main script
|
2023-08-27 01:21:18 +08:00
|
|
|
python3 infer-web.py --pycmd python3
|