Spaces:
Running
Running
Download ChallengePanel.jsx from kugguk/electrocheap: direct link, hf CLI and curl.
- Browser
- Download file 9.04 kB
-
https://huggingface.co/spaces/kugguk/electrocheap/resolve/main/ChallengePanel.jsx
- Command line
-
hf download hf://spaces/kugguk/electrocheap/ChallengePanel.jsx
-
curl -L -o ChallengePanel.jsx https://huggingface.co/spaces/kugguk/electrocheap/resolve/main/ChallengePanel.jsx
9.04 kB
| import React, {useEffect, useState} from 'react'; | |
| import {Download, Play, RefreshCw, Upload} from 'lucide-react'; | |
| async function call(path, payload, signal) { | |
| const response = await fetch(path, {method: payload === undefined ? 'GET' : 'POST', | |
| headers: payload === undefined ? {} : {'Content-Type': 'application/json'}, | |
| body: payload === undefined ? undefined : JSON.stringify(payload), signal}); | |
| if (!response.headers.get('content-type')?.includes('application/json')) { | |
| throw Error(`The service returned HTTP ${response.status} instead of JSON. Check the connection and retry.`); | |
| } | |
| const data = await response.json(); | |
| if (!response.ok) throw Error(data.detail || `Request failed (${response.status}).`); | |
| return data; | |
| } | |
| function save(data, name) { | |
| const url = URL.createObjectURL(new Blob([JSON.stringify(data, null, 2)], {type: 'application/json'})); | |
| const a = document.createElement('a'); a.href = url; a.download = name; a.click(); URL.revokeObjectURL(url); | |
| } | |
| const value = n => n == null ? '—' : Number(n).toLocaleString(undefined, {maximumFractionDigits: 3}); | |
| export default function ChallengePanel({country}) { | |
| const [packet, setPacket] = useState(null), [connections, setConnections] = useState(null); | |
| const [input, setInput] = useState(''), [report, setReport] = useState(null); | |
| const [busy, setBusy] = useState(false), [error, setError] = useState(''); | |
| useEffect(() => { | |
| const controller = new AbortController(); | |
| const timeout = setTimeout(() => controller.abort(), 30000); | |
| Promise.all([call('/api/challenge_packet', {country}, controller.signal), call('/api/connections', undefined, controller.signal)]) | |
| .then(([p, c]) => {setPacket(p); setConnections(c);}) | |
| .catch(e => {if (!controller.signal.aborted) setError(e.message); else setError('Connection timed out. Reopen LLM challenge to retry.');}) | |
| .finally(() => clearTimeout(timeout)); | |
| return () => {clearTimeout(timeout); controller.abort();}; | |
| }, [country]); | |
| const score = async submission => { | |
| setBusy(true); setError(''); setReport(null); | |
| try { | |
| if (submission.country !== country) throw Error(`This submission is for ${submission.country || 'an unspecified market'}. Select ${country} predictions.`); | |
| setReport(await call('/api/challenge_score', submission, AbortSignal.timeout(30000))); | |
| } catch (e) {setError(e.name === 'TimeoutError' ? 'Scoring timed out. Retry the same submission.' : e.message);} | |
| finally {setBusy(false);} | |
| }; | |
| return <> | |
| <section className="panel"> | |
| <div className="section-title"><div><div className="eyebrow">PORTABLE MODEL COMPARISON</div> | |
| <h2>Our model. Astra. The same test.</h2> | |
| <p>Run a chosen plugin, base model or fine-tuned adapter on four six-month forecasts. Compare its returned predictions with the recorded model family.</p> | |
| </div><span className="source-pill">{country} · 24 TARGETS</span></div> | |
| {error && <p className="error" role="alert">{error}</p>} | |
| {!packet ? <p role="status">{error || 'Loading the frozen challenge…'}</p> : <> | |
| <div className="protocol-strip"><span><b>1.</b> Get prompts</span><span><b>2.</b> Run our chosen model</span><span><b>3.</b> Upload predictions</span><span><b>4.</b> Compare</span></div> | |
| <div className="button-row"> | |
| <a className="primary" href={`/api/challenge/${country}/export`} download><Download size={16}/>Download test & fine-tuning kit</a> | |
| <button className="secondary" onClick={() => save(packet, `electrocheap-${country}-prompts.json`)}><Download size={15}/>Prompts JSON</button> | |
| <button className="secondary" disabled={busy} onClick={() => {const p=packet.demo_submission; setInput(JSON.stringify(p,null,2)); score(p);}}><Play size={15}/>Try seasonal baseline</button> | |
| </div> | |
| <p className="subtle">The baseline button checks the workflow with seasonal naive predictions. It does not call Astra or train a model.</p> | |
| <details><summary>Fine-tuning files and chronological boundaries</summary> | |
| <p>The kit contains chat-format <code>train.jsonl</code>, <code>validation.jsonl</code> and answer-free <code>test-prompts.jsonl</code>, plus a response template and checksums.</p> | |
| <p>Training targets stop before October 2022. Validation covers October 2022–September 2024; test covers October 2024–September 2026. Each prompt contains only history observed through its origin. Keep evaluation prompts out of training.</p> | |
| <p>This is a small public historical challenge. Its outcomes have already been published; fresh private or prospective data is required for an independent improvement claim.</p> | |
| </details> | |
| <label className="upload"><Upload size={18}/><b>Load a prediction JSON</b><span>24 target rows · model identity and revision · maximum 2 MB</span> | |
| <input type="file" accept=".json,application/json" aria-label="Upload challenge predictions" disabled={busy} onChange={async e => { | |
| const f=e.target.files[0]; e.target.value=''; if(!f)return; | |
| if(f.size>2000000){setError('Prediction JSON must be at most 2 MB.');return;} | |
| try{const text=await f.text(); JSON.parse(text); setInput(text);setReport(null);setError('');}catch{setError('The selected file is not valid JSON.');} | |
| }}/></label> | |
| <label className="field"><span>Prediction submission · editable JSON</span> | |
| <textarea rows={10} spellCheck={false} value={input} placeholder='Download the kit and fill submission-template.json, or try the seasonal baseline.' onChange={e=>{setInput(e.target.value);setReport(null);}}/> | |
| </label> | |
| <div className="button-row"><button className="primary" disabled={busy || !input} onClick={()=>{try{score(JSON.parse(input));}catch(e){setError(e.message);}}}>{busy?<RefreshCw size={16}/>:<Play size={16}/>}Compare predictions</button> | |
| <button className="secondary" onClick={()=>save(packet.response_template,`electrocheap-${country}-submission-template.json`)}>Response template</button></div> | |
| </>} | |
| </section> | |
| {report && <section className="panel" aria-live="polite"><div className="section-title"><div><div className="eyebrow">RETROSPECTIVE RESULT</div><h2>{report.model.id}</h2><p>{report.candidate.completed}/{report.candidate.eligible} completed targets · {report.status}</p></div><button className="secondary" onClick={()=>save(report,`electrocheap-${country}-comparison.json`)}><Download size={15}/>Evidence JSON</button></div> | |
| <div className="table-wrap"><table><thead><tr><th>Model / evidence</th><th>MAE · GWh</th><th>RMSE · GWh</th><th>MASE</th><th>Candidate MAE gain · GWh</th></tr></thead><tbody> | |
| <tr><td><b>{report.model.id} · submitted predictions</b></td><td>{value(report.candidate.mae_gwh)}</td><td>{value(report.candidate.rmse_gwh)}</td><td>{value(report.candidate.mase)}</td><td>—</td></tr> | |
| {report.comparators.map(r=><tr key={r.id}><td>{r.label}</td><td>{value(r.mae_gwh)}</td><td>{value(r.rmse_gwh)}</td><td>{value(r.mase)}</td><td>{value(r.candidate_mae_gain_gwh)}</td></tr>)} | |
| </tbody></table></div><p className="subtle">Positive gain means lower candidate MAE on this panel. Incomplete submissions receive no comparative gain. Submitted model identity is self-reported.</p> | |
| <details><summary>Per-origin, per-horizon and paired evidence</summary><pre className="json">{JSON.stringify(report,null,2)}</pre></details> | |
| </section>} | |
| <section className="notice"><p>Astra and Sol are archived delegated diagnostics. TimesFM, Chronos and Grokked entries are archived results. This test starts no remote model calls and promotes no winner. Four origin blocks cannot establish statistical superiority.</p></section> | |
| {connections && <section className="panel"><h2>Connection status</h2><p>REST: ready · MCP: registered · News: {connections.news.status} · Hosted LLM inference: {connections.live_hosted_llm.status}</p> | |
| <p>News needs the server’s SerpApi configuration. Official feeds are checked only when requested; this status does not imply every publisher is reachable.</p> | |
| <label className="field"><span>Canonical MCP URL</span><input readOnly value={connections.mcp.endpoint}/></label> | |
| <p>Connect the LLM plugin to this URL to discover <code>challenge_packet</code> and <code>challenge_score</code>. Connections to a separate older Worker do not automatically receive these tools.</p> | |
| <details><summary>REST / local adapter instructions</summary><pre className="json">{'POST /api/challenge_packet\n{"country":"'+country+'"}\n\nPOST /api/challenge_score\n<filled submission-template.json>\n\npython challenge_cli.py export --country '+country+' --output kit.zip\npython challenge_cli.py score --input predictions.json --output report.json\npython challenge_cli.py run --country '+country+' --adapter my_model:predict --model-id actual-id --revision actual-revision --output predictions.json'}</pre></details> | |
| </section>} | |
| </>; | |
| } | |