Download web/serve.py from tsdocode/trada-tts: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/tsdocode/trada-tts/resolve/main/web/serve.py
- Command line
-
hf download hf://tsdocode/trada-tts/web/serve.py
-
curl -L -o serve.py https://huggingface.co/tsdocode/trada-tts/resolve/main/web/serve.py
1.83 kB
| """Serve the Trà Đá web demo locally: python web/serve.py [port] [host] -> http://localhost:8000 | |
| Serves the repo root (the page loads ../onnx, ../voices, ../config.json) with the COOP/COEP headers that | |
| multi-threaded WASM needs and the right MIME types. WebGPU and the microphone need localhost or https.""" | |
| import http.server, os, socketserver, sys | |
| PORT = int(sys.argv[1]) if len(sys.argv) > 1 else 8000 | |
| HOST = sys.argv[2] if len(sys.argv) > 2 else "127.0.0.1" | |
| os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| class H(http.server.SimpleHTTPRequestHandler): | |
| extensions_map = {**http.server.SimpleHTTPRequestHandler.extensions_map, ".mjs": "text/javascript", ".js": "text/javascript", | |
| ".wasm": "application/wasm", ".onnx": "application/octet-stream", ".json": "application/json", ".wav": "audio/wav"} | |
| def do_GET(self): | |
| if self.path in ("/", "/index.html"): | |
| self.send_response(302); self.send_header("Location", "web/"); self.end_headers(); return | |
| super().do_GET() | |
| def end_headers(self): | |
| self.send_header("Cross-Origin-Opener-Policy", "same-origin") | |
| self.send_header("Cross-Origin-Embedder-Policy", "require-corp") | |
| self.send_header("Cross-Origin-Resource-Policy", "same-origin") | |
| self.send_header("Cache-Control", "no-cache") | |
| super().end_headers() | |
| def log_message(self, fmt, *a): | |
| if os.environ.get("TRADA_LOG"): | |
| sys.stderr.write("%s %s %s\n" % (self.headers.get("X-Real-IP") or self.client_address[0], self.headers.get("User-Agent", "")[:60], fmt % a)) | |
| socketserver.ThreadingTCPServer.allow_reuse_address = True | |
| with socketserver.ThreadingTCPServer((HOST, PORT), H) as s: | |
| print(f"Trà Đá TTS demo: http://localhost:{PORT}/web/", flush=True) | |
| s.serve_forever() | |