summaryrefslogtreecommitdiffstats
path: root/g4f/gui/webview.py
blob: 16f143c47a673113c628131be44af9dd53f86065 (plain) (blame)
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
import webview
from functools import partial
try:
    from platformdirs import user_config_dir
    has_platformdirs = True
except ImportError:
    has_platformdirs = False

from g4f.gui import run_gui
from g4f.gui.run import gui_parser
import g4f.version
import g4f.debug

def run_webview(
    host: str = "0.0.0.0",
    port: int = 8080,
    debug: bool = False,
    storage_path: str = None
):
    webview.create_window(
        f"g4f - {g4f.version.utils.current_version}",
        f"http://{host}:{port}/",
        text_select=True
    )
    if has_platformdirs and storage_path is None:
        storage_path = user_config_dir("g4f-webview")
    webview.start(
        partial(run_gui, host, port),
        private_mode=False,
        storage_path=storage_path,
        debug=debug
    )

if __name__ == "__main__":
    parser = gui_parser()
    args = parser.parse_args()
    if args.debug:
        g4f.debug.logging = True
    run_webview(args.host, args.port, args.debug)