From edcff1df046fdfbd0c8ba33c4ff7194c366aea46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sun, 27 Aug 2023 01:21:18 +0800 Subject: [PATCH] optimize: run.sh --- run.sh | 64 ++++++++++++++++++++++++++++------------------- tools/dlmodels.sh | 3 +-- 2 files changed, 39 insertions(+), 28 deletions(-) mode change 100644 => 100755 run.sh diff --git a/run.sh b/run.sh old mode 100644 new mode 100755 index 9f7186e..24ae3e2 --- a/run.sh +++ b/run.sh @@ -9,37 +9,49 @@ elif [[ "$(uname)" != "Linux" ]]; then exit 1 fi -requirements_file="requirements.txt" +if [ -d ".venv" ]; then + echo "Activate venv..." + source .venv/bin/activate +else + echo "Create venv..." + requirements_file="requirements.txt" -# Check if Python 3.8 is installed -if ! command -v python3.8 &> /dev/null; then - echo "Python 3.8 not found. Attempting to install..." - if [[ "$(uname)" == "Darwin" ]] && command -v brew &> /dev/null; then - brew install python@3.8 - elif [[ "$(uname)" == "Linux" ]] && command -v apt-get &> /dev/null; then - sudo apt-get update - sudo apt-get install python3.8 + # Check if Python 3.8 is installed + if ! command -v python3 &> /dev/null; then + echo "Python 3 not found. Attempting to install 3.8..." + if [[ "$(uname)" == "Darwin" ]] && command -v brew &> /dev/null; then + brew install python@3.8 + elif [[ "$(uname)" == "Linux" ]] && command -v apt-get &> /dev/null; then + 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 + source .venv/bin/activate + + # 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 + [[ "${package}" =~ ^#.* ]] && continue + 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}" else - echo "Please install Python 3.8 manually." + echo "${requirements_file} not found. Please ensure the requirements file with required packages exists." exit 1 fi fi -# Check if required packages are installed and install them if not -if [ -f "${requirements_file}" ]; then - installed_packages=$(python3.8 -m pip freeze) - while IFS= read -r package; do - [[ "${package}" =~ ^#.* ]] && continue - package_name=$(echo "${package}" | sed 's/[<>=!].*//') - if ! echo "${installed_packages}" | grep -q "${package_name}"; then - echo "${package_name} not found. Attempting to install..." - python3.8 -m pip install --upgrade "${package}" - fi - done < "${requirements_file}" -else - echo "${requirements_file} not found. Please ensure the requirements file with required packages exists." - exit 1 -fi +# Download models +./tools/dlmodels.sh # Run the main script -python3.8 infer-web.py --pycmd python3.8 \ No newline at end of file +python3 infer-web.py --pycmd python3 diff --git a/tools/dlmodels.sh b/tools/dlmodels.sh index 0ae7f7e..5d91b01 100755 --- a/tools/dlmodels.sh +++ b/tools/dlmodels.sh @@ -524,7 +524,7 @@ else fi echo checking $hb -if [ -f "./pretrained/$hb" ]; then +if [ -f "./$hb" ]; then echo $hb in ./pretrained checked. else echo failed. starting download from huggingface. @@ -543,4 +543,3 @@ else fi echo required files check finished. -read -p "Press any key to continue..." -n1 -s