rope-models / runpod_setup.sh
slaughters85j's picture
Upload runpod_setup.sh with huggingface_hub
a6e6c2d verified
#!/bin/bash
# RunPod Startup Script for Rope Face Swapping Tool
# This script sets up a VNC-accessible desktop environment with Rope installed
set -e # Exit on any error
echo "=========================================="
echo "Rope RunPod Setup Script"
echo "=========================================="
# ==========================================
# CONFIGURATION - Uses environment variables
# ==========================================
# GITHUB_TOKEN must be set via RunPod environment/secrets
if [ -z "$GITHUB_TOKEN" ]; then
echo "ERROR: GITHUB_TOKEN environment variable not set!"
echo "Please configure this in your RunPod template."
exit 1
fi
ROPE_REPO="https://${GITHUB_TOKEN}@github.com/slaughters85j/Rope.git"
# Model hosting URL - HuggingFace datasets repo (public)
MODEL_BASE_URL="https://huggingface.co/datasets/slaughters85j/rope-models/resolve/main"
# VNC Configuration
VNC_PASSWORD="${VNC_PASSWORD:-rope1234}"
VNC_PORT=5901
NOVNC_PORT=6080
# ==========================================
# SYSTEM DEPENDENCIES
# ==========================================
echo "[1/7] Installing system dependencies..."
apt-get update
apt-get install -y \
ffmpeg \
libsm6 \
libxext6 \
libxrender-dev \
libglib2.0-0 \
python3-tk \
x11vnc \
xvfb \
fluxbox \
novnc \
websockify \
wget \
git \
supervisor
# ==========================================
# CREATE WORKSPACE
# ==========================================
echo "[2/7] Setting up workspace..."
mkdir -p /workspace
cd /workspace
# ==========================================
# CLONE ROPE REPOSITORY
# ==========================================
echo "[3/7] Cloning Rope repository..."
if [ -d "Rope" ]; then
echo "Rope directory exists, pulling latest..."
cd Rope
git pull || true
cd ..
else
git clone ${ROPE_REPO}
fi
cd /workspace/Rope
# ==========================================
# INSTALL PYTHON DEPENDENCIES
# ==========================================
echo "[4/7] Installing Python dependencies..."
pip install --upgrade pip
# Install PyTorch with CUDA 11.8 support
pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 torchaudio==2.0.2 \
--extra-index-url https://download.pytorch.org/whl/cu118
# Install other requirements
pip install \
numpy==1.23.5 \
opencv-python==4.7.0.72 \
scikit-image==0.21.0 \
pillow==9.5.0 \
onnx==1.14.0 \
onnxruntime-gpu==1.16.2 \
protobuf==4.23.2 \
tqdm \
ftfy \
regex
# ==========================================
# DOWNLOAD MODELS
# ==========================================
echo "[5/7] Downloading model files..."
mkdir -p /workspace/Rope/models
cd /workspace/Rope/models
# List of model files to download
MODELS=(
"2d106det.onnx"
"79999_iter.pth"
"GPEN-BFR-512.onnx"
"det_10g.onnx"
"epoch_16_best.ckpt"
"faceparser_fp16.onnx"
"inswapper_128.fp16.onnx"
"occluder.onnx"
"rd64-uni-refined.pth"
"res50.onnx"
"scrfd_2.5g_bnkps.onnx"
"w600k_r50.onnx"
)
for model in "${MODELS[@]}"; do
if [ ! -f "$model" ]; then
echo "Downloading $model..."
wget -q --show-progress "${MODEL_BASE_URL}/${model}" -O "$model" || echo "WARNING: Failed to download $model"
else
echo "$model already exists, skipping..."
fi
done
cd /workspace/Rope
# ==========================================
# SETUP VNC SERVER
# ==========================================
echo "[6/7] Configuring VNC server..."
# Create VNC password
mkdir -p ~/.vnc
x11vnc -storepasswd ${VNC_PASSWORD} ~/.vnc/passwd
# Create supervisor config for managing services
cat > /etc/supervisor/conf.d/rope.conf << 'EOF'
[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
[program:xvfb]
command=/usr/bin/Xvfb :1 -screen 0 1920x1080x24
autorestart=true
priority=100
[program:fluxbox]
command=/usr/bin/fluxbox
environment=DISPLAY=":1"
autorestart=true
priority=200
[program:x11vnc]
command=/usr/bin/x11vnc -display :1 -rfbport 5901 -rfbauth /root/.vnc/passwd -forever -shared
autorestart=true
priority=300
[program:novnc]
command=/usr/share/novnc/utils/launch.sh --vnc localhost:5901 --listen 6080
autorestart=true
priority=400
EOF
# Create desktop shortcut for Rope
mkdir -p ~/Desktop
cat > ~/Desktop/Rope.sh << 'EOF'
#!/bin/bash
cd /workspace/Rope
python Rope.py --gpu 0
EOF
chmod +x ~/Desktop/Rope.sh
# ==========================================
# CREATE CONVENIENCE SCRIPTS
# ==========================================
echo "[7/7] Creating convenience scripts..."
# Script to start Rope directly
cat > /workspace/start_rope.sh << 'EOF'
#!/bin/bash
export DISPLAY=:1
cd /workspace/Rope
python Rope.py --gpu 0
EOF
chmod +x /workspace/start_rope.sh
# Script to check GPU status
cat > /workspace/check_gpu.sh << 'EOF'
#!/bin/bash
echo "=== NVIDIA GPU Status ==="
nvidia-smi
echo ""
echo "=== PyTorch CUDA Check ==="
python -c "import torch; print(f'PyTorch: {torch.__version__}'); print(f'CUDA Available: {torch.cuda.is_available()}'); print(f'GPU: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"None\"}')"
EOF
chmod +x /workspace/check_gpu.sh
# ==========================================
# START SERVICES
# ==========================================
echo "=========================================="
echo "Setup Complete!"
echo "=========================================="
echo ""
echo "Starting VNC server..."
echo ""
echo "Access Rope via browser at:"
echo " http://<your-runpod-url>:${NOVNC_PORT}/vnc.html"
echo ""
echo "VNC Password: ${VNC_PASSWORD}"
echo ""
echo "Once connected, open a terminal and run:"
echo " /workspace/start_rope.sh"
echo ""
echo "Or double-click the Rope shortcut on the desktop."
echo "=========================================="
# Start supervisor (this runs all services)
exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf