第 275 行模板字符串内嵌字符串字面量少一个右单引号:
fill="${get('--panel-2)}" ❌ 语法错误 → 整个 script 不执行
fill="${get('--panel-2')}" ✅ 修
修复前症状(Playwright 实测):
- pageerror: SyntaxError: Invalid or unexpected token
- 初始 textarea 完全为空(loadExample 未跑)
- 点击「加载示例」无任何反应
- 点击「运行」无反应
修复后实测:
- bank textarea 自动填入 109 字符(10 行示例)
- shop textarea 自动填入 77 字符(9 行示例)
- 点击 #btn-run 后 statTime=77ms / statIntersect=6 / statWhere=3 / statGroup=3
- 无 JS 报错
尚数网算子集市
统一入口。前端是自包含 HTML(不依赖任何 CDN / 框架),后端是真算法 (
nax.crypto/nax.data/nax.ml/nax.sql/nax.policy),所有动画 都跑在真计算结果的中间状态之上。12 个算子 = 100% 覆盖 nax 官方
examples/01_~12_。
启动
/Users/xs/.workbuddy/binaries/python/envs/nax-psi-demo/bin/python \
/Users/xs/Desktop/ssw/demo/server.py --host 0.0.0.0 --port 18850
依赖 Python venv(nax-psi-demo):pip install flask numpy pandas。
server.py 内部自动把 ../nax 加进 sys.path,无需手动配置。
访问
| URL | 内容 |
|---|---|
http://127.0.0.1:18850/ |
尚数网算子集市导航首页(12 卡片 · 3 区:基础原语/联邦学习/隐私检索) |
http://127.0.0.1:18850/psi/ |
PSI 求交演示(7 阶段动画 + manual/nax_data/compare 三种算法) |
http://127.0.0.1:18850/scql/ |
SCQL 安全 SQL(5 阶段:输入→PSI JOIN→WHERE→GROUP BY→reveal) |
http://127.0.0.1:18850/pir/ |
PIR 隐匿查询(1-out-of-N + Paillier 同态) |
http://127.0.0.1:18850/vertical_lr/ |
纵向 LR(hospital+insurer 密文训练 vs 明文对照) |
http://127.0.0.1:18850/horizontal_fedavg/ |
横向 FedAvg(mask / paillier 两种安全聚合) |
http://127.0.0.1:18850/dp_fedavg/ |
DP-FedAvg(噪声 ↔ 准确 ↔ 隐私 三角权衡) |
http://127.0.0.1:18850/secure_mlp/ |
Secure MLP(密文神经网络训练) |
http://127.0.0.1:18850/hetero_binning/ |
异构分箱 + WOE/IV(评分卡第一道工序) |
http://127.0.0.1:18850/policy_audit/ |
出域策略守卫 + 审计日志 |
http://127.0.0.1:18850/hello/ |
Hello MPC(三方密文算术入门) |
http://127.0.0.1:18850/dry_run/ |
Dry Run 试跑(真实 MPC vs 明文快路) |
http://127.0.0.1:18850/k8s_two_party/ |
k8s 跨方部署(部署指引) |
算子级别
| 级别 | 含义 | 模块 |
|---|---|---|
| L1 完整动画 | 5-6 节点流程图 + 完整表格 + 关键中间值 | PSI · SCQL · PIR · 纵向 LR |
| L2 简化流程 | 3-4 节点流程图 + 关键表格 | FedAvg · DP-FedAvg · SecureMLP · 异构分箱 · 策略审计 |
| L3 最小 demo | 输入 + 输出 + 文字说明 | Hello MPC · Dry Run |
| L4 部署指引 | 外部链接 / README | k8s 跨方 |
目录结构
demo/
├── server.py ← 统一入口(注册 12 个 blueprint)
├── index.html ← 导航首页(尚数网算子集市)
├── README.md ← 本文件
├── _shared/demo.css ← 12 个子模块共享 CSS
├── screenshots/ ← 导航 + 5 个子页快照
├── psi/ ← L1 · 完整 7 阶段动画
│ ├── __init__.py / app.py / index.html / PROTOCOL.md / requirements.txt
│ └── screenshots/ ← tick-{0..7}.png + flash 帧 + compare 面板
├── scql/ ← L1 · 5 阶段
│ ├── __init__.py / app.py / index.html
├── pir/ ← L1 · 1-out-of-N
│ ├── __init__.py / app.py / index.html
├── vertical_lr/ ← L1 · 密文 vs 明文对照
│ ├── __init__.py / app.py / index.html
├── horizontal_fedavg/ ← L2 · mask + paillier
│ ├── __init__.py / app.py / index.html
├── dp_fedavg/ ← L2 · 噪声 ↔ 准确 ↔ 隐私
│ ├── __init__.py / app.py / index.html
├── secure_mlp/ ← L2 · 密文神经网络
│ ├── __init__.py / app.py / index.html
├── hetero_binning/ ← L2 · WOE / IV
│ ├── __init__.py / app.py / index.html
├── policy_audit/ ← L2 · 出域守卫 + 审计
│ ├── __init__.py / app.py / index.html
├── hello/ ← L3 · 三方密文算术
│ ├── __init__.py / app.py / index.html
├── dry_run/ ← L3 · 双阶段执行
│ ├── __init__.py / app.py / index.html
└── k8s_two_party/ ← L4 · 部署指引
├── __init__.py / app.py / index.html
加新算法模块(扩展点)
在 demo/ 下新建子目录 demo/<algo>/:
demo/<algo>/
├── __init__.py ← 空即可
├── app.py ← Flask Blueprint,含 <algo>_bp
└── index.html ← 自包含演示页
然后在 demo/server.py 加一行注册:
from <algo>.app import <algo>_bp
app.register_blueprint(<algo>_bp, url_prefix="/<algo>")
约定:
- HTML 入口:
GET /<algo>/(顶层 server 自动send_from_directory) - API:
POST /<algo>/api/...(Blueprint 内url_prefix='/algo'后只写/api/...) - 共享 CSS:
/demo/_shared/demo.css通用(暗主题、表格、流程图样式) - 共享 logo:
<img src="https://shangshuwang.cn/images/logo-white-data.png" />直接用
已知坑
- 后台进程被 WorkBuddy 砍:用 Bash tool 的
run_in_background=true启 server,比nohup &稳 - 端口 18850 占用:先
pkill -9 -f demo/server.py再重启 - macOS Firewall:Python 首次对外开 18850 端口会触发弹窗,必须点 Allow;venv python 已通过
socketfilterfw --add加进允许列表 - Flask 单线程会卡:本 server 启
threaded=True - nax.data / nax.ml 必须在 nax.init() 之后才能 import:子模块 app.py 都用
try: nax.shutdown() finally清理 - nax 默认 backend='LocalBackend'(小写 'l'),不是 'local'(小写 l 是 server backend 名字,要看 nax 实际支持)
