forked from thygate/stable-diffusion-webui-depthmap-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
40 lines (33 loc) · 1.54 KB
/
main.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
# This launches DepthMap without the AUTOMATIC1111/stable-diffusion-webui
import argparse
import os
import pathlib
import src.misc
def maybe_chdir():
"""Detects if DepthMap was installed as a stable-diffusion-webui script, but run without current directory set to
the stable-diffusion-webui root. Changes current directory if needed.
This is to avoid re-downloading models and putting results into a wrong folder."""
try:
file_path = pathlib.Path(__file__)
path = file_path.parts
while len(path) > 0 and path[-1] != src.misc.REPOSITORY_NAME:
path = path[:-1]
if len(path) >= 2 and path[-1] == src.misc.REPOSITORY_NAME and path[-2] == "extensions":
path = path[:-2]
listdir = os.listdir(str(pathlib.Path(*path)))
if 'launch.py' in listdir and 'webui.py':
os.chdir(str(pathlib.Path(*path)))
except:
pass
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--share", help="Create public link", action='store_true')
parser.add_argument("--listen", help="Create public link", action='store_true')
parser.add_argument("--no_chdir", help="Do not try to use the root of stable-diffusion-webui", action='store_true')
args = parser.parse_args()
print(f"{src.misc.SCRIPT_FULL_NAME} running in standalone mode!")
if not args.no_chdir:
maybe_chdir()
server_name = "0.0.0.0" if args.listen else None
import src.common_ui
src.common_ui.on_ui_tabs().launch(share=args.share, server_name=server_name)