-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_web.py
More file actions
54 lines (39 loc) · 1.56 KB
/
app_web.py
File metadata and controls
54 lines (39 loc) · 1.56 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
"""Web Server Launcher — Browser-based GUI.
Starts the FastAPI server and opens the GUI in your default browser.
Works on Windows, Linux, macOS, and accessible from Android/iOS on the same network.
Usage:
python app_web.py
python app_web.py --host 0.0.0.0 --port 8000 # accessible from other devices
"""
from __future__ import annotations
import argparse
import os
import threading
import time
import webbrowser
from dotenv import load_dotenv
load_dotenv()
os.environ.setdefault("PYTHONPATH", os.path.dirname(__file__))
def main() -> None:
parser = argparse.ArgumentParser(description="HIC Web GUI")
parser.add_argument("--host", default="127.0.0.1", help="Server host")
parser.add_argument("--port", type=int, default=8765, help="Server port")
parser.add_argument("--no-browser", action="store_true", help="Don't open browser")
args = parser.parse_args()
import uvicorn
from src.web.api import app
url = f"http://{args.host}:{args.port}"
if args.host == "0.0.0.0":
import socket
local_ip = socket.gethostbyname(socket.gethostname())
print(f"\n 📱 Android/Mobile access: http://{local_ip}:{args.port}")
print(f" 🌐 Local access: {url}")
print(" Press Ctrl+C to stop\n")
if not args.no_browser:
def open_browser():
time.sleep(1.5)
webbrowser.open(f"http://127.0.0.1:{args.port}")
threading.Thread(target=open_browser, daemon=True).start()
uvicorn.run(app, host=args.host, port=args.port, log_level="info")
if __name__ == "__main__":
main()