-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (48 loc) · 1.42 KB
/
Copy pathmain.py
File metadata and controls
59 lines (48 loc) · 1.42 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
"""PaperLens - AI-Powered Research Assistant"""
import sys
import os
import threading
import time
if getattr(sys, "frozen", False):
os.chdir(os.path.dirname(sys.executable))
BASE_DIR = getattr(sys, "_MEIPASS", os.path.dirname(sys.executable))
else:
os.chdir(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
from server import create_app
def main():
app = create_app()
port = 51234
server_thread = threading.Thread(
target=lambda: app.run(
host="127.0.0.1", port=port, debug=False, use_reloader=False, threaded=True
),
daemon=True,
)
server_thread.start()
time.sleep(1.5)
try:
import webview
kwargs = {
"title": "PaperLens",
"url": f"http://127.0.0.1:{port}",
"width": 1200,
"height": 800,
"min_size": (800, 600),
"resizable": True,
"text_select": True,
}
webview.create_window(**kwargs)
webview.start(gui="edgechromium", debug=False)
except ImportError:
import webbrowser
webbrowser.open(f"http://127.0.0.1:{port}")
print(f"已在浏览器中打开: http://127.0.0.1:{port}")
print("按 Ctrl+C 退出")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
if __name__ == "__main__":
main()