interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / examples / mnist / server.py

36 lines · 1200 bytes Raw Blame History
1import http.server
2import socketserver
3import os
4import sys
5
6DIRECTORY = os.path.abspath(os.path.join(os.path.dirname(__file__), 'web'))
7PORT = 8000
8
9class CustomHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
10 def __init__(self, *args, **kwargs):
11 super().__init__(*args, directory=DIRECTORY, **kwargs)
12
13 def end_headers(self):
14 # Add required headers for SharedArrayBuffer
15 self.send_header("Cross-Origin-Opener-Policy", "same-origin")
16 self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
17 self.send_header("Access-Control-Allow-Origin", "*")
18 super().end_headers()
19
20# Enable address reuse
21class CustomServer(socketserver.TCPServer):
22 allow_reuse_address = True
23
24try:
25 with CustomServer(("", PORT), CustomHTTPRequestHandler) as httpd:
26 print(f"Serving directory '{DIRECTORY}' at http://localhost:{PORT}")
27 print(f"Application context root: http://localhost:{PORT}/")
28 try:
29 httpd.serve_forever()
30 except KeyboardInterrupt:
31 print("\nServer stopped.")
32 # Force complete exit
33 sys.exit(0)
34except OSError as e:
35 print(f"Error: {e}")
36 sys.exit(1)