Spaces:
Running on Zero
Running on Zero
murphylmf commited on
Commit ยท
fc2fc48
1
Parent(s): 15628fc
update
Browse files- app.py +72 -42
- requirements.txt +0 -1
app.py
CHANGED
|
@@ -1,47 +1,5 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import sys
|
| 3 |
-
import torch
|
| 4 |
import subprocess
|
| 5 |
|
| 6 |
-
def install_pytorch3d():
|
| 7 |
-
try:
|
| 8 |
-
import pytorch3d
|
| 9 |
-
print("โ
PyTorch3D already installed.")
|
| 10 |
-
return
|
| 11 |
-
except ImportError:
|
| 12 |
-
print("โณ PyTorch3D not found. Starting dynamic installation...")
|
| 13 |
-
|
| 14 |
-
pyt_version_str = torch.__version__.split("+")[0].replace(".", "")
|
| 15 |
-
version_str = "".join([
|
| 16 |
-
f"py3{sys.version_info.minor}_",
|
| 17 |
-
f"cu{torch.version.cuda.replace('.', '')}_",
|
| 18 |
-
f"pyt{pyt_version_str}"
|
| 19 |
-
])
|
| 20 |
-
|
| 21 |
-
whl_url = f"https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/{version_str}/pytorch3d-0.7.8-cp3{sys.version_info.minor}-cp3{sys.version_info.minor}-linux_x86_64.whl"
|
| 22 |
-
|
| 23 |
-
print(f"๐ Detected Env: {version_str}")
|
| 24 |
-
print(f"โฌ๏ธ Attempting to install from Wheel: {whl_url}")
|
| 25 |
-
|
| 26 |
-
try:
|
| 27 |
-
subprocess.run([sys.executable, "-m", "pip", "install", whl_url], check=True)
|
| 28 |
-
print("โ
PyTorch3D installed via Wheel!")
|
| 29 |
-
except subprocess.CalledProcessError:
|
| 30 |
-
print("โ ๏ธ Wheel installation failed (maybe version mismatch).")
|
| 31 |
-
print("๐จ Falling back to source compilation (this will take a few minutes)...")
|
| 32 |
-
|
| 33 |
-
subprocess.run(
|
| 34 |
-
[sys.executable, "-m", "pip", "install", "--no-build-isolation", "git+https://github.com/facebookresearch/pytorch3d.git@stable"],
|
| 35 |
-
check=True
|
| 36 |
-
)
|
| 37 |
-
print("โ
PyTorch3D installed via Source Build!")
|
| 38 |
-
|
| 39 |
-
# --- ๆง่กๅฎ่ฃ
ๅฝๆฐ ---
|
| 40 |
-
install_pytorch3d()
|
| 41 |
-
|
| 42 |
-
# --- ไธ้ขๆๆฏไฝ ๅๆฌ็ imports ---
|
| 43 |
-
# from unish.pipeline import UniSHPipeline ...
|
| 44 |
-
|
| 45 |
import gradio as gr
|
| 46 |
import os
|
| 47 |
import time
|
|
@@ -88,6 +46,78 @@ def prepare_local_assets():
|
|
| 88 |
|
| 89 |
prepare_local_assets()
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
def install_sam2():
|
| 92 |
try:
|
| 93 |
import sam2
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import subprocess
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import os
|
| 5 |
import time
|
|
|
|
| 46 |
|
| 47 |
prepare_local_assets()
|
| 48 |
|
| 49 |
+
def install_pytorch3d():
|
| 50 |
+
try:
|
| 51 |
+
import pytorch3d
|
| 52 |
+
print("โ
PyTorch3D already installed.")
|
| 53 |
+
return
|
| 54 |
+
except ImportError:
|
| 55 |
+
print("โณ PyTorch3D not found. Starting dynamic installation...")
|
| 56 |
+
|
| 57 |
+
pyt_version_str = torch.__version__.split("+")[0].replace(".", "")
|
| 58 |
+
version_str = "".join([
|
| 59 |
+
f"py3{sys.version_info.minor}_",
|
| 60 |
+
f"cu{torch.version.cuda.replace('.', '')}_",
|
| 61 |
+
f"pyt{pyt_version_str}"
|
| 62 |
+
])
|
| 63 |
+
|
| 64 |
+
whl_url = f"https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/{version_str}/pytorch3d-0.7.8-cp3{sys.version_info.minor}-cp3{sys.version_info.minor}-linux_x86_64.whl"
|
| 65 |
+
|
| 66 |
+
print(f"๐ Detected Env: {version_str}")
|
| 67 |
+
print(f"โฌ๏ธ Attempting to install from Wheel: {whl_url}")
|
| 68 |
+
|
| 69 |
+
try:
|
| 70 |
+
subprocess.run([sys.executable, "-m", "pip", "install", whl_url], check=True)
|
| 71 |
+
print("โ
PyTorch3D installed via Wheel!")
|
| 72 |
+
except subprocess.CalledProcessError:
|
| 73 |
+
print("โ ๏ธ Wheel installation failed (maybe version mismatch).")
|
| 74 |
+
print("๐จ Falling back to source compilation (this will take a few minutes)...")
|
| 75 |
+
|
| 76 |
+
subprocess.run(
|
| 77 |
+
[sys.executable, "-m", "pip", "install", "--no-build-isolation", "git+https://github.com/facebookresearch/pytorch3d.git@stable"],
|
| 78 |
+
check=True
|
| 79 |
+
)
|
| 80 |
+
print("โ
PyTorch3D installed via Source Build!")
|
| 81 |
+
|
| 82 |
+
install_pytorch3d()
|
| 83 |
+
|
| 84 |
+
def install_mmcv():
|
| 85 |
+
try:
|
| 86 |
+
import mmcv
|
| 87 |
+
print(f"โ
mmcv {mmcv.__version__} is already installed.")
|
| 88 |
+
return
|
| 89 |
+
except ImportError:
|
| 90 |
+
print("โณ mmcv not found. Starting dynamic installation...")
|
| 91 |
+
|
| 92 |
+
# 1. Detect environment versions to construct the URL dynamically
|
| 93 |
+
# Example: CUDA 12.1 -> "121", Torch 2.4.0 -> "2.4"
|
| 94 |
+
cuda_ver = torch.version.cuda.replace(".", "")
|
| 95 |
+
torch_ver = ".".join(torch.__version__.split(".")[:2])
|
| 96 |
+
|
| 97 |
+
# 2. Construct the find-links URL matching OpenMMLab's structure
|
| 98 |
+
# Structure: https://download.openmmlab.com/mmcv/dist/cu{CUDA}/torch{TORCH}/index.html
|
| 99 |
+
find_links_url = f"https://download.openmmlab.com/mmcv/dist/cu{cuda_ver}/torch{torch_ver}/index.html"
|
| 100 |
+
|
| 101 |
+
print(f"๐ Detected Env: CUDA={cuda_ver}, Torch={torch_ver}")
|
| 102 |
+
print(f"โฌ๏ธ Installing mmcv==2.2.0 from: {find_links_url}")
|
| 103 |
+
|
| 104 |
+
try:
|
| 105 |
+
# 3. Run pip install with the specific version and dynamic link
|
| 106 |
+
subprocess.run([
|
| 107 |
+
sys.executable, "-m", "pip", "install",
|
| 108 |
+
"mmcv==2.2.0",
|
| 109 |
+
"--find-links", find_links_url
|
| 110 |
+
], check=True)
|
| 111 |
+
print("โ
mmcv installed successfully.")
|
| 112 |
+
|
| 113 |
+
except subprocess.CalledProcessError:
|
| 114 |
+
print("โ ๏ธ Installation failed. The specific version might not exist for this environment.")
|
| 115 |
+
print("๐ Attempting fallback using openmim (auto-resolve mode)...")
|
| 116 |
+
|
| 117 |
+
# Fallback: Install openmim and let it handle the resolution
|
| 118 |
+
subprocess.run([sys.executable, "-m", "pip", "install", "openmim"], check=True)
|
| 119 |
+
subprocess.run(["mim", "install", "mmcv==2.2.0"], check=True)
|
| 120 |
+
|
| 121 |
def install_sam2():
|
| 122 |
try:
|
| 123 |
import sam2
|
requirements.txt
CHANGED
|
@@ -20,6 +20,5 @@ git+https://github.com/EasternJournalist/utils3d.git@3fab839f0be9931dac7c8488eb0
|
|
| 20 |
mmcv==2.2.0
|
| 21 |
fvcore
|
| 22 |
iopath
|
| 23 |
-
git+https://github.com/facebookresearch/pytorch3d.git@stable
|
| 24 |
smplx
|
| 25 |
hydra-core
|
|
|
|
| 20 |
mmcv==2.2.0
|
| 21 |
fvcore
|
| 22 |
iopath
|
|
|
|
| 23 |
smplx
|
| 24 |
hydra-core
|