Spaces:
Paused
Paused
Delete setup_spaces.py
Browse files- setup_spaces.py +0 -161
setup_spaces.py
DELETED
|
@@ -1,161 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
Setup script for Hugging Face Spaces deployment
|
| 4 |
-
This script handles the installation of complex dependencies like nvdiffrast and PyTorch3D
|
| 5 |
-
"""
|
| 6 |
-
|
| 7 |
-
import os
|
| 8 |
-
import sys
|
| 9 |
-
import subprocess
|
| 10 |
-
import shutil
|
| 11 |
-
from pathlib import Path
|
| 12 |
-
|
| 13 |
-
def run_command(command, cwd=None):
|
| 14 |
-
"""Run a shell command and return the result"""
|
| 15 |
-
print(f"Running: {command}")
|
| 16 |
-
result = subprocess.run(command, shell=True, cwd=cwd, capture_output=True, text=True)
|
| 17 |
-
if result.returncode != 0:
|
| 18 |
-
print(f"Error running command: {command}")
|
| 19 |
-
print(f"Error output: {result.stderr}")
|
| 20 |
-
return False
|
| 21 |
-
print(f"Success: {command}")
|
| 22 |
-
return True
|
| 23 |
-
|
| 24 |
-
def setup_nvdiffrast():
|
| 25 |
-
"""Install nvdiffrast"""
|
| 26 |
-
print("Setting up nvdiffrast...")
|
| 27 |
-
|
| 28 |
-
# Create packages directory if it doesn't exist
|
| 29 |
-
packages_dir = Path("packages")
|
| 30 |
-
packages_dir.mkdir(exist_ok=True)
|
| 31 |
-
|
| 32 |
-
# Clone nvdiffrast
|
| 33 |
-
if not (packages_dir / "nvdiffrast").exists():
|
| 34 |
-
if not run_command("git clone https://github.com/NVlabs/nvdiffrast.git", cwd=packages_dir):
|
| 35 |
-
return False
|
| 36 |
-
|
| 37 |
-
# Install nvdiffrast
|
| 38 |
-
nvdiffrast_dir = packages_dir / "nvdiffrast"
|
| 39 |
-
if not run_command("pip install .", cwd=nvdiffrast_dir):
|
| 40 |
-
return False
|
| 41 |
-
|
| 42 |
-
return True
|
| 43 |
-
|
| 44 |
-
def setup_pytorch3d():
|
| 45 |
-
"""Install PyTorch3D"""
|
| 46 |
-
print("Setting up PyTorch3D...")
|
| 47 |
-
|
| 48 |
-
packages_dir = Path("packages")
|
| 49 |
-
|
| 50 |
-
# Clone PyTorch3D
|
| 51 |
-
if not (packages_dir / "pytorch3d").exists():
|
| 52 |
-
if not run_command("git clone https://github.com/facebookresearch/pytorch3d.git", cwd=packages_dir):
|
| 53 |
-
return False
|
| 54 |
-
|
| 55 |
-
# Install PyTorch3D with CUDA support
|
| 56 |
-
pytorch3d_dir = packages_dir / "pytorch3d"
|
| 57 |
-
|
| 58 |
-
# Set environment variables for CUDA support
|
| 59 |
-
env = os.environ.copy()
|
| 60 |
-
env['FORCE_CUDA'] = '1'
|
| 61 |
-
env['DISTUTILS_USE_SDK'] = '1'
|
| 62 |
-
|
| 63 |
-
# Try to install with pip first
|
| 64 |
-
if not run_command("FORCE_CUDA=1 pip install .", cwd=pytorch3d_dir):
|
| 65 |
-
# Fallback to setup.py
|
| 66 |
-
if not run_command("FORCE_CUDA=1 python setup.py install", cwd=pytorch3d_dir):
|
| 67 |
-
return False
|
| 68 |
-
|
| 69 |
-
return True
|
| 70 |
-
|
| 71 |
-
def setup_fashion_clip():
|
| 72 |
-
"""Setup Fashion-CLIP"""
|
| 73 |
-
print("Setting up Fashion-CLIP...")
|
| 74 |
-
|
| 75 |
-
packages_dir = Path("packages")
|
| 76 |
-
|
| 77 |
-
# Clone Fashion-CLIP if not already present
|
| 78 |
-
if not (packages_dir / "fashion-clip").exists():
|
| 79 |
-
if not run_command("git clone https://github.com/patrickjohncyh/fashion-clip.git", cwd=packages_dir):
|
| 80 |
-
return False
|
| 81 |
-
|
| 82 |
-
# Install Fashion-CLIP dependencies
|
| 83 |
-
fashion_clip_dir = packages_dir / "fashion-clip"
|
| 84 |
-
dependencies = ["appdirs", "boto3", "annoy", "validators", "transformers", "datasets"]
|
| 85 |
-
|
| 86 |
-
for dep in dependencies:
|
| 87 |
-
if not run_command(f"pip install {dep}", cwd=fashion_clip_dir):
|
| 88 |
-
print(f"Warning: Failed to install {dep}")
|
| 89 |
-
|
| 90 |
-
return True
|
| 91 |
-
|
| 92 |
-
def install_basic_dependencies():
|
| 93 |
-
"""Install basic Python dependencies"""
|
| 94 |
-
print("Installing basic dependencies...")
|
| 95 |
-
|
| 96 |
-
# Install PyTorch with CUDA 12.1 support FIRST
|
| 97 |
-
if not run_command("pip install torch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 --index-url https://download.pytorch.org/whl/cu121"):
|
| 98 |
-
return False
|
| 99 |
-
|
| 100 |
-
# Install torch-sparse and torch-scatter with correct CUDA version
|
| 101 |
-
if not run_command("pip install torch-sparse torch-scatter -f https://data.pyg.org/whl/torch-2.2.2+cu121.html"):
|
| 102 |
-
return False
|
| 103 |
-
|
| 104 |
-
# Install other dependencies
|
| 105 |
-
if not run_command("pip install -r requirements.txt"):
|
| 106 |
-
return False
|
| 107 |
-
|
| 108 |
-
# Install CLIP
|
| 109 |
-
if not run_command("pip install git+https://github.com/openai/CLIP.git"):
|
| 110 |
-
return False
|
| 111 |
-
|
| 112 |
-
return True
|
| 113 |
-
|
| 114 |
-
def create_symlinks():
|
| 115 |
-
"""Create necessary symlinks for the packages"""
|
| 116 |
-
print("Creating package symlinks...")
|
| 117 |
-
|
| 118 |
-
# Add packages to Python path
|
| 119 |
-
packages_dir = Path("packages")
|
| 120 |
-
|
| 121 |
-
# Create __init__.py files if they don't exist
|
| 122 |
-
for package_dir in packages_dir.iterdir():
|
| 123 |
-
if package_dir.is_dir():
|
| 124 |
-
init_file = package_dir / "__init__.py"
|
| 125 |
-
if not init_file.exists():
|
| 126 |
-
init_file.touch()
|
| 127 |
-
|
| 128 |
-
return True
|
| 129 |
-
|
| 130 |
-
def main():
|
| 131 |
-
"""Main setup function"""
|
| 132 |
-
print("Starting setup for Hugging Face Spaces deployment...")
|
| 133 |
-
|
| 134 |
-
# Install basic dependencies first
|
| 135 |
-
if not install_basic_dependencies():
|
| 136 |
-
print("Failed to install basic dependencies")
|
| 137 |
-
sys.exit(1)
|
| 138 |
-
|
| 139 |
-
# Setup complex dependencies
|
| 140 |
-
if not setup_nvdiffrast():
|
| 141 |
-
print("Failed to setup nvdiffrast")
|
| 142 |
-
sys.exit(1)
|
| 143 |
-
|
| 144 |
-
if not setup_pytorch3d():
|
| 145 |
-
print("Failed to setup PyTorch3D")
|
| 146 |
-
sys.exit(1)
|
| 147 |
-
|
| 148 |
-
if not setup_fashion_clip():
|
| 149 |
-
print("Failed to setup Fashion-CLIP")
|
| 150 |
-
sys.exit(1)
|
| 151 |
-
|
| 152 |
-
# Create symlinks
|
| 153 |
-
if not create_symlinks():
|
| 154 |
-
print("Failed to create symlinks")
|
| 155 |
-
sys.exit(1)
|
| 156 |
-
|
| 157 |
-
print("Setup completed successfully!")
|
| 158 |
-
print("You can now run the Gradio interface with: python app.py")
|
| 159 |
-
|
| 160 |
-
if __name__ == "__main__":
|
| 161 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|