Upload 1.Setup.sh
Browse files- 1.Setup.sh +114 -0
1.Setup.sh
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
# Function to check if a command exists
|
| 5 |
+
command_exists() {
|
| 6 |
+
command -v "$1" >/dev/null 2>&1
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
echo "Starting the script..."
|
| 10 |
+
|
| 11 |
+
# Install Python 3.10.11 if not present
|
| 12 |
+
if ! command_exists python3.10; then
|
| 13 |
+
echo "Python 3.10 not found. Installing..."
|
| 14 |
+
apt update
|
| 15 |
+
apt install -y software-properties-common
|
| 16 |
+
add-apt-repository -y ppa:deadsnakes/ppa
|
| 17 |
+
apt update
|
| 18 |
+
apt install -y python3.10 python3.10-venv python3.10-distutils
|
| 19 |
+
apt install -y python3-pip
|
| 20 |
+
else
|
| 21 |
+
echo "Python 3.10 is already installed."
|
| 22 |
+
fi
|
| 23 |
+
|
| 24 |
+
# Check pip for Python 3.10
|
| 25 |
+
if ! python3.10 -m pip --version >/dev/null 2>&1; then
|
| 26 |
+
echo "pip not found for Python 3.10. Installing..."
|
| 27 |
+
python3.10 -m ensurepip --upgrade
|
| 28 |
+
python3.10 -m pip install --upgrade pip
|
| 29 |
+
else
|
| 30 |
+
echo "pip is already installed for Python 3.10."
|
| 31 |
+
fi
|
| 32 |
+
|
| 33 |
+
# Clone the repository if it doesn't exist
|
| 34 |
+
if [ ! -d "sd-scripts" ]; then
|
| 35 |
+
echo "Cloning the sd-scripts repository..."
|
| 36 |
+
git clone -b sd3 https://github.com/kohya-ss/sd-scripts.git
|
| 37 |
+
else
|
| 38 |
+
echo "The sd-scripts directory already exists. Skipping cloning."
|
| 39 |
+
fi
|
| 40 |
+
|
| 41 |
+
# Copy sample_prompts.txt if it exists
|
| 42 |
+
if [ -f "sample_prompts.txt" ]; then
|
| 43 |
+
echo "Copying sample_prompts.txt to the sd-scripts directory..."
|
| 44 |
+
cp sample_prompts.txt sd-scripts/
|
| 45 |
+
else
|
| 46 |
+
echo "Warning: sample_prompts.txt not found. Skipping copy."
|
| 47 |
+
fi
|
| 48 |
+
|
| 49 |
+
# Enter the repository directory
|
| 50 |
+
cd sd-scripts || { echo "Error: Could not enter the sd-scripts directory."; exit 1; }
|
| 51 |
+
|
| 52 |
+
# Create a virtual environment with Python 3.10 if it doesn't exist
|
| 53 |
+
if [ ! -d "venv" ]; then
|
| 54 |
+
echo "Creating the virtual environment with Python 3.10..."
|
| 55 |
+
python3.10 -m venv venv
|
| 56 |
+
else
|
| 57 |
+
echo "The virtual environment already exists. Skipping creation."
|
| 58 |
+
fi
|
| 59 |
+
|
| 60 |
+
# Activate the virtual environment in a compatible way
|
| 61 |
+
if [ -f "venv/bin/activate" ]; then
|
| 62 |
+
echo "Activating the virtual environment..."
|
| 63 |
+
source venv/bin/activate || { echo "Error: Could not activate the virtual environment."; exit 1; }
|
| 64 |
+
else
|
| 65 |
+
echo "Error: Could not find the virtual environment activation script."
|
| 66 |
+
exit 1
|
| 67 |
+
fi
|
| 68 |
+
|
| 69 |
+
# Upgrade pip and setuptools inside the virtual environment
|
| 70 |
+
echo "Upgrading pip and setuptools inside the virtual environment..."
|
| 71 |
+
pip install --upgrade pip setuptools
|
| 72 |
+
|
| 73 |
+
# Install dependencies from requirements.txt if it exists
|
| 74 |
+
if [ -f "requirements.txt" ]; then
|
| 75 |
+
echo "Installing dependencies from requirements.txt..."
|
| 76 |
+
pip install -r requirements.txt
|
| 77 |
+
else
|
| 78 |
+
echo "Warning: requirements.txt not found. Skipping dependency installation."
|
| 79 |
+
fi
|
| 80 |
+
|
| 81 |
+
# Install additional packages
|
| 82 |
+
echo "Installing toml and diffusers..."
|
| 83 |
+
apt install -y git
|
| 84 |
+
apt update
|
| 85 |
+
pip install toml diffusers
|
| 86 |
+
pip3 install --upgrade diffusers
|
| 87 |
+
pip3 install huggingface-hub==0.11.1
|
| 88 |
+
pip3 install --upgrade huggingface-hub
|
| 89 |
+
pip3 install --upgrade torch torchvision
|
| 90 |
+
pip3 uninstall -y torchvision
|
| 91 |
+
pip3 install torchvision
|
| 92 |
+
pip3 uninstall -y opencv-python
|
| 93 |
+
pip3 install opencv-python
|
| 94 |
+
pip3 install --upgrade numpy opencv-python pybind11
|
| 95 |
+
pip3 uninstall -y opencv-python opencv-python-headless
|
| 96 |
+
pip3 install opencv-python-headless
|
| 97 |
+
|
| 98 |
+
echo "Installing PyTorch and other libraries..."
|
| 99 |
+
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
|
| 100 |
+
|
| 101 |
+
# Always reinstall accelerate
|
| 102 |
+
echo "Reinstalling accelerate..."
|
| 103 |
+
pip install --upgrade --force-reinstall accelerate
|
| 104 |
+
|
| 105 |
+
# Configure accelerate
|
| 106 |
+
echo "Configuring accelerate..."
|
| 107 |
+
# Attempt a non-interactive configuration (if possible)
|
| 108 |
+
accelerate config || {
|
| 109 |
+
echo "Error: Accelerate configuration failed."
|
| 110 |
+
deactivate
|
| 111 |
+
exit 1
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
echo "Script completed successfully."
|