CoolFace
Apppublic

hololens/stable-diffusion-webui-depthmap-script

sourceHugging Faceupdated 2y agoView on Hugging Face
1likes
install.py79 linesDownload Raw Back to root
1# Installs dependencies
2# Make sure to add to requirements.txt - it can be used for the standalone mode
3
4import launch
5import platform
6import sys
7import importlib.metadata
8
9# TODO: some dependencies apparently being reinstalled on every run. Investigate and fix.
10
11if sys.version_info < (3, 8):
12    launch.run_pip("install importlib-metadata", "importlib-metadata for depthmap script")
13    import importlib_metadata
14else:
15    import importlib.metadata as importlib_metadata
16if not launch.is_installed('packaging'):
17    launch.run_pip("install packaging", "packaging requirement for depthmap script")
18from packaging.version import Version
19
20def ensure(module_name, min_version=None):
21    if launch.is_installed(module_name):
22        if min_version is None or Version(importlib_metadata.version(module_name)) >= Version(min_version):
23            return
24    requirement = f'{module_name}>={min_version}' if min_version is not None else module_name
25    cmd = f'install "{requirement}"'
26    msg = f'{requirement} requirement for depthmap script'
27    launch.run_pip(cmd, msg)
28
29
30ensure('timm', '0.9.2')  # For midas, specified just in case
31
32ensure('matplotlib')
33
34ensure('trimesh')
35
36ensure('numba', '0.57.0')
37ensure('vispy', '0.13.0')
38
39ensure('rembg', '2.0.50')
40
41if not launch.is_installed("moviepy"):
42    launch.run_pip('install "moviepy==1.0.2"', "moviepy requirement for depthmap script")
43ensure('transforms3d', '0.4.1')
44
45ensure('diffusers', '0.20.1')  # For Merigold
46
47ensure('imageio')  # 2.4.1
48try:  # Dirty hack to not reinstall every time
49    importlib_metadata.version('imageio-ffmpeg')
50except:
51    ensure('imageio-ffmpeg')
52
53
54if not launch.is_installed("networkx"):
55    launch.run_pip('install install "networkx==2.5"', "networkx requirement for depthmap script")
56if platform.system() == 'Windows':
57    ensure('pyqt5')
58
59if platform.system() == 'Darwin':
60    ensure('pyqt6')
61    ensure('PyOpenGL', '3.1.7')
62
63# Depth Anything
64def get_installed_version(package: str):
65    try:
66        return importlib.metadata.version(package)
67    except Exception:
68        return None
69def try_install_from_wheel(pkg_name: str, wheel_url: str):
70    if get_installed_version(pkg_name) is not None:
71        return
72    try:
73        launch.run_pip(f"install {wheel_url}", f" {pkg_name} requirement for depthmap script")
74    except Exception as e:
75        print('Failed to install wheel for Depth Anything support. It won\'t work.')
76try_install_from_wheel(
77    "depth_anything",
78    "https://github.com/huchenlei/Depth-Anything/releases/download/v1.0.0/depth_anything-2024.1.22.0-py2.py3-none-any.whl")
79