-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglminit.py
79 lines (61 loc) · 1.82 KB
/
glminit.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
71
72
73
74
75
76
77
78
79
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...')
def predict(ctx, query, max_length, top_p, temperature, use_stream_chat):
ctx.limit_round()
flag = True
from modules.model import infer
for _, output in infer(
query=query,
history=ctx.history,
max_length=max_length,
top_p=top_p,
temperature=temperature,
use_stream_chat=use_stream_chat
):
if flag:
ctx.append(query, output)
flag = False
else:
ctx.update_last(query, output)
yield ctx.rh, ""
ctx.refresh_last()
yield ctx.rh, ""
init()