|
| 1 | +# Docker Setup Guide for SHARP |
| 2 | + |
| 3 | +This guide covers running SHARP using Docker with the Gradio web interface. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- **Docker** 20.10 or later |
| 8 | +- **Docker Compose** v2.0 or later |
| 9 | +- **NVIDIA GPU** with CUDA support |
| 10 | +- **NVIDIA Container Toolkit** ([installation guide](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html)) |
| 11 | + |
| 12 | +### Verify NVIDIA Container Toolkit |
| 13 | + |
| 14 | +```bash |
| 15 | +docker run --rm --gpus all nvidia/cuda:12.9.1-base-ubuntu24.04 nvidia-smi |
| 16 | +``` |
| 17 | + |
| 18 | +## Quick Start |
| 19 | + |
| 20 | +```bash |
| 21 | +# Clone the repository |
| 22 | +git clone https://github.com/apple/ml-sharp.git |
| 23 | +cd ml-sharp |
| 24 | + |
| 25 | +# Build and run |
| 26 | +docker compose up --build |
| 27 | +``` |
| 28 | + |
| 29 | +Open http://localhost:7860 in your browser. |
| 30 | + |
| 31 | +## Configuration |
| 32 | + |
| 33 | +### Environment Variables |
| 34 | + |
| 35 | +Configure the application by setting environment variables in `compose.yml`: |
| 36 | + |
| 37 | +| Variable | Default | Description | |
| 38 | +|----------|---------|-------------| |
| 39 | +| `SHARP_AUTH_USERNAME` | *(none)* | Username for web authentication | |
| 40 | +| `SHARP_AUTH_PASSWORD` | *(none)* | Password for web authentication | |
| 41 | +| `SHARP_MAX_FILE_SIZE_MB` | `50` | Maximum upload file size in MB | |
| 42 | +| `SHARP_PORT` | `7860` | Web server port | |
| 43 | +| `SHARP_DATA_DIR` | `/app/data` | Data directory inside container | |
| 44 | + |
| 45 | +### Enabling Authentication |
| 46 | + |
| 47 | +Edit `compose.yml` to uncomment and set credentials: |
| 48 | + |
| 49 | +```yaml |
| 50 | +environment: |
| 51 | + - SHARP_AUTH_USERNAME=admin |
| 52 | + - SHARP_AUTH_PASSWORD=your-secure-password |
| 53 | +``` |
| 54 | +
|
| 55 | +**Important:** Always enable authentication when exposing the service to a network. |
| 56 | +
|
| 57 | +### Resource Limits |
| 58 | +
|
| 59 | +The default configuration limits resources to prevent abuse: |
| 60 | +
|
| 61 | +```yaml |
| 62 | +deploy: |
| 63 | + resources: |
| 64 | + limits: |
| 65 | + cpus: "8" |
| 66 | + memory: 32G |
| 67 | +``` |
| 68 | +
|
| 69 | +Adjust these based on your hardware capabilities. |
| 70 | +
|
| 71 | +## Usage |
| 72 | +
|
| 73 | +### Web Interface |
| 74 | +
|
| 75 | +1. Navigate to http://localhost:7860 |
| 76 | +2. Upload an image (JPEG, PNG, GIF, BMP, or WebP) |
| 77 | +3. Wait for processing (typically under 1 second on GPU) |
| 78 | +4. Download the generated RGB and depth videos |
| 79 | +
|
| 80 | +### Supported Image Formats |
| 81 | +
|
| 82 | +- JPEG/JPG |
| 83 | +- PNG |
| 84 | +- GIF |
| 85 | +- BMP |
| 86 | +- WebP |
| 87 | +
|
| 88 | +Maximum file size: 50MB (configurable) |
| 89 | +
|
| 90 | +### Output |
| 91 | +
|
| 92 | +The web interface generates two videos: |
| 93 | +- **RGB Video**: Photorealistic 3D view synthesis |
| 94 | +- **Depth Video**: Depth map visualization |
| 95 | +
|
| 96 | +Output files are saved to the `./data` directory on your host machine. |
| 97 | + |
| 98 | +## Advanced Usage |
| 99 | + |
| 100 | +### Running in Background |
| 101 | + |
| 102 | +```bash |
| 103 | +docker compose up -d --build |
| 104 | +``` |
| 105 | + |
| 106 | +### Viewing Logs |
| 107 | + |
| 108 | +```bash |
| 109 | +docker compose logs -f |
| 110 | +``` |
| 111 | + |
| 112 | +### Stopping the Service |
| 113 | + |
| 114 | +```bash |
| 115 | +docker compose down |
| 116 | +``` |
| 117 | + |
| 118 | +### Rebuilding After Changes |
| 119 | + |
| 120 | +```bash |
| 121 | +docker compose up --build --force-recreate |
| 122 | +``` |
| 123 | + |
| 124 | +### Using a Custom Port |
| 125 | + |
| 126 | +Edit `compose.yml`: |
| 127 | + |
| 128 | +```yaml |
| 129 | +ports: |
| 130 | + - "8080:7860" # Access at localhost:8080 |
| 131 | +``` |
| 132 | + |
| 133 | +Or set the environment variable: |
| 134 | + |
| 135 | +```yaml |
| 136 | +environment: |
| 137 | + - SHARP_PORT=8080 |
| 138 | +ports: |
| 139 | + - "8080:8080" |
| 140 | +``` |
| 141 | + |
| 142 | +## Production Deployment |
| 143 | + |
| 144 | +### Security Recommendations |
| 145 | + |
| 146 | +1. **Enable Authentication**: Always set `SHARP_AUTH_USERNAME` and `SHARP_AUTH_PASSWORD` |
| 147 | + |
| 148 | +2. **Use a Reverse Proxy**: Deploy behind nginx or Traefik for: |
| 149 | + - SSL/TLS termination |
| 150 | + - Rate limiting |
| 151 | + - Additional security headers |
| 152 | + |
| 153 | +3. **Network Isolation**: Bind to localhost and use a reverse proxy: |
| 154 | + ```yaml |
| 155 | + ports: |
| 156 | + - "127.0.0.1:7860:7860" |
| 157 | + ``` |
| 158 | + |
| 159 | +4. **Regular Updates**: Keep the Docker image updated for security patches |
| 160 | + |
| 161 | +### Example nginx Configuration |
| 162 | + |
| 163 | +```nginx |
| 164 | +server { |
| 165 | + listen 443 ssl http2; |
| 166 | + server_name sharp.example.com; |
| 167 | +
|
| 168 | + ssl_certificate /path/to/cert.pem; |
| 169 | + ssl_certificate_key /path/to/key.pem; |
| 170 | +
|
| 171 | + location / { |
| 172 | + proxy_pass http://127.0.0.1:7860; |
| 173 | + proxy_http_version 1.1; |
| 174 | + proxy_set_header Upgrade $http_upgrade; |
| 175 | + proxy_set_header Connection "upgrade"; |
| 176 | + proxy_set_header Host $host; |
| 177 | + proxy_set_header X-Real-IP $remote_addr; |
| 178 | + proxy_read_timeout 300s; |
| 179 | + } |
| 180 | +} |
| 181 | +``` |
| 182 | + |
| 183 | +## Troubleshooting |
| 184 | + |
| 185 | +### GPU Not Detected |
| 186 | + |
| 187 | +```bash |
| 188 | +# Verify NVIDIA Container Toolkit |
| 189 | +nvidia-ctk --version |
| 190 | +
|
| 191 | +# Check Docker GPU access |
| 192 | +docker run --rm --gpus all nvidia/cuda:12.9.1-base-ubuntu24.04 nvidia-smi |
| 193 | +``` |
| 194 | + |
| 195 | +### Out of Memory |
| 196 | + |
| 197 | +Reduce resource limits or process smaller images: |
| 198 | + |
| 199 | +```yaml |
| 200 | +environment: |
| 201 | + - SHARP_MAX_FILE_SIZE_MB=20 |
| 202 | +``` |
| 203 | + |
| 204 | +### Build Fails |
| 205 | + |
| 206 | +Ensure you have sufficient disk space (the image requires ~15GB): |
| 207 | + |
| 208 | +```bash |
| 209 | +docker system df |
| 210 | +docker system prune # Clean unused resources |
| 211 | +``` |
| 212 | + |
| 213 | +### Container Won't Start |
| 214 | + |
| 215 | +Check logs for errors: |
| 216 | + |
| 217 | +```bash |
| 218 | +docker compose logs sharp |
| 219 | +``` |
| 220 | + |
| 221 | +### Permission Denied on Data Directory |
| 222 | + |
| 223 | +Ensure the `./data` directory is writable: |
| 224 | + |
| 225 | +```bash |
| 226 | +mkdir -p data |
| 227 | +chmod 755 data |
| 228 | +``` |
| 229 | + |
| 230 | +## Development |
| 231 | + |
| 232 | +### Building Manually |
| 233 | + |
| 234 | +```bash |
| 235 | +docker build -t sharp:latest . |
| 236 | +``` |
| 237 | + |
| 238 | +### Running Without Compose |
| 239 | + |
| 240 | +```bash |
| 241 | +docker run --gpus all -p 7860:7860 -v $(pwd)/data:/app/data sharp:latest |
| 242 | +``` |
| 243 | + |
| 244 | +### Accessing Container Shell |
| 245 | + |
| 246 | +```bash |
| 247 | +docker compose exec sharp bash |
| 248 | +``` |
| 249 | + |
| 250 | +## Architecture |
| 251 | + |
| 252 | +The Docker setup includes: |
| 253 | + |
| 254 | +- **Base Image**: `nvidia/cuda:12.9.1-cudnn-devel-ubuntu24.04` |
| 255 | +- **Python**: 3.13 |
| 256 | +- **Security**: Runs as non-root user (`sharp`) |
| 257 | +- **Web Interface**: Gradio on port 7860 |
| 258 | +- **Model**: Auto-downloaded on first build (~cached in image) |
| 259 | + |
| 260 | +## License |
| 261 | + |
| 262 | +See the main [README.md](README.md) for license information. |
0 commit comments