| #!/bin/bash |
| set -e |
|
|
| |
| command_exists() { |
| command -v "$1" >/dev/null 2>&1 |
| } |
|
|
| echo "Starting the script..." |
|
|
| |
| if ! command_exists python3.10; then |
| echo "Python 3.10 not found. Installing..." |
| apt update |
| apt install -y software-properties-common |
| add-apt-repository -y ppa:deadsnakes/ppa |
| apt update |
| apt install -y python3.10 python3.10-venv python3.10-distutils |
| apt install -y python3-pip |
| else |
| echo "Python 3.10 is already installed." |
| fi |
|
|
| |
| if ! python3.10 -m pip --version >/dev/null 2>&1; then |
| echo "pip not found for Python 3.10. Installing..." |
| python3.10 -m ensurepip --upgrade |
| python3.10 -m pip install --upgrade pip |
| else |
| echo "pip is already installed for Python 3.10." |
| fi |
|
|
| |
| if [ ! -d "sd-scripts" ]; then |
| echo "Cloning the sd-scripts repository..." |
| git clone -b sd3 https://github.com/kohya-ss/sd-scripts.git |
| else |
| echo "The sd-scripts directory already exists. Skipping cloning." |
| fi |
|
|
| |
| if [ -f "sample_prompts.txt" ]; then |
| echo "Copying sample_prompts.txt to the sd-scripts directory..." |
| cp sample_prompts.txt sd-scripts/ |
| else |
| echo "Warning: sample_prompts.txt not found. Skipping copy." |
| fi |
|
|
| |
| cd sd-scripts || { echo "Error: Could not enter the sd-scripts directory."; exit 1; } |
|
|
| |
| if [ ! -d "venv" ]; then |
| echo "Creating the virtual environment with Python 3.10..." |
| python3.10 -m venv venv |
| else |
| echo "The virtual environment already exists. Skipping creation." |
| fi |
|
|
| |
| if [ -f "venv/bin/activate" ]; then |
| echo "Activating the virtual environment..." |
| source venv/bin/activate || { echo "Error: Could not activate the virtual environment."; exit 1; } |
| else |
| echo "Error: Could not find the virtual environment activation script." |
| exit 1 |
| fi |
|
|
| |
| echo "Upgrading pip and setuptools inside the virtual environment..." |
| pip install --upgrade pip setuptools |
|
|
| |
| if [ -f "requirements.txt" ]; then |
| echo "Installing dependencies from requirements.txt..." |
| pip install -r requirements.txt |
| else |
| echo "Warning: requirements.txt not found. Skipping dependency installation." |
| fi |
|
|
| |
| echo "Installing toml and diffusers..." |
| apt install -y git |
| apt update |
| pip install toml diffusers |
| pip3 install --upgrade diffusers |
| pip3 install huggingface-hub==0.11.1 |
| pip3 install --upgrade huggingface-hub |
| pip3 install --upgrade torch torchvision |
| pip3 uninstall -y torchvision |
| pip3 install torchvision |
| pip3 uninstall -y opencv-python |
| pip3 install opencv-python |
| pip3 install --upgrade numpy opencv-python pybind11 |
| pip3 uninstall -y opencv-python opencv-python-headless |
| pip3 install opencv-python-headless |
|
|
| echo "Installing PyTorch and other libraries..." |
| pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 |
|
|
| |
| echo "Reinstalling accelerate..." |
| pip install --upgrade --force-reinstall accelerate |
|
|
| |
| echo "Configuring accelerate..." |
| |
| accelerate config || { |
| echo "Error: Accelerate configuration failed." |
| deactivate |
| exit 1 |
| } |
|
|
| echo "Script completed successfully." |
|
|