-
Notifications
You must be signed in to change notification settings - Fork 2
/
webui.py
76 lines (69 loc) · 2.78 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""VFIformer-WebUI Application"""
import os
import time
import signal
import argparse
from typing import Callable
from interpolate_engine import InterpolateEngine
from webui_utils.simple_log import SimpleLog
from webui_utils.simple_config import SimpleConfig
from webui_utils.file_utils import create_directories
from create_ui import create_ui
from webui_tips import WebuiTips
def main():
"""Run the application"""
parser = argparse.ArgumentParser(description='VFIformer Web UI')
parser.add_argument("--config_path", type=str, default="config.yaml",
help="path to config YAML file")
parser.add_argument("--verbose", dest="verbose", default=False, action="store_true",
help="Show extra details")
args = parser.parse_args()
log = SimpleLog(args.verbose)
config = SimpleConfig(args.config_path).config_obj()
create_directories(config.directories)
WebUI(config, log).start()
class WebUI:
"""Top-Level application logic"""
def __init__(self,
config : SimpleConfig,
log : SimpleLog):
self.config = config
self.log = log
self.restart = False
self.prevent_inbrowser = False
def start(self):
"""Create the UI and start the event loop"""
WebuiTips.set_tips_path(self.config.user_interface["tips_path"])
engine = InterpolateEngine(self.config.model, self.config.gpu_ids)
while True:
print("\nStarting VFIformer-WebUI")
print("Models are loaded on the first interpolation")
app = create_ui(self.config, engine, self.log, self.restart_app)
app.launch(inbrowser = self.config.auto_launch_browser and not self.prevent_inbrowser,
server_name = self.config.server_name,
server_port = self.config.server_port,
prevent_thread_lock=True)
# after initial launch, disable inbrowser for subsequent restarts
self.prevent_inbrowser = True
self.wait_on_server(app)
print("\n--- Restarting\n")
def restart_app(self):
"""Signal to the event loop to restart the application"""
self.restart = True
def wait_on_server(self, app):
"""Restart application if signal is set"""
while True:
time.sleep(0.5)
if self.restart:
self.restart = False
time.sleep(0.5)
app.close()
time.sleep(0.5)
break
def sigint_handler(sig, frame):
"""Make the program just exit at ctrl+c without waiting for anything"""
print(f'Interrupted with signal {sig} in {frame}')
os._exit(0) #pylint: disable=protected-access
signal.signal(signal.SIGINT, sigint_handler)
if __name__ == '__main__':
main()