Refactor package installation to use dict and loop

main
Uminosachi 2024-05-09 21:18:39 +09:00
parent bfe7222bcc
commit aa077dd54c
2 changed files with 25 additions and 90 deletions

View File

@ -1,91 +1,26 @@
import launch
if not launch.is_installed("accelerate"):
try:
launch.run_pip("install accelerate", "requirements for accelerate")
except Exception:
print("Can't install accelerate. Please follow the readme to install manually")
required_packages = {
"accelerate": "accelerate",
"diffusers": "diffusers",
"huggingface_hub": "huggingface-hub",
"numpy": "numpy",
"cv2": "opencv-python",
"PIL": "Pillow",
"segment_anything": "segment-anything",
"transformers": "transformers",
"ultralytics": "ultralytics",
"tqdm": "tqdm",
"packaging": "packaging",
"loguru": "loguru",
"rich": "rich",
"pydantic": "pydantic",
"timm": "timm",
}
if not launch.is_installed("diffusers"):
try:
launch.run_pip("install diffusers", "requirements for diffusers")
except Exception:
print("Can't install diffusers. Please follow the readme to install manually")
if not launch.is_installed("huggingface_hub"):
try:
launch.run_pip("install huggingface-hub", "requirements for huggingface_hub")
except Exception:
print("Can't install huggingface-hub. Please follow the readme to install manually")
if not launch.is_installed("numpy"):
try:
launch.run_pip("install numpy", "requirements for numpy")
except Exception:
print("Can't install numpy. Please follow the readme to install manually")
if not launch.is_installed("cv2"):
try:
launch.run_pip("install opencv-python", "requirements for cv2")
except Exception:
print("Can't install opencv-python. Please follow the readme to install manually")
if not launch.is_installed("PIL"):
try:
launch.run_pip("install Pillow", "requirements for PIL")
except Exception:
print("Can't install Pillow. Please follow the readme to install manually")
if not launch.is_installed("segment_anything"):
try:
launch.run_pip("install segment-anything", "requirements for segment_anything")
except Exception:
print("Can't install segment-anything. Please follow the readme to install manually")
if not launch.is_installed("transformers"):
try:
launch.run_pip("install transformers", "requirements for transformers")
except Exception:
print("Can't install transformers. Please follow the readme to install manually")
if not launch.is_installed("loguru"):
try:
launch.run_pip("install loguru", "requirements for loguru")
except Exception:
print("Can't install loguru. Please follow the readme to install manually")
if not launch.is_installed("rich"):
try:
launch.run_pip("install rich", "requirements for rich")
except Exception:
print("Can't install rich. Please follow the readme to install manually")
if not launch.is_installed("pydantic"):
try:
launch.run_pip("install pydantic", "requirements for pydantic")
except Exception:
print("Can't install pydantic. Please follow the readme to install manually")
if not launch.is_installed("timm"):
try:
launch.run_pip("install timm", "requirements for timm")
except Exception:
print("Can't install timm. Please follow the readme to install manually")
if not launch.is_installed("ultralytics"):
try:
launch.run_pip("install ultralytics", "requirements for ultralytics")
except Exception:
print("Can't install ultralytics. Please follow the readme to install manually")
if not launch.is_installed("tqdm"):
try:
launch.run_pip("install tqdm", "requirements for tqdm")
except Exception:
print("Can't install tqdm. Please follow the readme to install manually")
if not launch.is_installed("packaging"):
try:
launch.run_pip("install packaging", "requirements for packaging")
except Exception:
print("Can't install packaging. Please follow the readme to install manually")
for package in required_packages:
if not launch.is_installed(package):
try:
launch.run_pip(f"install {required_packages[package]}", f"requirements for {package}")
except Exception:
print(f"Can't install {required_packages[package]}. Please follow the readme to install manually")

View File

@ -17,8 +17,6 @@ import torch
from diffusers import (DDIMScheduler, EulerAncestralDiscreteScheduler, EulerDiscreteScheduler,
KDPM2AncestralDiscreteScheduler, KDPM2DiscreteScheduler,
StableDiffusionInpaintPipeline)
from lama_cleaner.model_manager import ModelManager
from lama_cleaner.schema import Config, HDStrategy, LDMSampler, SDSampler
from modules import devices, script_callbacks, shared
from modules.processing import create_infotext, process_images
from modules.sd_models import get_closet_checkpoint_match
@ -43,6 +41,8 @@ from ia_webui_controlnet import (backup_alwayson_scripts, clear_controlnet_cache
disable_all_alwayson_scripts, disable_alwayson_scripts_wo_cn,
find_controlnet, get_controlnet_args_to, get_max_args_to,
get_sd_img2img_processing, restore_alwayson_scripts)
from lama_cleaner.model_manager import ModelManager
from lama_cleaner.schema import Config, HDStrategy, LDMSampler, SDSampler
@clear_cache_decorator