-
Notifications
You must be signed in to change notification settings - Fork 254
/
Copy pathwebui.py
58 lines (43 loc) · 1.28 KB
/
webui.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
import os
import time
import sysconfig
from modules import options
from modules.model import load_model
from modules.options import cmd_opts
from modules.ui import create_ui
# patch PATH for cpm_kernels libcudart lookup
os.environ['PATH'] = os.environ.get("PATH", "") + os.pathsep + os.path.join(sysconfig.get_paths()["purelib"], "torch\lib")
def ensure_output_dirs():
folders = ["outputs/save", "outputs/markdown"]
def check_and_create(p):
if not os.path.exists(p):
os.makedirs(p)
for i in folders:
check_and_create(i)
def init():
ensure_output_dirs()
load_model()
def wait_on_server(ui=None):
while 1:
time.sleep(1)
if options.need_restart:
options.need_restart = False
time.sleep(0.5)
ui.close()
time.sleep(0.5)
break
def main():
while True:
ui = create_ui()
ui.queue(concurrency_count=5, max_size=64).launch(
server_name="0.0.0.0" if cmd_opts.listen else None,
server_port=cmd_opts.port,
share=cmd_opts.share,
prevent_thread_lock=True,
root_path=cmd_opts.path_prefix,
)
wait_on_server(ui)
print('Restarting UI...')
if __name__ == "__main__":
init()
main()