Create setup.sh
Browse files
setup.sh
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Setup script for Medical Image Analysis Tool
|
| 4 |
+
# This script handles dependency installation and environment setup
|
| 5 |
+
|
| 6 |
+
set -e # Exit on any error
|
| 7 |
+
|
| 8 |
+
echo "=== Medical Image Analysis Tool Setup ==="
|
| 9 |
+
echo "Starting setup process at $(date)"
|
| 10 |
+
|
| 11 |
+
# Function to check if a Python package is installed
|
| 12 |
+
check_python_package() {
|
| 13 |
+
python3 -c "import $1" 2>/dev/null && echo "β
$1" || echo "β $1"
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
# Function to install Python packages with error handling
|
| 17 |
+
install_python_package() {
|
| 18 |
+
local package=$1
|
| 19 |
+
echo "Installing $package..."
|
| 20 |
+
|
| 21 |
+
if pip install "$package" --no-cache-dir; then
|
| 22 |
+
echo "β
Successfully installed $package"
|
| 23 |
+
else
|
| 24 |
+
echo "β Failed to install $package"
|
| 25 |
+
return 1
|
| 26 |
+
fi
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
# Update pip first
|
| 30 |
+
echo "Updating pip..."
|
| 31 |
+
python3 -m pip install --upgrade pip
|
| 32 |
+
|
| 33 |
+
# Install core dependencies
|
| 34 |
+
echo "Installing core dependencies..."
|
| 35 |
+
install_python_package "torch>=2.5.1"
|
| 36 |
+
install_python_package "torchvision>=0.20.1"
|
| 37 |
+
install_python_package "transformers>=4.30.0"
|
| 38 |
+
install_python_package "gradio>=4.0.0"
|
| 39 |
+
install_python_package "numpy>=1.24.4"
|
| 40 |
+
install_python_package "pillow>=9.4.0"
|
| 41 |
+
|
| 42 |
+
# Install additional required packages
|
| 43 |
+
echo "Installing additional dependencies..."
|
| 44 |
+
install_python_package "albumentations"
|
| 45 |
+
install_python_package "einops"
|
| 46 |
+
install_python_package "opencv-python"
|
| 47 |
+
install_python_package "tqdm"
|
| 48 |
+
install_python_package "hydra-core"
|
| 49 |
+
install_python_package "omegaconf"
|
| 50 |
+
|
| 51 |
+
# Install SAM-2 if directory exists
|
| 52 |
+
if [ -d "segment-anything-2" ]; then
|
| 53 |
+
echo "Installing SAM-2..."
|
| 54 |
+
cd segment-anything-2
|
| 55 |
+
pip install -e . --no-cache-dir
|
| 56 |
+
cd ..
|
| 57 |
+
echo "β
SAM-2 installation completed"
|
| 58 |
+
else
|
| 59 |
+
echo "β οΈ SAM-2 directory not found - cloning repository..."
|
| 60 |
+
git clone https://github.com/facebookresearch/segment-anything-2.git
|
| 61 |
+
cd segment-anything-2
|
| 62 |
+
pip install -e . --no-cache-dir
|
| 63 |
+
cd ..
|
| 64 |
+
echo "β
SAM-2 cloned and installed"
|
| 65 |
+
fi
|
| 66 |
+
|
| 67 |
+
# Verify installations
|
| 68 |
+
echo "Verifying installations..."
|
| 69 |
+
echo "Python packages status:"
|
| 70 |
+
check_python_package "torch"
|
| 71 |
+
check_python_package "torchvision"
|
| 72 |
+
check_python_package "transformers"
|
| 73 |
+
check_python_package "gradio"
|
| 74 |
+
check_python_package "albumentations"
|
| 75 |
+
check_python_package "einops"
|
| 76 |
+
check_python_package "cv2"
|
| 77 |
+
check_python_package "numpy"
|
| 78 |
+
check_python_package "PIL"
|
| 79 |
+
|
| 80 |
+
# Test torch and torchvision compatibility
|
| 81 |
+
echo "Testing PyTorch and Torchvision compatibility..."
|
| 82 |
+
python3 -c "
|
| 83 |
+
import torch
|
| 84 |
+
import torchvision
|
| 85 |
+
print(f'PyTorch version: {torch.__version__}')
|
| 86 |
+
print(f'Torchvision version: {torchvision.__version__}')
|
| 87 |
+
print(f'CUDA available: {torch.cuda.is_available()}')
|
| 88 |
+
print('β
PyTorch and Torchvision are compatible')
|
| 89 |
+
" || echo "β PyTorch/Torchvision compatibility issue"
|
| 90 |
+
|
| 91 |
+
# Create necessary directories
|
| 92 |
+
echo "Creating necessary directories..."
|
| 93 |
+
mkdir -p logs
|
| 94 |
+
mkdir -p uploads
|
| 95 |
+
mkdir -p outputs
|
| 96 |
+
|
| 97 |
+
# Set permissions
|
| 98 |
+
chmod +x app.py
|
| 99 |
+
|
| 100 |
+
echo "=== Setup completed at $(date) ==="
|
| 101 |
+
echo "You can now run the application with: python3 app.py"
|
| 102 |
+
|
| 103 |
+
# Optional: Run a quick test
|
| 104 |
+
echo "Running quick test..."
|
| 105 |
+
python3 -c "
|
| 106 |
+
import sys
|
| 107 |
+
sys.path.append('.')
|
| 108 |
+
try:
|
| 109 |
+
from app import check_dependencies
|
| 110 |
+
deps = check_dependencies()
|
| 111 |
+
print('Dependency check results:')
|
| 112 |
+
for dep, status in deps.items():
|
| 113 |
+
print(f' {dep}: {\"β
\" if status else \"β\"}')
|
| 114 |
+
except Exception as e:
|
| 115 |
+
print(f'Test failed: {e}')
|
| 116 |
+
"
|