forked from Haidra-Org/AI-Horde-Worker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bridge_stable_diffusion.py
70 lines (58 loc) · 2.42 KB
/
bridge_stable_diffusion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""This is the bridge, It connects the horde with the ML processing"""
import os
# isort: off
# We need to import the argparser first, as it sets the necessry Switches
from worker.argparser.stable_diffusion import args
# isort: on
from nataili.model_manager.super import ModelManager
from nataili.util.logger import logger, quiesce_logger, set_logger_verbosity
from worker.bridge_data.stable_diffusion import StableDiffusionBridgeData
from worker.workers.stable_diffusion import StableDiffusionWorker
def check_for_old_dir():
models_folder = "models/custom"
compvis_folder = "nataili/compvis"
if not os.path.exists(compvis_folder):
os.makedirs(compvis_folder)
if os.path.exists(models_folder):
print(f"{models_folder} folder exists.")
answer = input(f"Do you want to move its contents to {compvis_folder} (recommended) [Y/N]? ")
if answer.lower() == "y":
import shutil
contents = os.listdir(models_folder)
for item in contents:
shutil.move(os.path.join(models_folder, item), compvis_folder)
print(f"Contents of {models_folder} have been moved to {compvis_folder}.")
answer = input("Do you want to delete the models/ folder (not needed anymore) [Y/N]? ")
if answer.lower() == "y":
shutil.rmtree("models/")
print("models/ folder has been deleted.")
else:
print("old models/ folder left intact.")
else:
print("Existing custom models left in their previous location.")
def main():
set_logger_verbosity(args.verbosity)
quiesce_logger(args.quiet)
# TODO: Remove check after fully deprecating arg.
if args.skip_md5:
logger.warning("DeprecationWarning: `--skip_md5` has been deprecated. Please use `--skip_checksum` instead.")
bridge_data = StableDiffusionBridgeData()
model_manager = ModelManager(
clip=True,
compvis=True,
diffusers=True,
esrgan=True,
gfpgan=True,
safety_checker=True,
codeformer=True,
controlnet=True,
)
try:
worker = StableDiffusionWorker(model_manager, bridge_data)
worker.start()
except KeyboardInterrupt:
logger.info("Keyboard Interrupt Received. Ending Process")
logger.init(f"{bridge_data.worker_name} Instance", status="Stopped")
if __name__ == "__main__":
check_for_old_dir()
main()