akhaliq HF Staff commited on
Commit
ee01f31
·
verified ·
1 Parent(s): b288f79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -29
app.py CHANGED
@@ -37,39 +37,58 @@ def install_dependencies():
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
- # ADDED: hydra-core, omegaconf, and other core ML libs required by sam3d
50
- # because we are using --no-deps later.
51
  packages = [
52
- "hydra-core", # Required for the patch script
53
- "omegaconf", # Required for hydra
54
- "numpy",
55
- "einops", # Required by model
56
- "timm", # Required by model
57
- "diffusers", # Required by model
58
- "transformers", # Required by model
59
- "accelerate", # Required by model
60
- "safetensors", # Required by model
61
- "pytest",
62
- "pipdeptree",
63
- "findpydeps",
64
- "lovely_tensors",
65
- "seaborn==0.13.2",
66
- "gradio==5.49.0",
67
- "kaolin==0.17.0",
68
- "flash_attn==2.8.3",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  # Git installs
70
- "git+https://github.com/nerfstudio-project/gsplat.git@2323de5905d5e90e035f792fe65bad0fedd413e7",
71
  "git+https://github.com/facebookresearch/pytorch3d",
72
- "utils3d"
 
73
  ]
74
 
75
  for pkg in packages:
@@ -77,7 +96,6 @@ def install_dependencies():
77
  print(f"Installing: {pkg}")
78
  print(f"----------------------------------------")
79
  try:
80
- # We use --no-build-isolation for git repos sometimes to pick up current environment packages
81
  cmd = [sys.executable, "-m", "pip", "install", pkg]
82
  subprocess.run(cmd, env=env, check=True)
83
  except subprocess.CalledProcessError as e:
@@ -89,9 +107,8 @@ def install_dependencies():
89
  subprocess.run(["git", "clone", REPO_URL, REPO_DIR], check=True)
90
 
91
  os.chdir(REPO_DIR)
92
- patch_pyproject_toml() # Strip bad dependencies
93
 
94
- # Install the repo itself (excluding the faulty dev deps we just manually handled)
95
  print("Installing sam-3d-objects in editable mode...")
96
  subprocess.run([sys.executable, "-m", "pip", "install", "--no-deps", "-e", "."], env=env, check=True)
97
 
@@ -100,7 +117,6 @@ def install_dependencies():
100
  if os.path.exists(patch_script):
101
  print("Applying Hydra patch...")
102
  subprocess.run(["chmod", "+x", patch_script], check=True)
103
- # Now this should work because hydra-core is installed
104
  subprocess.run([patch_script], check=True)
105
 
106
  # Run installation
@@ -199,7 +215,6 @@ def lazy_import_sam3d():
199
  except ImportError as e:
200
  print(f"Failed to import SAM 3D modules: {e}")
201
  print("Ensure the installation step completed successfully.")
202
- # Helpful debugging for missing deps
203
  subprocess.run([sys.executable, "-m", "pipdeptree"])
204
  raise
205
 
