MatverseHub commited on
Commit
d5b79ad
·
verified ·
1 Parent(s): cfb176e
README_BIGBANG_WIRING.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MatVerse Big‑Bang Wiring (core → dataset → Space)
2
+
3
+ Você já tem os quatro nós (Space, Dataset, core, WebX). O que falta para **existir de verdade** é **circulação**:
4
+
5
+ 1) **core** produz métricas reais e um *receipt* auditável.
6
+ 2) **dataset (WebX)** recebe essas métricas como artefatos versionados.
7
+ 3) **Space (audit)** lê do dataset e renderiza **valores reais** (Ω, Ψ, Θ, CVaR, etc.).
8
+
9
+ Links (rodapé):
10
+ - Space audit: https://huggingface.co/spaces/MatverseHub/audit
11
+ - Dataset WebX: https://huggingface.co/datasets/MatverseHub/WebX
12
+ - Core: https://github.com/matverse-acoa/core
13
+ - WebX: https://github.com/matverse-acoa/Webx
14
+
15
+ ---
16
+
17
+ ## 0) Pré‑requisitos
18
+
19
+ - Token Hugging Face com permissão de escrita no org `MatverseHub`.
20
+ - `hf` CLI instalado.
21
+
22
+ Instalar CLI:
23
+ ```bash
24
+ curl -LsSf https://hf.co/cli/install.sh | bash
25
+ hf auth login
26
+ ```
27
+
28
+ ---
29
+
30
+ ## 1) Gerar `metrics.json` REAL (sem placeholder)
31
+
32
+ Use `scripts/generate_metrics_payload.py`.
33
+
34
+ Exemplos:
35
+
36
+ ### A) A partir de um arquivo JSON existente (ex.: export do core)
37
+ ```bash
38
+ python scripts/generate_metrics_payload.py \
39
+ --in metrics_source.json \
40
+ --out metrics.json \
41
+ --source-repo matverse-acoa/core \
42
+ --source-commit <SHA>
43
+ ```
44
+
45
+ ### B) A partir de um receipt OME‑1 (se você já gera `receipt_ome1.json`)
46
+ ```bash
47
+ python scripts/generate_metrics_payload.py \
48
+ --receipt receipt_ome1.json \
49
+ --out metrics.json \
50
+ --source-repo matverse-acoa/core \
51
+ --source-commit <SHA>
52
+ ```
53
+
54
+ O script valida presença dos campos e força timestamp ISO‑8601.
55
+
56
+ ---
57
+
58
+ ## 2) Publicar no Dataset (WebX)
59
+
60
+ ```bash
61
+ bash scripts/publish_to_hf_dataset.sh \
62
+ MatverseHub/WebX \
63
+ metrics.json \
64
+ --path metrics/metrics.json
65
+ ```
66
+
67
+ Isso cria/atualiza `metrics/metrics.json` no dataset.
68
+
69
+ ---
70
+
71
+ ## 3) Fazer o Space ler do Dataset
72
+
73
+ O arquivo `space/app.py` é uma versão “audit dashboard” que:
74
+ - baixa `metrics/metrics.json` do dataset via `huggingface_hub`,
75
+ - renderiza cards,
76
+ - expõe botão de refresh.
77
+
78
+ Você copia o conteúdo para o repo do Space (MatverseHub/audit) ou aplica o patch em `patches/`.
79
+
80
+ ---
81
+
82
+ ## 4) CI (opcional, mas é o que fecha a antifragilidade)
83
+
84
+ - Workflow no `core` para, a cada `main`, executar OME‑1 e publicar métricas no dataset.
85
+ - Workflow no `Space` para rebuild quando dataset atualizar (ou polling leve).
86
+
87
+ Arquivos em `patches/` incluem exemplos de GitHub Actions.
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from datetime import datetime
3
+
4
+ import gradio as gr
5
+ from huggingface_hub import hf_hub_download
6
+
7
+ DATASET_REPO = "MatverseHub/WebX"
8
+ REMOTE_PATH = "metrics/metrics.json"
9
+
10
+
11
+ def load_metrics():
12
+ local_path = hf_hub_download(repo_id=DATASET_REPO, repo_type="dataset", filename=REMOTE_PATH)
13
+ with open(local_path, "r", encoding="utf-8") as f:
14
+ payload = json.load(f)
15
+ return payload
16
+
17
+
18
+ def render(payload):
19
+ m = payload.get("metrics", {})
20
+ updated_at = payload.get("updated_at") or "?"
21
+ src = payload.get("source", {})
22
+
23
+ lines = []
24
+ lines.append(f"Updated: {updated_at}")
25
+ if src:
26
+ lines.append(f"Source: {src.get('repo','?')}@{src.get('commit','?')}")
27
+ lines.append("")
28
+
29
+ def fmt(key):
30
+ v = m.get(key)
31
+ return "?" if v is None else str(v)
32
+
33
+ lines.append(f"Ω (omega): {fmt('omega')}")
34
+ lines.append(f"Ψ (psi): {fmt('psi')}")
35
+ lines.append(f"Θ (theta): {fmt('theta')}")
36
+ lines.append(f"CVaR: {fmt('cvar')}")
37
+
38
+ # Optional extras
39
+ for extra in ["ccr", "viability", "antifragility", "epsilon", "energy", "tau", "delta_i"]:
40
+ if extra in m:
41
+ lines.append(f"{extra}: {m.get(extra)}")
42
+
43
+ return "\n".join(lines)
44
+
45
+
46
+ with gr.Blocks(title="MatVerse WebX Dashboard") as demo:
47
+ gr.Markdown(
48
+ """
49
+ # MatVerse WebX Dashboard
50
+
51
+ This dashboard pulls **real metrics** from the WebX dataset (`MatverseHub/WebX`).
52
+
53
+ If it shows `?`, your dataset file is missing or malformed.
54
+ """
55
+ )
56
+
57
+ out = gr.Textbox(label="Current Metrics", lines=12)
58
+
59
+ def refresh():
60
+ payload = load_metrics()
61
+ return render(payload)
62
+
63
+ btn = gr.Button("Refresh Metrics")
64
+ btn.click(fn=refresh, outputs=out)
65
+
66
+ # Auto-load on startup
67
+ demo.load(fn=refresh, outputs=out)
68
+
69
+
70
+ demo.launch()
generate_metrics_payload.py ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Generate a canonical metrics payload for the WebX dashboard.
3
+
4
+ Design goals:
5
+ - No hidden magic: deterministic, explicit inputs.
6
+ - Works with either a 'receipt' JSON (OME‑1 style) or a generic metrics JSON.
7
+ - Emits a single canonical JSON with timestamps and minimal provenance.
8
+
9
+ This file is intentionally dependency‑free (stdlib only).
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import argparse
15
+ import json
16
+ import sys
17
+ from dataclasses import dataclass
18
+ from datetime import datetime, timezone
19
+ from pathlib import Path
20
+ from typing import Any, Dict, Optional
21
+
22
+
23
+ ISO_FMT = "%Y-%m-%dT%H:%M:%SZ"
24
+
25
+
26
+ def now_utc_iso() -> str:
27
+ return datetime.now(timezone.utc).strftime(ISO_FMT)
28
+
29
+
30
+ def read_json(path: Path) -> Dict[str, Any]:
31
+ try:
32
+ return json.loads(path.read_text(encoding="utf-8"))
33
+ except Exception as e:
34
+ raise SystemExit(f"Failed to read JSON from {path}: {e}")
35
+
36
+
37
+ def pick(d: Dict[str, Any], keys: list[str]) -> Optional[Any]:
38
+ for k in keys:
39
+ if k in d:
40
+ return d[k]
41
+ return None
42
+
43
+
44
+ def coerce_float(x: Any, field: str) -> float:
45
+ try:
46
+ return float(x)
47
+ except Exception:
48
+ raise SystemExit(f"Field '{field}' must be numeric; got: {x!r}")
49
+
50
+
51
+ @dataclass
52
+ class Provenance:
53
+ source_repo: str
54
+ source_commit: str
55
+ updated_at: str
56
+
57
+
58
+ def build_from_generic(metrics: Dict[str, Any], prov: Provenance) -> Dict[str, Any]:
59
+ # Accept multiple key spellings.
60
+ omega = pick(metrics, ["omega", "Ω", "Omega", "OMEGA"])
61
+ psi = pick(metrics, ["psi", "Ψ", "Psi", "PSI"])
62
+ theta = pick(metrics, ["theta", "Θ", "Theta", "THETA"])
63
+ cvar = pick(metrics, ["cvar", "CVaR", "CVAR"])
64
+
65
+ if omega is None or psi is None or theta is None or cvar is None:
66
+ missing = [
67
+ name
68
+ for name, val in [("omega", omega), ("psi", psi), ("theta", theta), ("cvar", cvar)]
69
+ if val is None
70
+ ]
71
+ raise SystemExit(
72
+ "Missing required metric fields in --in JSON: " + ", ".join(missing)
73
+ )
74
+
75
+ payload = {
76
+ "schema": "matverse.webx.metrics.v1",
77
+ "updated_at": prov.updated_at,
78
+ "source": {"repo": prov.source_repo, "commit": prov.source_commit},
79
+ "metrics": {
80
+ "omega": coerce_float(omega, "omega"),
81
+ "psi": coerce_float(psi, "psi"),
82
+ "theta": coerce_float(theta, "theta"),
83
+ "cvar": coerce_float(cvar, "cvar"),
84
+ },
85
+ }
86
+
87
+ # Optional extras preserved if present.
88
+ extras = {}
89
+ for k in ["ccr", "CCR", "viability", "antifragility", "epsilon", "energy", "tau", "delta_i"]:
90
+ if k in metrics:
91
+ extras[k.lower()] = metrics[k]
92
+ if extras:
93
+ payload["metrics"].update(extras)
94
+
95
+ return payload
96
+
97
+
98
+ def build_from_receipt(receipt: Dict[str, Any], prov: Provenance) -> Dict[str, Any]:
99
+ # Receipt formats vary; we support common patterns.
100
+ # Try direct fields first.
101
+ omega = pick(receipt, ["omega", "Ω"])
102
+ psi = pick(receipt, ["psi", "Ψ"])
103
+ theta = pick(receipt, ["theta", "Θ"])
104
+ cvar = pick(receipt, ["cvar", "CVaR"])
105
+
106
+ # Or nested in a 'metrics' object.
107
+ if isinstance(receipt.get("metrics"), dict):
108
+ m = receipt["metrics"]
109
+ omega = omega if omega is not None else pick(m, ["omega", "Ω"])
110
+ psi = psi if psi is not None else pick(m, ["psi", "Ψ"])
111
+ theta = theta if theta is not None else pick(m, ["theta", "Θ"])
112
+ cvar = cvar if cvar is not None else pick(m, ["cvar", "CVaR"])
113
+
114
+ if omega is None or psi is None or theta is None or cvar is None:
115
+ raise SystemExit(
116
+ "Receipt does not expose omega/psi/theta/cvar (directly or under 'metrics')."
117
+ )
118
+
119
+ merkle_root = pick(receipt, ["merkle_root", "merkle", "root"])
120
+ ledger_path = pick(receipt, ["ledger", "ledger_path", "rb_ledger"])
121
+ ohash = pick(receipt, ["ohash", "OHASH"])
122
+
123
+ payload = {
124
+ "schema": "matverse.webx.metrics.v1",
125
+ "updated_at": prov.updated_at,
126
+ "source": {"repo": prov.source_repo, "commit": prov.source_commit},
127
+ "artifacts": {
128
+ "receipt": "receipt.json",
129
+ "merkle_root": merkle_root,
130
+ "ledger": ledger_path,
131
+ "ohash": ohash,
132
+ },
133
+ "metrics": {
134
+ "omega": coerce_float(omega, "omega"),
135
+ "psi": coerce_float(psi, "psi"),
136
+ "theta": coerce_float(theta, "theta"),
137
+ "cvar": coerce_float(cvar, "cvar"),
138
+ },
139
+ }
140
+
141
+ return payload
142
+
143
+
144
+ def main() -> int:
145
+ ap = argparse.ArgumentParser()
146
+ ap.add_argument("--in", dest="in_path", help="Generic metrics JSON input")
147
+ ap.add_argument("--receipt", help="Receipt JSON input (OME‑1 style)")
148
+ ap.add_argument("--out", required=True, help="Output metrics.json")
149
+ ap.add_argument("--source-repo", default="matverse-acoa/core")
150
+ ap.add_argument("--source-commit", default="unknown")
151
+ ap.add_argument("--updated-at", default=None)
152
+
153
+ args = ap.parse_args()
154
+
155
+ if not args.in_path and not args.receipt:
156
+ raise SystemExit("Provide either --in <json> or --receipt <json>.")
157
+ if args.in_path and args.receipt:
158
+ raise SystemExit("Provide only one: --in or --receipt.")
159
+
160
+ updated_at = args.updated_at or now_utc_iso()
161
+ prov = Provenance(args.source_repo, args.source_commit, updated_at)
162
+
163
+ if args.in_path:
164
+ data = read_json(Path(args.in_path))
165
+ payload = build_from_generic(data, prov)
166
+ else:
167
+ receipt = read_json(Path(args.receipt))
168
+ payload = build_from_receipt(receipt, prov)
169
+
170
+ out_path = Path(args.out)
171
+ out_path.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
172
+
173
+ print(f"Wrote {out_path} ({payload['schema']})")
174
+ return 0
175
+
176
+
177
+ if __name__ == "__main__":
178
+ raise SystemExit(main())
github_actions_core_publish_metrics.yml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: publish-webx-metrics
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ workflow_dispatch:
7
+ schedule:
8
+ - cron: '*/30 * * * *' # every 30 minutes (adjust)
9
+
10
+ jobs:
11
+ publish:
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: read
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: '3.11'
23
+
24
+ - name: Install
25
+ run: |
26
+ python -m pip install --upgrade pip
27
+ # Use your pinned requirements; adjust if needed
28
+ if [ -f requirements/dev.txt ]; then pip install -r requirements/dev.txt; fi
29
+ if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
30
+
31
+ - name: Run OME-1 (or your chosen experiment)
32
+ run: |
33
+ # Prefer your Makefile targets if present
34
+ if [ -f Makefile ]; then
35
+ make ome1
36
+ else
37
+ python experiments/autopoiesis_ab_test/run_experiment.py --config config.yaml --output results/
38
+ fi
39
+
40
+ - name: Build metrics.json
41
+ run: |
42
+ python scripts/generate_metrics_payload.py \
43
+ --receipt receipt_ome1.json \
44
+ --out metrics.json \
45
+ --source-repo matverse-acoa/core \
46
+ --source-commit ${{ github.sha }}
47
+
48
+ - name: Install HF CLI
49
+ run: |
50
+ curl -LsSf https://hf.co/cli/install.sh | bash
51
+
52
+ - name: Upload to HF dataset
53
+ env:
54
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
55
+ run: |
56
+ hf auth login --token "$HF_TOKEN" --add-to-git-credential
57
+ hf upload MatverseHub/WebX metrics.json --repo-type=dataset --path metrics/metrics.json
metrics.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metrics": {
3
+ "antifragility": 0.88,
4
+ "cvar": 0.18,
5
+ "delta_i": 128,
6
+ "energy": 12.4,
7
+ "epsilon": 0.05,
8
+ "omega": 0.73,
9
+ "psi": 0.61,
10
+ "tau": 3600,
11
+ "theta": 0.42,
12
+ "viability": 0.91
13
+ },
14
+ "schema": "matverse.webx.metrics.v1",
15
+ "source": {
16
+ "commit": "EXAMPLE",
17
+ "repo": "matverse-acoa/core"
18
+ },
19
+ "updated_at": "2026-01-08T00:57:43Z"
20
+ }
metrics_source_example.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "omega": 0.73,
3
+ "psi": 0.61,
4
+ "theta": 0.42,
5
+ "cvar": 0.18,
6
+ "viability": 0.91,
7
+ "antifragility": 0.88,
8
+ "epsilon": 0.05,
9
+ "energy": 12.4,
10
+ "tau": 3600,
11
+ "delta_i": 128
12
+ }
publish_to_hf_dataset.sh ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ if [[ $# -lt 2 ]]; then
5
+ echo "Usage: $0 <dataset_repo> <file> [--path <remote_path>]" >&2
6
+ echo "Example: $0 MatverseHub/WebX metrics.json --path metrics/metrics.json" >&2
7
+ exit 2
8
+ fi
9
+
10
+ DATASET_REPO="$1"
11
+ LOCAL_FILE="$2"
12
+ shift 2
13
+
14
+ REMOTE_PATH=""
15
+ if [[ ${1:-} == "--path" ]]; then
16
+ REMOTE_PATH="${2:-}"
17
+ fi
18
+
19
+ if [[ ! -f "$LOCAL_FILE" ]]; then
20
+ echo "File not found: $LOCAL_FILE" >&2
21
+ exit 2
22
+ fi
23
+
24
+ # Default remote path
25
+ if [[ -z "$REMOTE_PATH" ]]; then
26
+ REMOTE_PATH="$(basename "$LOCAL_FILE")"
27
+ fi
28
+
29
+ # Requires hf CLI auth with write permission.
30
+
31
+ hf upload "$DATASET_REPO" "$LOCAL_FILE" --repo-type=dataset --path "$REMOTE_PATH"
32
+
33
+ echo "OK: uploaded $LOCAL_FILE -> hf://datasets/$DATASET_REPO/$REMOTE_PATH"
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ huggingface_hub
space_app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from datetime import datetime
3
+
4
+ import gradio as gr
5
+ from huggingface_hub import hf_hub_download
6
+
7
+ DATASET_REPO = "MatverseHub/WebX"
8
+ REMOTE_PATH = "metrics/metrics.json"
9
+
10
+
11
+ def load_metrics():
12
+ local_path = hf_hub_download(repo_id=DATASET_REPO, repo_type="dataset", filename=REMOTE_PATH)
13
+ with open(local_path, "r", encoding="utf-8") as f:
14
+ payload = json.load(f)
15
+ return payload
16
+
17
+
18
+ def render(payload):
19
+ m = payload.get("metrics", {})
20
+ updated_at = payload.get("updated_at") or "?"
21
+ src = payload.get("source", {})
22
+
23
+ lines = []
24
+ lines.append(f"Updated: {updated_at}")
25
+ if src:
26
+ lines.append(f"Source: {src.get('repo','?')}@{src.get('commit','?')}")
27
+ lines.append("")
28
+
29
+ def fmt(key):
30
+ v = m.get(key)
31
+ return "?" if v is None else str(v)
32
+
33
+ lines.append(f"Ω (omega): {fmt('omega')}")
34
+ lines.append(f"Ψ (psi): {fmt('psi')}")
35
+ lines.append(f"Θ (theta): {fmt('theta')}")
36
+ lines.append(f"CVaR: {fmt('cvar')}")
37
+
38
+ # Optional extras
39
+ for extra in ["ccr", "viability", "antifragility", "epsilon", "energy", "tau", "delta_i"]:
40
+ if extra in m:
41
+ lines.append(f"{extra}: {m.get(extra)}")
42
+
43
+ return "\n".join(lines)
44
+
45
+
46
+ with gr.Blocks(title="MatVerse WebX Dashboard") as demo:
47
+ gr.Markdown(
48
+ """
49
+ # MatVerse WebX Dashboard
50
+
51
+ This dashboard pulls **real metrics** from the WebX dataset (`MatverseHub/WebX`).
52
+
53
+ If it shows `?`, your dataset file is missing or malformed.
54
+ """
55
+ )
56
+
57
+ out = gr.Textbox(label="Current Metrics", lines=12)
58
+
59
+ def refresh():
60
+ payload = load_metrics()
61
+ return render(payload)
62
+
63
+ btn = gr.Button("Refresh Metrics")
64
+ btn.click(fn=refresh, outputs=out)
65
+
66
+ # Auto-load on startup
67
+ demo.load(fn=refresh, outputs=out)
68
+
69
+
70
+ demo.launch()
space_requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ huggingface_hub