-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclient.py
More file actions
99 lines (74 loc) · 2.03 KB
/
Copy pathclient.py
File metadata and controls
99 lines (74 loc) · 2.03 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
import sys
import ctypes
import asyncio
import argparse
import traceback
from aiohttp import web
import wx
from main import create_app
from sd_model_manager.utils.common import get_config
import gui.patch
from gui.app import App
try:
ctypes.windll.shcore.SetProcessDpiAwareness(True)
except:
pass
parser = argparse.ArgumentParser()
parser.add_argument(
"-l",
"--listen",
type=str,
default="127.0.0.1",
help="Address for model manager server",
)
parser.add_argument("-p", "--port", type=int, help="Port for model manager server")
parser.add_argument(
"-m",
"--mode",
type=str,
default="standalone",
help="Runtime mode ('standalone', 'noserver', 'comfyui')",
)
async def init_server():
server = await create_app([])
host = server["config"].listen
port = server["config"].port
runner = web.AppRunner(server)
await runner.setup()
site = web.TCPSite(runner, host, port)
await site.start()
return server
app = None
def exception_handler(exception_type, exception_value, exception_traceback):
global app
msg = "An error has occurred!\n\n"
tb = traceback.format_exception(
exception_type, exception_value, exception_traceback
)
for i in tb:
msg += i
parent = None
if app is not None:
parent = app.frame
dlg = wx.MessageDialog(parent, msg, str(exception_type), wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
async def main():
global app
config = parser.parse_args()
use_internal_server = config.mode != "noserver" and config.mode != "comfyui"
is_comfyui = config.mode == "comfyui"
if config.port is None:
config.port = 8188 if is_comfyui else 7779
server = None
if use_internal_server:
server = await init_server()
app = App(server, config, redirect=False)
sys.excepthook = exception_handler
try:
await app.MainLoop()
except asyncio.exceptions.CancelledError:
pass
if __name__ == "__main__":
asyncio.run(main())