Spaces:
Build error
Build error
Vo Minh Vu
commited on
Commit
·
c9e158d
1
Parent(s):
9077d48
update torchmcubes
Browse files- app.py +8 -43
- requirements.txt +2 -0
app.py
CHANGED
|
@@ -1,55 +1,20 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
-
import
|
| 3 |
import subprocess
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
# 1) Locate the wheel relative to this file
|
| 10 |
-
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 11 |
-
WHEELS_DIR = os.path.join(BASE_DIR, "wheels")
|
| 12 |
-
WHL_NAME = "torchmcubes-0.1.0-cp310-cp310-linux_x86_64.whl"
|
| 13 |
-
WHL_PATH = os.path.join(WHEELS_DIR, WHL_NAME)
|
| 14 |
|
| 15 |
-
def install_torchmcubes_wheel(whl_path: str):
|
| 16 |
-
"""
|
| 17 |
-
Installs the given wheel via pip. Exits on failure.
|
| 18 |
-
"""
|
| 19 |
-
if not os.path.exists(whl_path):
|
| 20 |
-
raise FileNotFoundError(f"Cannot find torchmcubes wheel at {whl_path!r}")
|
| 21 |
-
print(f"[bootstrap] Installing torchmcubes from {whl_path!r} …")
|
| 22 |
-
try:
|
| 23 |
-
subprocess.check_call([
|
| 24 |
-
sys.executable, "-m", "pip", "install",
|
| 25 |
-
"--upgrade", whl_path
|
| 26 |
-
])
|
| 27 |
-
except subprocess.CalledProcessError as e:
|
| 28 |
-
print(f"[bootstrap][ERROR] pip install failed: {e}")
|
| 29 |
-
sys.exit(1)
|
| 30 |
-
|
| 31 |
-
# 2) Try import, install if missing
|
| 32 |
-
try:
|
| 33 |
-
import torchmcubes
|
| 34 |
-
except ImportError:
|
| 35 |
-
install_torchmcubes_wheel(WHL_PATH)
|
| 36 |
-
import torchmcubes
|
| 37 |
-
|
| 38 |
-
# ----------------------------------------------------------------
|
| 39 |
-
# 1. Now safe to import the rest of your dependencies
|
| 40 |
-
# ----------------------------------------------------------------
|
| 41 |
-
import io
|
| 42 |
-
import zipfile
|
| 43 |
-
import tempfile
|
| 44 |
import numpy as np
|
| 45 |
import rembg
|
| 46 |
import torch
|
| 47 |
from PIL import Image
|
| 48 |
|
| 49 |
-
from fastapi import FastAPI, File, UploadFile, Form, HTTPException
|
| 50 |
-
from fastapi.responses import StreamingResponse
|
| 51 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 52 |
-
|
| 53 |
from tsr.system import TSR
|
| 54 |
from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation
|
| 55 |
|
|
|
|
| 1 |
+
import io
|
| 2 |
import os
|
| 3 |
+
import shlex
|
| 4 |
import subprocess
|
| 5 |
+
import tempfile
|
| 6 |
+
import zipfile
|
| 7 |
+
from functools import partial
|
| 8 |
|
| 9 |
+
from fastapi import FastAPI, File, UploadFile, Form, HTTPException
|
| 10 |
+
from fastapi.responses import StreamingResponse
|
| 11 |
+
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
import numpy as np
|
| 14 |
import rembg
|
| 15 |
import torch
|
| 16 |
from PIL import Image
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
from tsr.system import TSR
|
| 19 |
from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation
|
| 20 |
|
requirements.txt
CHANGED
|
@@ -10,3 +10,5 @@ gradio
|
|
| 10 |
onnxruntime
|
| 11 |
fastapi
|
| 12 |
uvicorn[standard]
|
|
|
|
|
|
|
|
|
| 10 |
onnxruntime
|
| 11 |
fastapi
|
| 12 |
uvicorn[standard]
|
| 13 |
+
--no-binary=torchmcubes
|
| 14 |
+
torchmcubes @ git+https://github.com/tatsy/torchmcubes.git
|