File size: 5,905 Bytes
a6e6c2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/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