diff --git a/install.py b/install.py index 8b7f942..c60b3f0 100644 --- a/install.py +++ b/install.py @@ -1,20 +1,37 @@ -import launch -import os +import subprocess +import os, sys import pkg_resources -import sys from tqdm import tqdm import urllib.request req_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "requirements.txt") -import os - models_dir = os.path.abspath("models/roop") model_url = "https://huggingface.co/henryruhs/roop/resolve/main/inswapper_128.onnx" model_name = os.path.basename(model_url) model_path = os.path.join(models_dir, model_name) +def run_pip(*args): + subprocess.run([sys.executable, "-m", "pip", "install", *args]) + +def is_installed ( + package: str, version: str | None = None +): + has_package = None + try: + has_package = pkg_resources.get_distribution(package) + if has_package is not None: + installed_version = has_package.version + if installed_version != version: + return False + else: + return True + else: + return False + except: + return False + def download(url, path): request = urllib.request.urlopen(url) total = int(request.headers.get('Content-Length', 0)) @@ -27,28 +44,23 @@ if not os.path.exists(models_dir): if not os.path.exists(model_path): download(model_url, model_path) +print("Checking Roop-GE requirements...") with open(req_file) as file: + install_count = 0 for package in file: + package_version = None try: package = package.strip() - if "==" in package: - package_name, package_version = package.split('==') - installed_version = pkg_resources.get_distribution(package_name).version - if installed_version != package_version: - print( - f"Running install of {package}, {installed_version} vs {package_version}" - ) - launch.run_pip( - f"install {package}", - f"sd-webui-roop-nsfw requirement: changing {package_name} version from {installed_version} to {package_version}" - ) - elif not launch.is_installed(package): - launch.run_pip(f"install {package}", f"sd-webui-roop-nsfw requirement: {package}") - + package_version = package.split('==')[1] + if not is_installed(package,package_version): + install_count += 1 + run_pip(package) except Exception as e: print(e) - print(f"Warning: Failed to install {package}, nsfw-roop will not work.") + print(f"Warning: Failed to install {package}, Roop-GE will not work.") raise e - # finally: - # print(f'{package} - ok') + if install_count > 0: + print(f'\n--- PLEASE, RESTART the Server! ---\n') + else: + print('Done!') diff --git a/requirements.txt b/requirements.txt index e5ca8f0..661461e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,3 @@ onnx==1.14.0 onnxruntime==1.15.0 opencv-python==4.7.0.72 diffusers==0.17.1 -tqdm diff --git a/scripts/roop_logging.py b/scripts/roop_logging.py index cd547f7..08aca39 100644 --- a/scripts/roop_logging.py +++ b/scripts/roop_logging.py @@ -36,6 +36,6 @@ if not logger.handlers: logger.addHandler(handler) # Configure logger -loglevel_string = getattr(shared.cmd_opts, "controlnet_loglevel", "INFO") +loglevel_string = getattr(shared.cmd_opts, "roop_loglevel", "INFO") loglevel = getattr(logging, loglevel_string.upper(), "info") logger.setLevel(loglevel)