Spaces:
Sleeping
Sleeping
Deploy BASILISC worker: app.py
Browse files
app.py
CHANGED
|
@@ -21,6 +21,36 @@ from PIL import Image
|
|
| 21 |
from torchvision import transforms
|
| 22 |
from transformers import AutoModelForImageSegmentation
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
from mvadapter.models.attention_processor import DecoupledMVRowColSelfAttnProcessor2_0
|
| 25 |
from mvadapter.pipelines.pipeline_mvadapter_i2mv_sdxl import MVAdapterI2MVSDXLPipeline
|
| 26 |
from mvadapter.schedulers.scheduling_shift_snr import ShiftSNRScheduler
|
|
|
|
| 21 |
from torchvision import transforms
|
| 22 |
from transformers import AutoModelForImageSegmentation
|
| 23 |
|
| 24 |
+
# Keep the Space image build simple: fetch a pinned MV-Adapter source snapshot
|
| 25 |
+
# at runtime instead of asking pip to resolve the entire upstream package and
|
| 26 |
+
# its dependency tree during the Hugging Face image build.
|
| 27 |
+
MV_ADAPTER_COMMIT = "4277e0018232bac82bb2c103caf0893cedb711be"
|
| 28 |
+
MV_ADAPTER_ROOT = Path("/tmp/basilisc-mv-adapter")
|
| 29 |
+
|
| 30 |
+
def _ensure_mvadapter_source():
|
| 31 |
+
pkg = MV_ADAPTER_ROOT / "mvadapter"
|
| 32 |
+
if not pkg.is_dir():
|
| 33 |
+
import urllib.request
|
| 34 |
+
import zipfile
|
| 35 |
+
archive = Path("/tmp/basilisc-mv-adapter.zip")
|
| 36 |
+
url = f"https://codeload.github.com/huanngzh/MV-Adapter/zip/{MV_ADAPTER_COMMIT}"
|
| 37 |
+
print(f"Fetching pinned MV-Adapter source: {MV_ADAPTER_COMMIT}", flush=True)
|
| 38 |
+
urllib.request.urlretrieve(url, archive)
|
| 39 |
+
extract_root = Path("/tmp/basilisc-mv-adapter-extract")
|
| 40 |
+
shutil.rmtree(extract_root, ignore_errors=True)
|
| 41 |
+
extract_root.mkdir(parents=True, exist_ok=True)
|
| 42 |
+
with zipfile.ZipFile(archive, "r") as zf:
|
| 43 |
+
zf.extractall(extract_root)
|
| 44 |
+
children = [x for x in extract_root.iterdir() if x.is_dir()]
|
| 45 |
+
if len(children) != 1 or not (children[0] / "mvadapter").is_dir():
|
| 46 |
+
raise RuntimeError("Downloaded MV-Adapter archive had an unexpected layout")
|
| 47 |
+
shutil.rmtree(MV_ADAPTER_ROOT, ignore_errors=True)
|
| 48 |
+
shutil.move(str(children[0]), str(MV_ADAPTER_ROOT))
|
| 49 |
+
if str(MV_ADAPTER_ROOT) not in sys.path:
|
| 50 |
+
sys.path.insert(0, str(MV_ADAPTER_ROOT))
|
| 51 |
+
|
| 52 |
+
_ensure_mvadapter_source()
|
| 53 |
+
|
| 54 |
from mvadapter.models.attention_processor import DecoupledMVRowColSelfAttnProcessor2_0
|
| 55 |
from mvadapter.pipelines.pipeline_mvadapter_i2mv_sdxl import MVAdapterI2MVSDXLPipeline
|
| 56 |
from mvadapter.schedulers.scheduling_shift_snr import ShiftSNRScheduler
|