2024-10-05 14:23:55 +02:00
|
|
|
from pathlib import Path
|
|
|
|
|
2024-08-28 22:20:36 +02:00
|
|
|
from core.stack import Stack
|
2024-08-28 10:39:27 +02:00
|
|
|
|
|
|
|
|
2024-08-28 22:20:36 +02:00
|
|
|
class BackgroundRemovalDis(Stack):
|
2024-08-28 10:39:27 +02:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__(
|
2024-08-28 22:20:36 +02:00
|
|
|
'Background Removal (DIS)',
|
|
|
|
'background_removal_dis',
|
2024-08-28 10:39:27 +02:00
|
|
|
5005,
|
|
|
|
'https://huggingface.co/spaces/ECCV2022/dis-background-removal'
|
|
|
|
)
|
|
|
|
|
2024-08-29 12:26:37 +02:00
|
|
|
def _install(self):
|
2024-10-05 14:23:55 +02:00
|
|
|
self.git_clone(url=self.url, dest=Path(self.path / "webui"))
|
2024-08-28 10:39:27 +02:00
|
|
|
self.install_requirements("webui/requirements.txt")
|
|
|
|
self.pip_install("gradio") # gradio is not in requirements.txt for some reason
|
|
|
|
|
|
|
|
self.remove_line_in_file("os.", "webui/app.py") # remove manual clone of DIS from app.py (done below)
|
|
|
|
|
2024-10-05 14:23:55 +02:00
|
|
|
self.git_clone("https://github.com/xuebinqin/DIS.git", dest=Path("tmp-dis"))
|
2024-08-28 10:39:27 +02:00
|
|
|
self.move_all_files_in_dir("tmp-dis/IS-Net", "webui")
|
|
|
|
self.remove_dir("tmp-dis")
|
|
|
|
|
|
|
|
self.create_dir("webui/saved_models")
|
|
|
|
self.move_file_or_dir("webui/isnet.pth", "webui/saved_models/isnet.pth")
|
|
|
|
|
|
|
|
# self.remove_dir("webui/.git") # saves a lot of space due to big repo
|
|
|
|
|
2024-08-29 12:26:37 +02:00
|
|
|
def _start(self):
|
2024-10-05 14:23:55 +02:00
|
|
|
self.python(f"app.py", current_dir=Path(self.path / "webui"),
|
2024-08-29 12:03:37 +02:00
|
|
|
env=["TORCH_BLAS_PREFER_HIPBLASLT=0", f"GRADIO_SERVER_PORT={self.port}"], daemon=True)
|