Spaces:
Build error
Build error
Vo Minh Vu
commited on
Commit
·
091c098
1
Parent(s):
1a93c67
update name wheel to wheels
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ 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
|
|
@@ -18,6 +19,36 @@ from PIL import Image
|
|
| 18 |
from tsr.system import TSR
|
| 19 |
from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# ------------------------------------------------------------
|
| 22 |
# 1. Model & utils initialization (runs at startup)
|
| 23 |
# ------------------------------------------------------------
|
|
|
|
| 5 |
import tempfile
|
| 6 |
import zipfile
|
| 7 |
from functools import partial
|
| 8 |
+
import sys
|
| 9 |
|
| 10 |
from fastapi import FastAPI, File, UploadFile, Form, HTTPException
|
| 11 |
from fastapi.responses import StreamingResponse
|
|
|
|
| 19 |
from tsr.system import TSR
|
| 20 |
from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation
|
| 21 |
|
| 22 |
+
# ----------------------------------------------------------------
|
| 23 |
+
# 0. Bootstrap install of torchmcubes wheel if needed
|
| 24 |
+
# ----------------------------------------------------------------
|
| 25 |
+
|
| 26 |
+
# Compute the path to this file and to your wheels folder
|
| 27 |
+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 28 |
+
WHEELS_DIR = os.path.join(BASE_DIR, "wheels")
|
| 29 |
+
WHL_NAME = "torchmcubes-0.1.0-cp310-cp310-linux_x86_64.whl"
|
| 30 |
+
WHL_PATH = os.path.join(WHEELS_DIR, WHL_NAME)
|
| 31 |
+
|
| 32 |
+
def install_torchmcubes():
|
| 33 |
+
if not os.path.exists(WHL_PATH):
|
| 34 |
+
raise FileNotFoundError(f"Cannot find wheel at {WHL_PATH!r}")
|
| 35 |
+
print(f"[bootstrap] Installing torchmcubes from {WHL_PATH!r} …")
|
| 36 |
+
try:
|
| 37 |
+
subprocess.check_call([
|
| 38 |
+
sys.executable, "-m", "pip", "install",
|
| 39 |
+
"--upgrade", WHL_PATH
|
| 40 |
+
])
|
| 41 |
+
except subprocess.CalledProcessError as e:
|
| 42 |
+
print(f"[bootstrap][ERROR] pip install failed: {e}")
|
| 43 |
+
sys.exit(1)
|
| 44 |
+
|
| 45 |
+
# Try to import, and if missing, install then re-import
|
| 46 |
+
try:
|
| 47 |
+
import torchmcubes
|
| 48 |
+
except ImportError:
|
| 49 |
+
install_torchmcubes()
|
| 50 |
+
import torchmcubes
|
| 51 |
+
|
| 52 |
# ------------------------------------------------------------
|
| 53 |
# 1. Model & utils initialization (runs at startup)
|
| 54 |
# ------------------------------------------------------------
|
{wheel → wheels}/torchmcubes-0.1.0-cp310-cp310-linux_x86_64.whl
RENAMED
|
File without changes
|