File size: 1,259 Bytes
3883c60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from webui.ui.ui import create_ui
from .args import args
import gradio


def launch_webui():
    auth = (args.username, args.password) if args.username else None

    template_response_original = gradio.routes.templates.TemplateResponse

    # Magic monkeypatch
    import webui.extensionlib.extensionmanager as em
    scripts = ''.join([f'<script type="module" src="file={s}"></script>' for s in ['scripts/script.js'] + em.get_scripts()])

    def template_response(*args, **kwargs):
        res = template_response_original(*args, **kwargs)
        res.body = res.body.replace(b'</body>',
                                    f'{scripts}</body>'.encode("utf8"))
        res.init_headers()
        return res

    gradio.routes.templates.TemplateResponse = template_response

    import webui.extensionlib.callbacks as cb
    cb.get_manager('webui.init')()

    create_ui(args.theme).queue().launch(share=args.share,
                                         auth=auth,
                                         server_name='0.0.0.0' if args.listen else None,
                                         server_port=args.port,
                                         favicon_path='assets/logo.png',
                                         inbrowser=args.launch)