Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,6 @@ REPO_DIR = "/home/user/app/sam-3d-objects"
|
|
| 11 |
def patch_pyproject_toml():
|
| 12 |
"""
|
| 13 |
Removes 'bpy==4.3.0' from pyproject.toml to prevent installation failures.
|
| 14 |
-
This package is often unavailable on PyPI and usually not needed for inference.
|
| 15 |
"""
|
| 16 |
print("Patching pyproject.toml to remove strict bpy dependency...")
|
| 17 |
pyproject_path = os.path.join(REPO_DIR, "pyproject.toml")
|
|
@@ -20,12 +19,9 @@ def patch_pyproject_toml():
|
|
| 20 |
with open(pyproject_path, "r") as f:
|
| 21 |
content = f.read()
|
| 22 |
|
| 23 |
-
# Remove dependency entries for bpy
|
| 24 |
-
# We try multiple formats to ensure we catch it (with/without quotes/commas)
|
| 25 |
new_content = content.replace('"bpy==4.3.0",', '')
|
| 26 |
new_content = new_content.replace("'bpy==4.3.0',", '')
|
| 27 |
-
new_content = new_content.replace('"bpy==4.3.0"', '')
|
| 28 |
-
new_content = new_content.replace("'bpy==4.3.0'", '')
|
| 29 |
|
| 30 |
with open(pyproject_path, "w") as f:
|
| 31 |
f.write(new_content)
|
|
@@ -35,51 +31,65 @@ def patch_pyproject_toml():
|
|
| 35 |
|
| 36 |
def install_dependencies():
|
| 37 |
"""
|
| 38 |
-
Installs
|
| 39 |
"""
|
| 40 |
-
print("Starting installation sequence...")
|
| 41 |
|
| 42 |
-
# 1.
|
| 43 |
-
if not os.path.exists(REPO_DIR):
|
| 44 |
-
print(f"Cloning repository to {REPO_DIR}...")
|
| 45 |
-
subprocess.run(["git", "clone", REPO_URL, REPO_DIR], check=True)
|
| 46 |
-
|
| 47 |
-
# Switch working directory to repo
|
| 48 |
-
os.chdir(REPO_DIR)
|
| 49 |
-
|
| 50 |
-
# 2. Patch the faulty dependency BEFORE installing
|
| 51 |
-
patch_pyproject_toml()
|
| 52 |
-
|
| 53 |
-
# 3. Set Environment Variables for PIP
|
| 54 |
env = os.environ.copy()
|
|
|
|
| 55 |
env["PIP_EXTRA_INDEX_URL"] = "https://pypi.ngc.nvidia.com https://download.pytorch.org/whl/cu121"
|
| 56 |
env["PIP_FIND_LINKS"] = "https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-2.5.1_cu121.html"
|
| 57 |
-
|
| 58 |
-
#
|
|
|
|
| 59 |
subprocess.run([sys.executable, "-m", "pip", "install", "--upgrade", "pip"], env=env, check=True)
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
# Install
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
patch_script = os.path.join(REPO_DIR, "patching", "hydra")
|
| 77 |
if os.path.exists(patch_script):
|
| 78 |
print("Applying Hydra patch...")
|
| 79 |
subprocess.run(["chmod", "+x", patch_script], check=True)
|
| 80 |
subprocess.run([patch_script], check=True)
|
| 81 |
-
else:
|
| 82 |
-
print(f"Warning: Patch script not found at {patch_script}")
|
| 83 |
|
| 84 |
# Run installation
|
| 85 |
install_dependencies()
|
|
@@ -177,6 +187,8 @@ def lazy_import_sam3d():
|
|
| 177 |
except ImportError as e:
|
| 178 |
print(f"Failed to import SAM 3D modules: {e}")
|
| 179 |
print("Ensure the installation step completed successfully.")
|
|
|
|
|
|
|
| 180 |
raise
|
| 181 |
|
| 182 |
def load_pipeline(config_file: str):
|
|
|
|
| 11 |
def patch_pyproject_toml():
|
| 12 |
"""
|
| 13 |
Removes 'bpy==4.3.0' from pyproject.toml to prevent installation failures.
|
|
|
|
| 14 |
"""
|
| 15 |
print("Patching pyproject.toml to remove strict bpy dependency...")
|
| 16 |
pyproject_path = os.path.join(REPO_DIR, "pyproject.toml")
|
|
|
|
| 19 |
with open(pyproject_path, "r") as f:
|
| 20 |
content = f.read()
|
| 21 |
|
| 22 |
+
# Remove dependency entries for bpy
|
|
|
|
| 23 |
new_content = content.replace('"bpy==4.3.0",', '')
|
| 24 |
new_content = new_content.replace("'bpy==4.3.0',", '')
|
|
|
|
|
|
|
| 25 |
|
| 26 |
with open(pyproject_path, "w") as f:
|
| 27 |
f.write(new_content)
|
|
|
|
| 31 |
|
| 32 |
def install_dependencies():
|
| 33 |
"""
|
| 34 |
+
Installs the specific list of dependencies requested by the user individually.
|
| 35 |
"""
|
| 36 |
+
print("Starting manual installation sequence...")
|
| 37 |
|
| 38 |
+
# 1. Basic PIP Upgrade
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
env = os.environ.copy()
|
| 40 |
+
# specific links for torch/cuda compatibility
|
| 41 |
env["PIP_EXTRA_INDEX_URL"] = "https://pypi.ngc.nvidia.com https://download.pytorch.org/whl/cu121"
|
| 42 |
env["PIP_FIND_LINKS"] = "https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-2.5.1_cu121.html"
|
| 43 |
+
env["CUDA_HOME"] = "/usr/local/cuda"
|
| 44 |
+
env["MAX_JOBS"] = "4" # Speed up compilation
|
| 45 |
+
|
| 46 |
subprocess.run([sys.executable, "-m", "pip", "install", "--upgrade", "pip"], env=env, check=True)
|
| 47 |
|
| 48 |
+
# 2. User Defined Package List
|
| 49 |
+
# Note: Order optimized slightly to put light packages first
|
| 50 |
+
packages = [
|
| 51 |
+
"pytest",
|
| 52 |
+
"pipdeptree",
|
| 53 |
+
"findpydeps",
|
| 54 |
+
"lovely_tensors",
|
| 55 |
+
"seaborn==0.13.2",
|
| 56 |
+
"gradio==5.49.0", # Note: If this version doesn't exist, pip will error.
|
| 57 |
+
"kaolin==0.17.0",
|
| 58 |
+
"flash_attn==2.8.3",
|
| 59 |
+
# Git installs
|
| 60 |
+
"git+https://github.com/nerfstudio-project/gsplat.git@2323de5905d5e90e035f792fe65bad0fedd413e7",
|
| 61 |
+
"git+https://github.com/facebookresearch/pytorch3d.git@75ebeeaea0908c5527e7b1e305fbc7681382db47"
|
| 62 |
+
]
|
| 63 |
|
| 64 |
+
for pkg in packages:
|
| 65 |
+
print(f"----------------------------------------")
|
| 66 |
+
print(f"Installing: {pkg}")
|
| 67 |
+
print(f"----------------------------------------")
|
| 68 |
+
try:
|
| 69 |
+
# We use --no-build-isolation for git repos sometimes to pick up current environment packages
|
| 70 |
+
cmd = [sys.executable, "-m", "pip", "install", pkg]
|
| 71 |
+
subprocess.run(cmd, env=env, check=True)
|
| 72 |
+
except subprocess.CalledProcessError as e:
|
| 73 |
+
print(f"❌ Failed to install {pkg}. Continuing to next package...")
|
| 74 |
|
| 75 |
+
# 3. Clone & Install Main Repo (SAM 3D Objects)
|
| 76 |
+
if not os.path.exists(REPO_DIR):
|
| 77 |
+
print(f"Cloning repository to {REPO_DIR}...")
|
| 78 |
+
subprocess.run(["git", "clone", REPO_URL, REPO_DIR], check=True)
|
| 79 |
+
|
| 80 |
+
os.chdir(REPO_DIR)
|
| 81 |
+
patch_pyproject_toml() # Strip bad dependencies
|
| 82 |
|
| 83 |
+
# Install the repo itself (excluding the faulty dev deps we just manually handled)
|
| 84 |
+
print("Installing sam-3d-objects in editable mode...")
|
| 85 |
+
subprocess.run([sys.executable, "-m", "pip", "install", "--no-deps", "-e", "."], env=env, check=True)
|
| 86 |
+
|
| 87 |
+
# 4. Apply Hydra Patch
|
| 88 |
patch_script = os.path.join(REPO_DIR, "patching", "hydra")
|
| 89 |
if os.path.exists(patch_script):
|
| 90 |
print("Applying Hydra patch...")
|
| 91 |
subprocess.run(["chmod", "+x", patch_script], check=True)
|
| 92 |
subprocess.run([patch_script], check=True)
|
|
|
|
|
|
|
| 93 |
|
| 94 |
# Run installation
|
| 95 |
install_dependencies()
|
|
|
|
| 187 |
except ImportError as e:
|
| 188 |
print(f"Failed to import SAM 3D modules: {e}")
|
| 189 |
print("Ensure the installation step completed successfully.")
|
| 190 |
+
# Helpful debugging for missing deps
|
| 191 |
+
subprocess.run([sys.executable, "-m", "pipdeptree"])
|
| 192 |
raise
|
| 193 |
|
| 194 |
def load_pipeline(config_file: str):
|