-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
67 lines (55 loc) · 1.57 KB
/
run.py
File metadata and controls
67 lines (55 loc) · 1.57 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
from g4f.gui import run_gui
import sys
import os.path
import webview
try:
from platformdirs import user_config_dir
has_platformdirs = True
except ImportError:
has_platformdirs = False
import threading
from g4f.gui.gui_parser import gui_parser
from g4f.gui.server.js_api import JsApi
import g4f.version
import g4f.debug
from flask import url_for
import atexit
def on_closed():
print("Stop Server...")
def run_webview(
debug: bool = False,
http_port: int = None,
ssl: bool = True,
storage_path: str = None,
gui: str = None
):
webview.settings['OPEN_EXTERNAL_LINKS_IN_BROWSER'] = True
webview.settings['ALLOW_DOWNLOADS'] = True
# f"g4f - {g4f.version.utils.current_version}",
webview.create_window(
"FreeAI App",
"http://127.0.0.1:8080/chat/",
text_select=True,
js_api=JsApi(),
width=1100, height=700
)
if has_platformdirs and storage_path is None:
storage_path = user_config_dir("g4f-webview")
webview.start(
private_mode=False,
storage_path=storage_path,
debug=debug,
http_port=http_port,
ssl=ssl,
gui=gui
)
if __name__ == "__main__":
atexit.register(on_closed)
server = threading.Thread(target=run_gui)
server.daemon = True
server.start()
parser = gui_parser()
args = parser.parse_args()
if args.debug:
g4f.debug.logging = True
run_webview(debug=args.debug, http_port=args.port, ssl=True, storage_path=None, gui=None)