YiftachEde commited on
Commit
6b78472
·
1 Parent(s): b12ec62
Files changed (1) hide show
  1. app.py +29 -1
app.py CHANGED
@@ -2,7 +2,35 @@ import os
2
  # this is a HF Spaces specific hack, as
3
  # (i) building pytorch3d with GPU support is a bit tricky here
4
  # (ii) installing the wheel via requirements.txt breaks ZeroGPU
5
- os.system("pip install pytorch3d -f https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/py310_cu118_pyt240/download.html")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  import torch
8
  import torch.nn as nn
 
2
  # this is a HF Spaces specific hack, as
3
  # (i) building pytorch3d with GPU support is a bit tricky here
4
  # (ii) installing the wheel via requirements.txt breaks ZeroGPU
5
+
6
+ # Use the dynamic approach from PyTorch3D documentation to determine the correct wheel
7
+ import sys
8
+ import torch
9
+
10
+ # Install iopath first as it's a dependency
11
+ os.system("pip install iopath")
12
+
13
+ # Dynamically determine the correct wheel URL based on Python and PyTorch versions
14
+ pyt_version_str = torch.__version__.split("+")[0].replace(".", "")
15
+ cuda_version_str = torch.version.cuda.replace(".", "") if torch.cuda.is_available() else "cpu"
16
+ version_str = f"py3{sys.version_info.minor}_cu{cuda_version_str}_pyt{pyt_version_str}"
17
+
18
+ print(f"Looking for PyTorch3D wheel for: {version_str}")
19
+ os.system(f"pip install --no-index --no-cache-dir pytorch3d -f https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/{version_str}/download.html")
20
+
21
+ # If the wheel installation fails, try installing from source
22
+ try:
23
+ import pytorch3d
24
+ print("PyTorch3D installed successfully from wheel")
25
+ except ImportError:
26
+ print("Wheel not found, attempting to install PyTorch3D from source")
27
+ os.system('pip install "git+https://github.com/facebookresearch/pytorch3d.git@stable"')
28
+ try:
29
+ import pytorch3d
30
+ print("PyTorch3D installed successfully from source")
31
+ except ImportError:
32
+ print("WARNING: Could not install PyTorch3D. Some functionality may be limited.")
33
+ # Continue without PyTorch3D - the app will need to handle missing functionality
34
 
35
  import torch
36
  import torch.nn as nn