@@ -226,7 +241,6 @@ def run_inference(image: np.ndarray, mask: np.ndarray, config_file: str, seed: O
226
  """GPU-decorated inference function for ZeroGPU."""
227
  global _pipeline
228
 
229
- # Ensure pipeline is loaded
230
  _pipeline = load_pipeline(config_file)
231
  if hasattr(_pipeline, 'to'):
232
  _pipeline.to('cuda')
 
37
 
38
  # 1. Basic PIP Upgrade
39
  env = os.environ.copy()
 
40
  env["PIP_EXTRA_INDEX_URL"] = "https://pypi.ngc.nvidia.com https://download.pytorch.org/whl/cu121"
41
  env["PIP_FIND_LINKS"] = "https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-2.5.1_cu121.html"
42
  env["CUDA_HOME"] = "/usr/local/cuda"
43
+ env["MAX_JOBS"] = "4"
44
 
45
  subprocess.run([sys.executable, "-m", "pip", "install", "--upgrade", "pip"], env=env, check=True)
46
 
47
  # 2. User Defined Package List
 
 
48
  packages = [
49
+ # Core ML & Hydra
50
+ "hydra-core", "hydra-submitit-launcher", "omegaconf", "numpy", "einops",
51
+ "einops-exts", "timm", "diffusers", "transformers", "accelerate", "safetensors",
52
+ # Testing & Dev Tools
53
+ "pytest", "pipdeptree", "findpydeps", "lovely_tensors", "autoflake",
54
+ "black", "flake8", "usort",
55
+ # Visualization & UI
56
+ "seaborn", "gradio", "tensorboard", "wandb", "polyscope",
57
+ # 3D & Graphics
58
+ "kaolin", "flash_attn", "open3d", "pyrender", "point-cloud-utils",
59
+ "pymeshfix", "xatlas", "panda3d-gltf", "fvcore", "roma", "smplx",
60
+ "OpenEXR", "imath",
61
+ # Video & Audio
62
+ "av", "decord", "librosa",
63
+ # CUDA & GPU
64
+ "cuda-python", "nvidia-cuda-nvcc-cu12", "nvidia-pyindex", "spconv-cu121",
65
+ "xformers", "torchaudio",
66
+ # ML Optimization
67
+ "auto_gptq", "bitsandbytes", "peft", "optimum", "optree", "lightning",
68
+ "sentence-transformers",
69
+ # Data & Serialization
70
+ "h5py", "fastavro", "jsonlines", "jsonpickle", "orjson", "simplejson",
71
+ "webdataset",
72
+ # Image Processing
73
+ "opencv-python", "scikit-image", "pycocotools", "ftfy",
74
+ # Web & Networking
75
+ "Flask", "Werkzeug", "hdfs", "httplib2", "PySocks", "gdown",
76
+ # Utilities
77
+ "astor", "async-timeout", "colorama", "deprecation", "easydict",
78
+ "exceptiongroup", "fasteners", "loguru", "objsize", "randomname",
79
+ "rootutils", "Rtree", "tomli",
80
+ # JSON Schema & URI
81
+ "fqdn", "isoduration", "jsonpointer", "uri-template", "webcolors",
82
+ # Graph & Docs
83
+ "igraph", "pydot", "pdoc3",
84
+ # Jupyter & Misc
85
+ "jupyter", "dataclasses", "crcmod", "conda-pack", "pip-system-certs",
86
+ "python-pycg", "pymongo", "sagemaker", "mosaicml-streaming", "bpy",
87
  # Git installs
88
+ "git+https://github.com/nerfstudio-project/gsplat.git",
89
  "git+https://github.com/facebookresearch/pytorch3d",
90
+ "git+https://github.com/microsoft/MoGe.git",
91
+ "utils3d",
92
  ]
93
 
94
  for pkg in packages:
 
96
  print(f"Installing: {pkg}")
97
  print(f"----------------------------------------")
98
  try:
 
99
  cmd = [sys.executable, "-m", "pip", "install", pkg]
100
  subprocess.run(cmd, env=env, check=True)
101
  except subprocess.CalledProcessError as e:
 
107
  subprocess.run(["git", "clone", REPO_URL, REPO_DIR], check=True)
108
 
109
  os.chdir(REPO_DIR)
110
+ patch_pyproject_toml()
111
 
 
112
  print("Installing sam-3d-objects in editable mode...")
113
  subprocess.run([sys.executable, "-m", "pip", "install", "--no-deps", "-e", "."], env=env, check=True)
114
 
 
117
  if os.path.exists(patch_script):
118
  print("Applying Hydra patch...")
119
  subprocess.run(["chmod", "+x", patch_script], check=True)
 
120
  subprocess.run([patch_script], check=True)
121
 
122
  # Run installation
 
215
  except ImportError as e:
216
  print(f"Failed to import SAM 3D modules: {e}")
217
  print("Ensure the installation step completed successfully.")
 
218
  subprocess.run([sys.executable, "-m", "pipdeptree"])
219
  raise
220
 
 
241
  """GPU-decorated inference function for ZeroGPU."""
242
  global _pipeline
243
 
 
244
  _pipeline = load_pipeline(config_file)
245
  if hasattr(_pipeline, 'to'):
246
  _pipeline.to('cuda')