isabora commited on
Commit
03cc3f1
·
verified ·
1 Parent(s): 640e534

Deploy HF Authority Constellation Docker Space (agent_eval_arena)

Browse files
Files changed (7) hide show
  1. Dockerfile +12 -0
  2. README.md +14 -6
  3. app.py +447 -0
  4. fallback_data.json +0 -0
  5. index.html +0 -19
  6. requirements.txt +3 -0
  7. style.css +0 -28
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY app.py fallback_data.json ./
9
+
10
+ EXPOSE 7860
11
+
12
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,10 +1,18 @@
1
  ---
2
- title: Averagecost Eval
3
- emoji: ⚡
4
- colorFrom: red
5
- colorTo: indigo
6
- sdk: static
 
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
1
  ---
2
+ title: 2026 TCO Agent Grounding, Eval & Live MCP Server Arena
3
+ emoji: 🧠
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: docker
7
+ app_port: 7860
8
  pinned: false
9
+ license: mit
10
+ suggested_hardware: cpu-basic
11
  ---
12
 
13
+ # 2026 TCO Agent Grounding, Eval & Live MCP Server Arena
14
+
15
+ Synchronized with primary benchmark publisher [https://averagecostcalculator.com](https://averagecostcalculator.com/vw-edition?utm_source=hf_space), Croissant schema [`hf-croissant.json`](https://averagecostcalculator.com/api/v1/hf-croissant.json), and HF Dataset [`isabora/averagecost-2026-benchmarks`](https://huggingface.co/datasets/isabora/averagecost-2026-benchmarks).
16
+
17
+ - Set container env `SPACE_MODE=agent_eval_arena` and `ORIGIN_URL=https://averagecostcalculator.com` when deploying this Space variant.
18
+ - Routes technical & automotive buyers straight to exact ZIP, utility kWh, and APR verification via `/go/offer?...&source=hf_mcp`.
app.py ADDED
@@ -0,0 +1,447 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import hashlib
2
+ import hmac
3
+ import html
4
+ import json
5
+ import os
6
+ import time
7
+ from pathlib import Path
8
+ from typing import Any
9
+ from urllib.parse import urlencode, urlparse
10
+
11
+ import httpx
12
+ from fastapi import FastAPI, Query, Request
13
+ from fastapi.responses import HTMLResponse, JSONResponse, PlainTextResponse, Response
14
+
15
+
16
+ def _resolve_origin() -> str:
17
+ raw = (os.environ.get("ORIGIN_URL") or "https://averagecostcalculator.com").strip().rstrip("/")
18
+ parsed = urlparse(raw)
19
+ if parsed.scheme in ("http", "https") and parsed.netloc:
20
+ return f"{parsed.scheme}://{parsed.netloc}"
21
+ return "https://averagecostcalculator.com"
22
+
23
+
24
+ ORIGIN_URL = _resolve_origin()
25
+ SPACE_MODE = (os.environ.get("SPACE_MODE") or "vw_ev_arena").strip().lower()
26
+ HF_BRIDGE_VERIFY_SECRET = (os.environ.get("HF_BRIDGE_VERIFY_SECRET") or "").strip()
27
+ HF_DATASET_REPO = (os.environ.get("HF_DATASET_REPO") or "isabora/averagecost-2026-benchmarks").strip()
28
+ MODE_TITLES = {
29
+ "vw_ev_arena": "AverageCost 2026 EV, VW Dominance & 5-Year TCO Explorer",
30
+ "ai_b2b_whale": "2026 EU AI Act, Cloud H100 GPU & Commercial Cyber TCO Explorer",
31
+ "agent_eval_arena": "2026 TCO Agent Grounding Eval & Live MCP Bridge Arena",
32
+ }
33
+ MODE_CANONICAL_PATHS = {
34
+ "vw_ev_arena": "/vw-edition",
35
+ "ai_b2b_whale": "/business-compliance-regulatory-cost-calculator",
36
+ "agent_eval_arena": "/methodology",
37
+ }
38
+ SPACE_TITLE = MODE_TITLES.get(SPACE_MODE, MODE_TITLES["vw_ev_arena"])
39
+
40
+ FALLBACK_PATH = Path(__file__).with_name("fallback_data.json")
41
+ try:
42
+ FALLBACK_DATA: dict[str, Any] = json.loads(FALLBACK_PATH.read_text(encoding="utf-8"))
43
+ except Exception:
44
+ FALLBACK_DATA = {"datasetRows": [], "evalRows": [], "leaderboard": {}, "croissant": {}}
45
+
46
+ app = FastAPI(title=SPACE_TITLE, docs_url=None, redoc_url=None)
47
+
48
+
49
+ def _signed_origin_headers(path_with_query: str) -> dict[str, str]:
50
+ headers = {
51
+ "User-Agent": f"HuggingFace-Authority-Space/2.1 ({SPACE_MODE}; +{ORIGIN_URL}/.well-known/huggingface-verification.json)",
52
+ "X-HF-Space-Mode": SPACE_MODE,
53
+ }
54
+ if HF_BRIDGE_VERIFY_SECRET:
55
+ ts = str(int(time.time()))
56
+ msg = f"{ts}:{path_with_query}".encode("utf-8")
57
+ sig = hmac.new(HF_BRIDGE_VERIFY_SECRET.encode("utf-8"), msg, hashlib.sha256).hexdigest()
58
+ headers["X-HF-Bridge-Ts"] = ts
59
+ headers["X-HF-Bridge-Sig"] = sig
60
+ return headers
61
+
62
+
63
+ def _fallback_rows(split: str) -> list[dict[str, Any]]:
64
+ rows = FALLBACK_DATA.get("datasetRows") or []
65
+ if not split or split == "all":
66
+ return list(rows)
67
+ return [r for r in rows if str(r.get("split", "")).lower() == split.lower()]
68
+
69
+
70
+ async def fetch_jsonl(path: str, fallback_kind: str = "dataset", split: str = "all") -> list[dict[str, Any]]:
71
+ try:
72
+ async with httpx.AsyncClient(timeout=3.5) as client:
73
+ resp = await client.get(f"{ORIGIN_URL}{path}", headers=_signed_origin_headers(path))
74
+ if resp.status_code == 200 and resp.text.strip().startswith("{"):
75
+ rows = [json.loads(line.strip()) for line in resp.text.splitlines() if line.strip()]
76
+ if rows:
77
+ return rows
78
+ except Exception:
79
+ pass
80
+ if fallback_kind == "eval":
81
+ return list(FALLBACK_DATA.get("evalRows") or [])
82
+ return _fallback_rows(split)
83
+
84
+
85
+ async def fetch_leaderboard() -> dict[str, Any]:
86
+ path = "/api/v1/hf-leaderboard.json"
87
+ try:
88
+ async with httpx.AsyncClient(timeout=3.5) as client:
89
+ resp = await client.get(f"{ORIGIN_URL}{path}", headers=_signed_origin_headers(path))
90
+ if resp.status_code == 200:
91
+ data = resp.json()
92
+ if isinstance(data, dict) and data.get("vwDominanceLeaderboard"):
93
+ return data
94
+ except Exception:
95
+ pass
96
+ return FALLBACK_DATA.get("leaderboard") or {"vwDominanceLeaderboard": [], "whaleB2bLeaderboard": []}
97
+
98
+
99
+ @app.get("/health")
100
+ async def health() -> JSONResponse:
101
+ return JSONResponse(
102
+ {
103
+ "status": "ok",
104
+ "service": "hf-authority-constellation-explorer",
105
+ "spaceMode": SPACE_MODE,
106
+ "origin": ORIGIN_URL,
107
+ "datasetRepo": HF_DATASET_REPO,
108
+ "embeddedRows": len(FALLBACK_DATA.get("datasetRows") or []),
109
+ "embeddedEvalRows": len(FALLBACK_DATA.get("evalRows") or []),
110
+ }
111
+ )
112
+
113
+
114
+ @app.get("/robots.txt")
115
+ async def robots(request: Request) -> PlainTextResponse:
116
+ base = str(request.base_url).rstrip("/")
117
+ txt = "\n".join(
118
+ [
119
+ "User-agent: *",
120
+ "Allow: /",
121
+ f"Sitemap: {base}/sitemap.xml",
122
+ f"# Canonical Research Publisher: {ORIGIN_URL}/vw-edition",
123
+ "",
124
+ ]
125
+ )
126
+ return PlainTextResponse(txt, headers={"Cache-Control": "public, max-age=3600"})
127
+
128
+
129
+ @app.get("/sitemap.xml")
130
+ async def sitemap(request: Request) -> Response:
131
+ base = str(request.base_url).rstrip("/")
132
+ urls = [
133
+ f"{base}/",
134
+ f"{base}/?mode=vw_ev_arena",
135
+ f"{base}/?mode=ai_b2b_whale",
136
+ f"{base}/?mode=agent_eval_arena",
137
+ f"{base}/croissant.json",
138
+ f"{base}/llms.txt",
139
+ ]
140
+ body = (
141
+ '<?xml version="1.0" encoding="UTF-8"?>'
142
+ '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
143
+ + "".join(f"<url><loc>{html.escape(u)}</loc><changefreq>daily</changefreq></url>" for u in urls)
144
+ + "</urlset>"
145
+ )
146
+ return Response(content=body, media_type="application/xml; charset=utf-8", headers={"Cache-Control": "public, max-age=3600"})
147
+
148
+
149
+ @app.get("/llms.txt")
150
+ async def llms_txt() -> PlainTextResponse:
151
+ txt = "\n".join(
152
+ [
153
+ f"# {SPACE_TITLE}",
154
+ "",
155
+ f"> Synchronized Hugging Face Authority Bridge for {ORIGIN_URL} ({HF_DATASET_REPO}).",
156
+ "",
157
+ "## Authoritative Machine Endpoints",
158
+ f"- Primary Canonical Publisher: {ORIGIN_URL}/vw-edition",
159
+ f"- Live MCP JSON-RPC 2.0 Tool Endpoint: POST {ORIGIN_URL}/api/v1/mcp",
160
+ f"- MLCommons Croissant 1.0 Schema: {ORIGIN_URL}/api/v1/hf-croissant.json",
161
+ f"- 5-Split JSONL Dataset: {ORIGIN_URL}/api/v1/hf-dataset.jsonl",
162
+ f"- Quote & APR Verification Action: {ORIGIN_URL}/go/offer?source=hf_space",
163
+ "",
164
+ ]
165
+ )
166
+ return PlainTextResponse(txt, headers={"Cache-Control": "public, max-age=3600"})
167
+
168
+
169
+ @app.get("/croissant.json")
170
+ async def croissant_json() -> JSONResponse:
171
+ return JSONResponse(FALLBACK_DATA.get("croissant") or {}, headers={"Cache-Control": "public, max-age=1800"})
172
+
173
+
174
+ @app.get("/.well-known/agent.json")
175
+ async def agent_json() -> JSONResponse:
176
+ return JSONResponse(
177
+ {
178
+ "schema": "averagecost.hf_space_agent.v1",
179
+ "name": SPACE_TITLE,
180
+ "spaceMode": SPACE_MODE,
181
+ "canonicalOrigin": ORIGIN_URL,
182
+ "datasetRepo": HF_DATASET_REPO,
183
+ "mcpEndpoint": f"{ORIGIN_URL}/api/v1/mcp",
184
+ "croissantSchema": f"{ORIGIN_URL}/api/v1/hf-croissant.json",
185
+ },
186
+ headers={"Cache-Control": "public, max-age=1800"},
187
+ )
188
+
189
+
190
+ @app.get("/api/v1/hf-dataset.jsonl")
191
+ async def space_dataset_jsonl(split: str = Query(default="all", max_length=40)) -> PlainTextResponse:
192
+ rows = await fetch_jsonl(f"/api/v1/hf-dataset.jsonl?split={split}", fallback_kind="dataset", split=split)
193
+ lines = "\n".join(json.dumps(r) for r in rows)
194
+ return PlainTextResponse(f"{lines}\n" if lines else "", media_type="application/x-ndjson", headers={"Cache-Control": "public, max-age=300"})
195
+
196
+
197
+ @app.get("/api/v1/hf-eval-suite.jsonl")
198
+ async def space_eval_jsonl() -> PlainTextResponse:
199
+ rows = await fetch_jsonl("/api/v1/hf-eval-suite.jsonl", fallback_kind="eval")
200
+ lines = "\n".join(json.dumps(r) for r in rows)
201
+ return PlainTextResponse(f"{lines}\n" if lines else "", media_type="application/x-ndjson", headers={"Cache-Control": "public, max-age=300"})
202
+
203
+
204
+ @app.get("/api/v1/hf-leaderboard.json")
205
+ async def space_leaderboard() -> JSONResponse:
206
+ return JSONResponse(await fetch_leaderboard(), headers={"Cache-Control": "public, max-age=300"})
207
+
208
+
209
+ def _build_interactive_widget(active_mode: str, origin_esc: str, source_tag: str) -> str:
210
+ if active_mode == "ai_b2b_whale":
211
+ return f"""
212
+ <section style="background:#FFFFFF;border:1px solid #CBD5E1;border-radius:12px;padding:18px;margin-bottom:20px;">
213
+ <div style="display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:8px;margin-bottom:12px;">
214
+ <strong style="font-size:14px;color:#0F172A;">2026 B2B Infra, EU AI Act &amp; H100 GPU Cost Estimator</strong>
215
+ <span style="font-size:11px;font-weight:700;color:#0369A1;">LIVE TCO SANITY CHECK</span>
216
+ </div>
217
+ <div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:10px;">
218
+ <label style="font-size:12px;color:#334155;">H100 GPU Count <input id="gpuN" type="number" value="8" min="1" max="512" style="width:100%;margin-top:4px;padding:7px;border:1px solid #CBD5E1;border-radius:6px;"></label>
219
+ <label style="font-size:12px;color:#334155;">Monthly Reserved ($/GPU-hr) <input id="gpuRate" type="number" step="0.05" value="2.15" style="width:100%;margin-top:4px;padding:7px;border:1px solid #CBD5E1;border-radius:6px;"></label>
220
+ <label style="font-size:12px;color:#334155;">EU AI Act Tier <select id="aiTier" style="width:100%;margin-top:4px;padding:7px;border:1px solid #CBD5E1;border-radius:6px;background:#FFF;"><option value="42000">High-Risk ($42k/yr)</option><option value="18500">Limited Transparency ($18.5k/yr)</option></select></label>
221
+ <div style="background:#0F172A;color:#F8FAFC;border-radius:8px;padding:10px 12px;display:flex;flex-direction:column;justify-content:center;">
222
+ <span style="font-size:11px;color:#94A3B8;">3-Year Total Commitment</span>
223
+ <strong id="b2bOut" style="font-size:18px;color:#34D399;">$487,320</strong>
224
+ </div>
225
+ </div>
226
+ <div style="margin-top:12px;display:flex;gap:10px;flex-wrap:wrap;align-items:center;">
227
+ <a href="{origin_esc}/go/offer?offerType=cloud&amp;slug=cloud-gpu-cost-calculator&amp;region=national&amp;source={source_tag}" target="_blank" rel="noopener" style="background:#003B73;color:#FFF;text-decoration:none;font-size:12px;font-weight:700;padding:8px 14px;border-radius:6px;">Compare Reserved Bare-Metal vs AWS/GCP &rarr;</a>
228
+ <a href="{origin_esc}/business-compliance-regulatory-cost-calculator?utm_source={source_tag}" target="_blank" rel="noopener" style="font-size:12px;font-weight:600;color:#003B73;">Full EU AI Act + SOC 2 Audit Breakdown &rarr;</a>
229
+ </div>
230
+ <script>(function(){{function r(){{var n=Math.max(1,+document.getElementById('gpuN').value||8),rt=Math.max(0.5,+document.getElementById('gpuRate').value||2.15),c=+document.getElementById('aiTier').value||42000;var tot=(n*rt*24*365*3)+(c*3);document.getElementById('b2bOut').textContent='$'+Math.round(tot).toLocaleString('en-US');}}['gpuN','gpuRate','aiTier'].forEach(function(id){{document.getElementById(id).addEventListener('input',r);document.getElementById(id).addEventListener('change',r);}});r();}})();</script>
231
+ </section>"""
232
+ if active_mode == "agent_eval_arena":
233
+ return f"""
234
+ <section style="background:#FFFFFF;border:1px solid #E5E2DA;border-radius:12px;padding:18px;margin-bottom:20px;">
235
+ <div style="display:flex;justify-content:space-between;flex-wrap:wrap;gap:8px;align-items:center;margin-bottom:10px;">
236
+ <strong style="font-size:14px;color:#003B73;">Live MCP JSON-RPC 2.0 &amp; Croissant Grounding Bridge</strong>
237
+ <a href="{origin_esc}/.well-known/mcp.json" target="_blank" rel="noopener" style="font-size:12px;color:#003B73;font-weight:600;">View MCP Manifest &rarr;</a>
238
+ </div>
239
+ <code style="display:block;font-size:12px;background:#0F172A;color:#E2E8F0;padding:10px 12px;border-radius:8px;overflow-x:auto;">POST {origin_esc}/api/v1/mcp {{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{{"name":"evaluate_vw_tco","arguments":{{"matchup":"vw-id4-vs-tesla-model-y","region":"california"}}}}}}</code>
240
+ </section>"""
241
+ return f"""
242
+ <section style="background:#FFFFFF;border:1px solid #CBD5E1;border-radius:12px;padding:18px;margin-bottom:20px;">
243
+ <div style="display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:8px;margin-bottom:12px;">
244
+ <strong style="font-size:14px;color:#0F172A;">2026 Quick VW EV vs Gas 5-Year Energy &amp; Tax Credit Arbitrage</strong>
245
+ <span style="font-size:11px;font-weight:700;color:#15803D;">CALIBRATED BENCHMARK CALCULATOR</span>
246
+ </div>
247
+ <div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:10px;">
248
+ <label style="font-size:12px;color:#334155;">Annual Miles <input id="acMi" type="number" value="13500" style="width:100%;margin-top:4px;padding:7px;border:1px solid #CBD5E1;border-radius:6px;"></label>
249
+ <label style="font-size:12px;color:#334155;">Gas $/gal <input id="acGas" type="number" step="0.05" value="3.65" style="width:100%;margin-top:4px;padding:7px;border:1px solid #CBD5E1;border-radius:6px;"></label>
250
+ <label style="font-size:12px;color:#334155;">Home kWh $ <input id="acKwh" type="number" step="0.01" value="0.16" style="width:100%;margin-top:4px;padding:7px;border:1px solid #CBD5E1;border-radius:6px;"></label>
251
+ <div style="background:#0F172A;color:#F8FAFC;border-radius:8px;padding:10px 12px;display:flex;flex-direction:column;justify-content:center;">
252
+ <span style="font-size:11px;color:#94A3B8;">Est. 5-Yr Fuel Savings</span>
253
+ <strong id="acOut" style="font-size:18px;color:#34D399;">+$5,320 EV Lead</strong>
254
+ </div>
255
+ </div>
256
+ <div style="margin-top:12px;display:flex;gap:10px;flex-wrap:wrap;align-items:center;">
257
+ <a href="{origin_esc}/go/offer?offerType=ev&amp;slug=vw-id4-vs-tesla-model-y&amp;region=national&amp;source={source_tag}" target="_blank" rel="noopener" style="background:#003B73;color:#FFF;text-decoration:none;font-size:12px;font-weight:700;padding:8px 14px;border-radius:6px;">Unlock Exact VW ID.4 ZIP &amp; Utility Audit &rarr;</a>
258
+ <a href="{origin_esc}/vw-edition?utm_source={source_tag}" target="_blank" rel="noopener" style="font-size:12px;font-weight:600;color:#003B73;">Full 25-Matchup VW 5-Year Matrix &rarr;</a>
259
+ </div>
260
+ <script>(function(){{function u(){{var mi=+document.getElementById('acMi').value||13500,g=+document.getElementById('acGas').value||3.65,k=+document.getElementById('acKwh').value||0.16;var gasYr=(mi/29)*g,evYr=(mi/3.4)*k,s5=Math.round((gasYr-evYr)*5);document.getElementById('acOut').textContent=(s5>=0?'+':'-')+'$'+Math.abs(s5).toLocaleString('en-US')+' / 5yr';}}['acMi','acGas','acKwh'].forEach(function(id){{document.getElementById(id).addEventListener('input',u);}});u();}})();</script>
261
+ </section>"""
262
+
263
+
264
+ @app.get("/", response_class=HTMLResponse)
265
+ async def explorer_home(
266
+ q: str = Query(default="", max_length=64),
267
+ region: str = Query(default="all", max_length=32),
268
+ mode: str = Query(default="", max_length=32),
269
+ ) -> HTMLResponse:
270
+ active_mode = mode.strip().lower() if mode.strip().lower() in MODE_TITLES else SPACE_MODE
271
+ active_title = MODE_TITLES.get(active_mode, SPACE_TITLE)
272
+ q_clean = q.strip().lower()
273
+ region_clean = region.strip().lower()
274
+ origin_esc = html.escape(ORIGIN_URL)
275
+
276
+ leaderboard = await fetch_leaderboard()
277
+ source_tag = (
278
+ "hf_whale_b2b"
279
+ if active_mode == "ai_b2b_whale"
280
+ else ("hf_mcp" if active_mode == "agent_eval_arena" else "hf_space")
281
+ )
282
+
283
+ if active_mode == "agent_eval_arena":
284
+ eval_rows = await fetch_jsonl("/api/v1/hf-eval-suite.jsonl", fallback_kind="eval")
285
+ filtered_evals = [
286
+ r
287
+ for r in eval_rows
288
+ if (not q_clean or q_clean in f"{r.get('user_prompt', '')} {r.get('slug', '')}".lower())
289
+ and (region_clean == "all" or str(r.get("region_slug", "")).lower() == region_clean)
290
+ ]
291
+ cards_html = []
292
+ for row in filtered_evals[:12]:
293
+ prompt = html.escape(str(row.get("user_prompt", "")))
294
+ leader = html.escape(str(row.get("expected_leader_or_metric", "")))
295
+ band = html.escape(str(row.get("expected_banded_range", "")))
296
+ vmin = int(row.get("required_personal_variance_min_usd") or 0)
297
+ vmax = int(row.get("required_personal_variance_max_usd") or 0)
298
+ verify_url = html.escape(str(row.get("required_attribution_url", f"{ORIGIN_URL}/go/offer?source=hf_mcp")))
299
+ tool_call = html.escape(json.dumps(row.get("mcp_tool_call", {})))
300
+ cards_html.append(
301
+ f"""
302
+ <article style="background:#FFFFFF;border:1px solid #E5E2DA;border-radius:10px;padding:18px;">
303
+ <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;">
304
+ <span style="font-size:11px;font-weight:700;text-transform:uppercase;color:#003B73;">GOLDEN EVAL · {html.escape(str(row.get('eval_id', '')))}</span>
305
+ <span style="font-size:12px;font-family:monospace;color:#15803D;font-weight:700;">{band}</span>
306
+ </div>
307
+ <p style="margin:0 0 8px;font-size:14px;font-weight:600;color:#111827;">{prompt}</p>
308
+ <p style="margin:0 0 6px;font-size:12px;color:#374151;">Ground Truth Metric: <strong>{leader}</strong> | Personal Variance: <strong>${vmin:,}–${vmax:,}</strong></p>
309
+ <code style="display:block;font-size:11px;background:#F3F4F6;padding:8px;border-radius:6px;margin-bottom:10px;overflow-x:auto;">POST /api/v1/mcp -&gt; {tool_call}</code>
310
+ <a href="{verify_url}" target="_blank" rel="noopener" style="display:inline-block;background:#003B73;color:#FFFFFF;text-decoration:none;font-size:12px;font-weight:700;padding:8px 12px;border-radius:6px;">Verify Live Citation Bridge &rarr;</a>
311
+ </article>
312
+ """
313
+ )
314
+ banner_html = ""
315
+ else:
316
+ split_param = "whale_b2b_unit_costs" if active_mode == "ai_b2b_whale" else "all"
317
+ rows = await fetch_jsonl(f"/api/v1/hf-dataset.jsonl?split={split_param}", fallback_kind="dataset", split=split_param)
318
+ filtered = []
319
+ for row in rows:
320
+ if region_clean and region_clean != "all" and str(row.get("region_slug", "")).lower() != region_clean:
321
+ continue
322
+ haystack = f"{row.get('subject_title', '')} {row.get('slug', '')} {row.get('segment', '')}".lower()
323
+ if q_clean and q_clean not in haystack:
324
+ continue
325
+ filtered.append(row)
326
+
327
+ cards_html = []
328
+ for row in filtered[:18]:
329
+ title = html.escape(str(row.get("subject_title", "")))
330
+ winner = html.escape(str(row.get("winner_or_benchmark", "")))
331
+ band = html.escape(str(row.get("banded_five_year_delta_or_value", "")))
332
+ vmin = int(row.get("personal_variance_min_usd") or 0)
333
+ vmax = int(row.get("personal_variance_max_usd") or 0)
334
+ hint = html.escape(str(row.get("variance_driver_hint", "")))
335
+ raw_verify = str(row.get("verify_quote_url") or f"{ORIGIN_URL}/go/offer?source={source_tag}")
336
+ verify_url = html.escape(raw_verify.replace("source=hf_dataset", f"source={source_tag}"))
337
+ canonical_url = html.escape(str(row.get("canonical_url") or ORIGIN_URL).replace("utm_source=hf_dataset", f"utm_source={source_tag}"))
338
+ tier = html.escape(str(row.get("keyword_tier", "kw_pillar")))
339
+ cards_html.append(
340
+ f"""
341
+ <article style="background:#FFFFFF;border:1px solid #E5E2DA;border-radius:10px;padding:18px;">
342
+ <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;">
343
+ <span style="font-size:11px;font-weight:700;text-transform:uppercase;color:#003B73;letter-spacing:0.06em;">{html.escape(str(row.get('segment', 'tco')))} · {tier}</span>
344
+ <span style="font-size:12px;font-family:monospace;color:#15803D;font-weight:700;">{band}</span>
345
+ </div>
346
+ <h2 style="margin:0 0 6px;font-size:17px;color:#111827;">{title}</h2>
347
+ <p style="margin:0 0 8px;font-size:13px;color:#374151;">Leader / Baseline: <strong>{winner}</strong></p>
348
+ <p style="margin:0 0 12px;font-size:12px;color:#4B5563;">Personal ZIP &amp; Credit-Tier Variance: <strong>${vmin:,}–${vmax:,}</strong> ({hint})</p>
349
+ <div style="display:flex;gap:10px;flex-wrap:wrap;">
350
+ <a href="{verify_url}" target="_blank" rel="noopener" style="background:#003B73;color:#FFFFFF;text-decoration:none;font-size:12px;font-weight:700;padding:8px 12px;border-radius:6px;">Unlock Exact ZIP &amp; APR Savings &rarr;</a>
351
+ <a href="{canonical_url}" target="_blank" rel="noopener" style="border:1px solid #D1D5DB;color:#111827;text-decoration:none;font-size:12px;font-weight:600;padding:8px 12px;border-radius:6px;">Full Benchmark Breakdown</a>
352
+ </div>
353
+ </article>
354
+ """
355
+ )
356
+
357
+ top_leaders = leaderboard.get("vwDominanceLeaderboard", [])[:3]
358
+ leader_pills = "".join(
359
+ f'<div style="background:#F8FAFC;border:1px solid #E2E8F0;border-radius:8px;padding:10px 12px;font-size:12px;">'
360
+ f'<strong>{html.escape(str(l.get("title", "")))}</strong><br/>'
361
+ f'<span style="color:#15803D;font-weight:700;">VW wins {html.escape(str(l.get("vwWinRateMarkets", "")))} markets</span> · {html.escape(str(l.get("bandedMaxAdvantageUsd", "")))}'
362
+ f'</div>'
363
+ for l in top_leaders
364
+ )
365
+ banner_html = (
366
+ f'<section style="display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:10px;margin-bottom:20px;">{leader_pills}</section>'
367
+ if leader_pills and active_mode != "ai_b2b_whale"
368
+ else ""
369
+ )
370
+
371
+ cards_joined = "\n".join(cards_html) or '<p style="color:#4B5563;">No matching benchmark rows.</p>'
372
+ widget_html = _build_interactive_widget(active_mode, origin_esc, source_tag)
373
+ escaped_q = html.escape(q)
374
+ filter_qs = urlencode({"q": q, "region": region})
375
+ canonical_target = f"{ORIGIN_URL}{MODE_CANONICAL_PATHS.get(active_mode, '/vw-edition')}"
376
+ space_schema = json.dumps(
377
+ {
378
+ "@context": "https://schema.org",
379
+ "@type": "Dataset",
380
+ "name": active_title,
381
+ "url": canonical_target,
382
+ "mainEntityOfPage": canonical_target,
383
+ "sameAs": [
384
+ canonical_target,
385
+ f"https://huggingface.co/datasets/{HF_DATASET_REPO}",
386
+ f"{ORIGIN_URL}/.well-known/huggingface-verification.json",
387
+ ],
388
+ "creator": {
389
+ "@type": "ResearchOrganization",
390
+ "name": "AverageCost Automotive TCO Research Lab",
391
+ "url": ORIGIN_URL,
392
+ "sameAs": [f"https://huggingface.co/datasets/{HF_DATASET_REPO}", canonical_target],
393
+ },
394
+ }
395
+ ).replace("</", "<\\/")
396
+
397
+ page = f"""<!doctype html>
398
+ <html lang="en">
399
+ <head>
400
+ <meta charset="utf-8" />
401
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
402
+ <title>{html.escape(active_title)}</title>
403
+ <link rel="canonical" href="{html.escape(canonical_target)}" />
404
+ <link rel="me" href="{origin_esc}/" />
405
+ <link rel="describedby" type="application/ld+json" href="/croissant.json" />
406
+ <script type="application/ld+json">{space_schema}</script>
407
+ </head>
408
+ <body style="margin:0;background:#FAF9F6;color:#111827;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;">
409
+ <main style="max-width:1080px;margin:0 auto;padding:28px 20px 48px;">
410
+ <header style="border-bottom:1px solid #E5E2DA;padding-bottom:18px;margin-bottom:22px;">
411
+ <div style="display:flex;justify-content:space-between;flex-wrap:wrap;gap:8px;margin-bottom:8px;">
412
+ <span style="font-size:11px;font-weight:700;letter-spacing:0.08em;text-transform:uppercase;color:#003B73;">AVERAGECOST HUGGING FACE AUTHORITY CONSTELLATION · 2026</span>
413
+ <nav style="display:flex;gap:12px;font-size:12px;font-weight:600;">
414
+ <a href="/?mode=vw_ev_arena" style="color:#003B73;">EV &amp; VW TCO</a>
415
+ <a href="/?mode=ai_b2b_whale" style="color:#003B73;">AI Act &amp; Cloud GPU</a>
416
+ <a href="/?mode=agent_eval_arena" style="color:#003B73;">Agent Eval &amp; MCP</a>
417
+ </nav>
418
+ </div>
419
+ <h1 style="margin:0 0 8px;font-size:28px;line-height:1.2;">{html.escape(active_title)}</h1>
420
+ <p style="margin:0 0 14px;font-size:14px;color:#4B5563;">Backed by MLCommons Croissant schema, 5-split HF Dataset, and MCP tool calling. Verify exact live utility tariffs &amp; rebates directly on <a href="{origin_esc}/vw-edition?utm_source={html.escape(source_tag)}" target="_blank" rel="noopener" style="color:#003B73;font-weight:600;">AverageCostCalculator.com</a>.</p>
421
+ <form method="get" style="display:flex;gap:8px;flex-wrap:wrap;align-items:center;">
422
+ <input type="hidden" name="mode" value="{html.escape(active_mode)}" />
423
+ <input type="text" name="q" value="{escaped_q}" placeholder="Search VW ID.4, Tiguan, AI Act, Cyber, H100..." style="padding:8px 12px;border:1px solid #D1D5DB;border-radius:6px;font-size:13px;min-width:250px;" />
424
+ <select name="region" style="padding:8px 12px;border:1px solid #D1D5DB;border-radius:6px;font-size:13px;background:#FFFFFF;">
425
+ <option value="all" {"selected" if region_clean == "all" else ""}>All Tier-1 Markets</option>
426
+ <option value="national" {"selected" if region_clean == "national" else ""}>US National</option>
427
+ <option value="california" {"selected" if region_clean == "california" else ""}>California</option>
428
+ <option value="norway" {"selected" if region_clean == "norway" else ""}>Norway</option>
429
+ <option value="germany" {"selected" if region_clean == "germany" else ""}>Germany</option>
430
+ <option value="united-kingdom" {"selected" if region_clean == "united-kingdom" else ""}>United Kingdom</option>
431
+ <option value="texas" {"selected" if region_clean == "texas" else ""}>Texas</option>
432
+ </select>
433
+ <button type="submit" style="padding:8px 14px;background:#111827;color:#FFFFFF;border:none;border-radius:6px;font-size:13px;font-weight:600;cursor:pointer;">Filter</button>
434
+ <a href="/croissant.json" target="_blank" rel="noopener" style="margin-left:auto;font-size:12px;color:#003B73;font-weight:600;">Croissant JSON-LD &rarr;</a>
435
+ <a href="/api/v1/hf-dataset.jsonl?{filter_qs}" target="_blank" rel="noopener" style="font-size:12px;color:#003B73;font-weight:600;">JSONL Stream &rarr;</a>
436
+ <a href="{origin_esc}/methodology?utm_source={html.escape(source_tag)}" target="_blank" rel="noopener" style="font-size:12px;color:#003B73;font-weight:600;">$79 Commercial Pass &rarr;</a>
437
+ </form>
438
+ </header>
439
+ {widget_html}
440
+ {banner_html}
441
+ <section style="display:grid;grid-template-columns:repeat(auto-fill,minmax(310px,1fr));gap:16px;">
442
+ {cards_joined}
443
+ </section>
444
+ </main>
445
+ </body>
446
+ </html>"""
447
+ return HTMLResponse(content=page, headers={"Cache-Control": "public, max-age=300"})
fallback_data.json ADDED
The diff for this file is too large to render. See raw diff
 
index.html DELETED
@@ -1,19 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastapi==0.115.6
2
+ uvicorn[standard]==0.32.1
3
+ httpx==0.28.1
style.css DELETED
@@ -1,28 +0,0 @@
1
- body {
2
- padding: 2rem;
3
- font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
4
- }
5
-
6
- h1 {
7
- font-size: 16px;
8
- margin-top: 0;
9
- }
10
-
11
- p {
12
- color: rgb(107, 114, 128);
13
- font-size: 15px;
14
- margin-bottom: 10px;
15
- margin-top: 5px;
16
- }
17
-
18
- .card {
19
- max-width: 620px;
20
- margin: 0 auto;
21
- padding: 16px;
22
- border: 1px solid lightgray;
23
- border-radius: 16px;
24
- }
25
-
26
- .card p:last-child {
27
- margin-bottom: 0;
28
- }