oc_chat
Loading...
Searching...
No Matches
launch.py
Go to the documentation of this file.
2import os
3import socketserver
4import sys
5import webbrowser
6
7PORT = 8000
8PAGE = "ollama-chat.html"
9
10os.chdir(os.path.dirname(os.path.abspath(__file__)))
11
12url = f"http://localhost:{PORT}/{PAGE}"
13
14class QuietHandler(http.server.SimpleHTTPRequestHandler):
15 def log_message(self, fmt, *args):
16 pass
17
18try:
19 with socketserver.TCPServer(("", PORT), QuietHandler) as httpd:
20 print(f"Serving {PAGE} at {url}")
21 print("Press Ctrl+C to stop.")
22 webbrowser.open_new_tab(url)
23 httpd.serve_forever()
24except KeyboardInterrupt:
25 print("\nStopped.")
26 sys.exit(0)
27except OSError as e:
28 print(f"Could not start server on port {PORT}: {e}")
29 sys.exit(1)
log_message(self, fmt, *args)
Definition launch.py:15