Files
Robot_Arm/ml/serve.py
T

18 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""本地预览查看器(带 COOP/COEP 头 → 页面跨源隔离 → onnxruntime-web 可用多线程 wasm)
python ml/serve.py [端口=8000] 然后打开 http://localhost:8000/?policy=1
注:跨源隔离下从 CDN 加载 ort.min.js 需要 CDN 返回 CORP 头;jsDelivr 支持。若被拦,用 &ortLocal=1 并把
onnxruntime-web 的 dist 文件(ort.min.js、ort-wasm-simd-threaded*.wasm/.mjs)放到 webapp/vendor/ort/。"""
import http.server, os, sys
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'webapp'))
class H(http.server.SimpleHTTPRequestHandler):
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', 'cross-origin')
self.send_header('Cache-Control', 'no-store')
super().end_headers()
extensions_map = {**http.server.SimpleHTTPRequestHandler.extensions_map, '.wasm': 'application/wasm', '.mjs': 'text/javascript'}
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
print(f'http://localhost:{port}/?policy=1')
http.server.ThreadingHTTPServer(('', port), H).serve_forever()