ggml
[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)
Brought by drakestapleton
ggml / examples / mnist / server.py
| 1 | import http.server |
| 2 | import socketserver |
| 3 | import os |
| 4 | import sys |
| 5 | |
| 6 | DIRECTORY = os.path.abspath(os.path.join(os.path.dirname(__file__), 'web')) |
| 7 | PORT = 8000 |
| 8 | |
| 9 | class 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 |
| 21 | class CustomServer(socketserver.TCPServer): |
| 22 | allow_reuse_address = True |
| 23 | |
| 24 | try: |
| 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) |
| 34 | except OSError as e: |
| 35 | print(f"Error: {e}") |
| 36 | sys.exit(1) |