Spaces:
Running
Running
Download index.html from bitsnaps/dz-phone-value: direct link, hf CLI and curl.
- Browser
- Download file 17.1 kB
-
https://huggingface.co/spaces/bitsnaps/dz-phone-value/resolve/main/index.html
- Command line
-
hf download hf://spaces/bitsnaps/dz-phone-value/index.html
-
curl -L -o index.html https://huggingface.co/spaces/bitsnaps/dz-phone-value/resolve/main/index.html
17.1 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>DZ Phone Value — Smartphone Price Estimator (Algeria)</title> | |
| <meta name="description" content="100% client-side smartphone price estimation for the Algerian market. XGBoost via ONNX WebAssembly — no server, no data leaves your browser."> | |
| <style> | |
| :root{ | |
| --bg:#070b16;--surface:#121a30;--surface-2:#182240;--line:#27345a;--line-2:#354675; | |
| --text:#e9eefc;--muted:#8b9bb8;--faint:#5d6d8f;--teal:#2ee6c7;--teal-dim:rgba(46,230,199,.14); | |
| --gold:#f5c15a;--rose:#ff7a93;--mono:'IBM Plex Mono',ui-monospace,monospace; | |
| } | |
| *{box-sizing:border-box;margin:0;padding:0} | |
| body{background:var(--bg);color:var(--text);font:15px/1.55 'Segoe UI',system-ui,-apple-system,sans-serif; | |
| background-image:radial-gradient(900px 300px at 12% -8%,rgba(46,230,199,.10),transparent 55%), | |
| radial-gradient(760px 260px at 88% -4%,rgba(139,156,255,.10),transparent 50%);} | |
| .wrap{max-width:1060px;margin:0 auto;padding:2rem 1.2rem 4rem} | |
| header{text-align:center;margin-bottom:1.6rem} | |
| h1{font-size:1.7rem;font-weight:800;letter-spacing:-.01em} | |
| h1 .accent{color:var(--teal)} | |
| .tagline{color:var(--muted);font-size:.92rem;margin-top:.35rem} | |
| .tagline .chip{border:1px solid var(--line);border-radius:999px;padding:.12rem .55rem;font-size:.72rem;color:var(--teal);background:var(--teal-dim);white-space:nowrap} | |
| .layout{display:grid;grid-template-columns:1fr 340px;gap:1rem;align-items:start} | |
| @media(max-width:900px){.layout{grid-template-columns:1fr}} | |
| .panel{background:var(--surface);border:1px solid var(--line);border-radius:16px;padding:1.15rem;box-shadow:0 8px 24px rgba(0,0,0,.18)} | |
| .panel h2{font-size:.78rem;text-transform:uppercase;letter-spacing:.09em;color:var(--muted);margin-bottom:.9rem;font-weight:700} | |
| .grid{display:grid;grid-template-columns:1fr 1fr;gap:.75rem 1rem} | |
| .field label{display:block;font-size:.72rem;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);margin-bottom:.3rem} | |
| select,input[type=number]{width:100%;background:var(--surface-2);border:1px solid var(--line-2);color:var(--text); | |
| border-radius:10px;padding:.5rem .6rem;font-size:.9rem;outline:none} | |
| select:focus,input:focus{border-color:var(--teal)} | |
| .toggles{display:flex;flex-wrap:wrap;gap:.45rem;margin-top:.9rem} | |
| .tg{display:inline-flex;align-items:center;gap:.4rem;border:1px solid var(--line);background:var(--surface-2); | |
| border-radius:999px;padding:.34rem .7rem;font-size:.78rem;color:var(--muted);cursor:pointer;user-select:none;transition:.12s} | |
| .tg input{accent-color:var(--teal)} | |
| .tg:has(input:checked){color:var(--teal);border-color:var(--teal);background:var(--teal-dim)} | |
| .batt-row{display:flex;gap:.6rem;align-items:center} | |
| .batt-row input[type=range]{flex:1;accent-color:var(--teal)} | |
| .batt-row .val{font-family:var(--mono);font-size:.85rem;min-width:3.2rem;text-align:right} | |
| .batt-unknown{display:flex;align-items:center;gap:.35rem;font-size:.78rem;color:var(--muted);margin-top:.25rem} | |
| button.estimate{width:100%;margin-top:1.1rem;background:var(--teal);color:#061018;border:none;border-radius:12px; | |
| padding:.7rem;font-size:.95rem;font-weight:800;cursor:pointer;transition:.15s} | |
| button.estimate:hover{filter:brightness(1.08)} | |
| button.estimate:disabled{opacity:.55;cursor:wait} | |
| .result .price{font-size:2.1rem;font-weight:800;font-family:var(--mono);color:var(--teal);text-align:center} | |
| .result .sub{text-align:center;color:var(--muted);font-size:.8rem;margin-top:.25rem} | |
| .band{margin-top:1rem} | |
| .band .row{display:flex;justify-content:space-between;font-family:var(--mono);font-size:.8rem;color:var(--muted)} | |
| .band .bar{position:relative;height:10px;border-radius:6px;background:var(--surface-2);border:1px solid var(--line);margin:.45rem 0;overflow:hidden} | |
| .band .fill{position:absolute;top:0;bottom:0;background:linear-gradient(90deg,#4f6dff,var(--teal));opacity:.85;border-radius:6px} | |
| .band .dot{position:absolute;top:50%;transform:translate(-50%,-50%);width:10px;height:10px;border-radius:50%; | |
| background:var(--teal);border:2px solid #061018;box-shadow:0 0 0 2px var(--teal)} | |
| .band .cap{text-align:center;font-size:.72rem;color:var(--faint);margin-top:.25rem} | |
| .metrics{display:grid;grid-template-columns:1fr 1fr;gap:.5rem;margin-top:.2rem} | |
| .metric{background:var(--surface-2);border:1px solid var(--line);border-radius:10px;padding:.5rem .65rem} | |
| .metric .k{font-size:.66rem;text-transform:uppercase;letter-spacing:.07em;color:var(--faint);font-weight:700} | |
| .metric .v{font-family:var(--mono);font-size:.95rem;margin-top:.1rem} | |
| .metric .v small{color:var(--faint);font-size:.68rem} | |
| .note{margin-top:.9rem;font-size:.78rem;color:var(--faint);line-height:1.5} | |
| .note b{color:var(--muted)} | |
| footer{margin-top:1.4rem;text-align:center;color:var(--faint);font-size:.8rem} | |
| footer a{color:var(--teal);text-decoration:none} | |
| footer a:hover{text-decoration:underline} | |
| .loading-overlay{position:fixed;inset:0;background:rgba(7,11,22,.7);display:none;place-items:center;z-index:50; | |
| font-family:var(--mono);color:var(--teal)} | |
| .loading-overlay.on{display:grid} | |
| .status{color:var(--faint);font-size:.78rem;font-family:var(--mono);margin-top:.5rem;text-align:center} | |
| .status.err{color:var(--rose)} | |
| </style> | |
| </head> | |
| <body> | |
| <div class="loading-overlay" id="boot"><div>loading model…</div></div> | |
| <div class="wrap"> | |
| <header> | |
| <h1>DZ Phone <span class="accent">Value</span> · Smartphone Price Estimator</h1> | |
| <p class="tagline"> | |
| <span class="chip">100% client-side</span> | |
| <span class="chip">ONNX in your browser</span> | |
| <span class="chip">no data leaves this page</span> | |
| </p> | |
| </header> | |
| <div class="layout"> | |
| <section class="panel"> | |
| <h2>Phone attributes</h2> | |
| <div class="grid"> | |
| <div class="field"><label for="brand">Brand</label> | |
| <select id="brand"></select></div> | |
| <div class="field"><label for="tier">Tier</label> | |
| <select id="tier"></select></div> | |
| <div class="field"><label for="storageGb">Storage</label> | |
| <select id="storageGb"></select></div> | |
| <div class="field"><label for="ramGb">RAM</label> | |
| <select id="ramGb"></select></div> | |
| <div class="field"><label for="releaseYear">Release year</label> | |
| <select id="releaseYear"></select></div> | |
| <div class="field"><label for="condition">Condition</label> | |
| <select id="condition"></select></div> | |
| <div class="field" style="grid-column:1/-1"><label for="batteryHealth">Battery health</label> | |
| <div class="batt-row"> | |
| <input type="range" id="batteryHealth" min="40" max="100" step="1" value="87"> | |
| <span class="val" id="batteryVal">87%</span> | |
| </div> | |
| <label class="batt-unknown"><input type="checkbox" id="batteryUnknown"> Unknown (median imputed)</label> | |
| </div> | |
| <div class="field"><label for="region">Region (wilaya)</label> | |
| <select id="region"></select></div> | |
| <div class="field"><label for="priceType">Price type</label> | |
| <select id="priceType"></select></div> | |
| </div> | |
| <div class="toggles" id="toggles"></div> | |
| <button class="estimate" id="estimateBtn">Estimate price</button> | |
| <div class="status" id="status"></div> | |
| </section> | |
| <aside> | |
| <section class="panel result"> | |
| <h2>Estimate</h2> | |
| <div class="price" id="pred-value">—</div> | |
| <div class="sub" id="pred-sub">DZD · point estimate</div> | |
| <div class="band"> | |
| <div class="row"><span>P10 <b id="band-lo">—</b></span><span>P90 <b id="band-hi">—</b></span></div> | |
| <div class="bar"><div class="fill" id="band-fill"></div><div class="dot" id="band-dot"></div></div> | |
| <div class="cap">80% conformal band (P10–P90), DZD</div> | |
| </div> | |
| </section> | |
| <section class="panel" style="margin-top:1rem"> | |
| <h2>Model card</h2> | |
| <div class="metrics" id="metrics"></div> | |
| <p class="note"><b id="mc-version"></b> · trained on <span id="mc-rows"></span> cleaned marketplace | |
| listings (Algeria, new & second-hand). Interval reference: <span id="mc-cov"></span> coverage, | |
| median width <span id="mc-width"></span>. Predictions are list-price hints for a fresh listing, | |
| not an official valuation.</p> | |
| </section> | |
| </aside> | |
| </div> | |
| <footer> | |
| Production app: <a href="https://bitsnaps.github.io/smartphone_pricing/" target="_blank" rel="noopener">DZ Phone Value (full site)</a> | |
| · Dataset: <a href="https://huggingface.co/datasets/bitsnaps/dz-smartphone-pricing" target="_blank" rel="noopener">bitsnaps/dz-smartphone-pricing</a><br> | |
| XGBoost sp10 → ONNX · feature engineering identical to the production app (golden-gated) · <a href="https://bitsnaps.github.io/benchmark_arena/#/methodology" target="_blank" rel="noopener">our honesty rules</a> | |
| </footer> | |
| </div> | |
| <script src="https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.0/dist/ort.min.js"></script> | |
| <script src="engine.js"></script> | |
| <script> | |
| const ARTIFACTS = /*__ARTIFACTS__*/{"model_version": "sp10-a2-refined", "trained_at": "2026-09-18T22:23:52.517051", "n_rows": 8611, "refined_labels": true, "b_cols": ["log2_storage", "storage_missing", "ram_gb", "ram_missing", "model_age_years", "age_missing", "tier_base", "tier_compact", "tier_plus", "tier_pro", "tier_promax", "tier_ultra", "brand_apple", "brand_google", "brand_honor", "brand_huawei", "brand_infinix", "brand_oneplus", "brand_oppo", "brand_realme", "brand_samsung", "brand_vivo", "brand_xiaomi", "region_alger", "region_blida", "region_boumerdès", "region_béjaïa", "region_constantine", "region_oran", "region_sétif", "region_tipaza", "region_tizi ouzou", "region_tlemcen", "priceType_FIXED", "priceType_NONE", "priceType_OFFERED", "condition_good", "condition_new", "condition_refurb", "condition_used", "battery_health", "battery_missing", "desc_damage", "desc_original_parts", "is_5g", "dual_sim", "acc_count", "log_repost"], "medians": {"log2_storage": 7.0, "ram_gb": 8.0, "battery_health": 87.0, "model_age_years": 3.71}, "tier_map": {"ultra": "ultra", "pro max": "promax", "promax": "promax", "pro+": "promax", "pro": "pro", "plus": "plus", "max": "promax", "mini": "compact", "lite": "compact", "fe": "compact", "turbo": "pro", "t": "pro", "c": "compact"}, "brands_top": ["apple", "samsung", "xiaomi", "honor", "realme", "oppo", "oneplus", "google", "vivo", "huawei", "infinix", "other"], "regions_top": ["alger", "oran", "blida", "constantine", "boumerdès", "sétif", "tizi ouzou", "tipaza", "tlemcen", "béjaïa"], "conditions": ["good", "like_new", "new", "refurb", "used"], "price_types": ["FIXED", "NEGOTIABLE", "NONE"], "smear": 1.14795, "cqr_Q_log": 0.0488, "cqr_alpha": 0.2, "n_estimators": {"point": 184, "q10": 448, "q90": 437}, "base_scores": {"point": 11.111612, "q10": 9.852194, "q90": 12.190959}, "card_metrics_time_split": {"mae": 33053.0, "rmse": 59451.0, "r2": 0.607, "r2_log": 0.645, "mape_pct": 38.2, "med_ape_pct": 22.5, "bias_pct": 2.0, "n_estimators": 116, "protocol": "time split, train=80% oldest (15% val), test=newest 20%", "interval_reference": {"coverage_pct": 80.2, "median_width_pct": 94.0, "coverage_by_price_tercile": {"low": 79.6, "mid": 92.2, "high": 68.9}, "source": "stats-SP9 prediction intervals"}}, "target": "log(price), Duan smearing in price space; band = [exp(qlo-Q), exp(qhi+Q)]*smear"}; | |
| const TIER_LABELS = {none:"Not specified",base:"Base (SE, C-series …)",compact:"Compact (mini / lite / FE)", | |
| plus:"Plus",pro:"Pro",promax:"Pro Max / Max",ultra:"Ultra"}; | |
| const CONDITION_LABELS = {new:"New / sealed",like_new:"Like new",good:"Good — light wear", | |
| used:"Used — visible wear",refurb:"Refurbished"}; | |
| const PRICE_TYPE_LABELS = {FIXED:"Fixed price",NEGOTIABLE:"Negotiable",NONE:"Not specified"}; | |
| const TOGGLES = [ | |
| ["damage","Damaged"],["originalParts","Original parts"],["is5g","5G"],["dualSim","Dual SIM"], | |
| ["acc_box","Box"],["acc_charger","Charger"],["acc_case","Case"], | |
| ]; | |
| const STORAGES = [32,64,128,256,512,1024], RAMS = [2,3,4,6,8,12,16]; | |
| const YEARS = Array.from({length:13},(_,i)=>2026-i); | |
| const cap = s => s.charAt(0).toUpperCase()+s.slice(1); | |
| const fmt = n => new Intl.NumberFormat("fr-FR").format(Math.round(n)); | |
| const $ = id => document.getElementById(id); | |
| __spEngine.init(ARTIFACTS); | |
| let session = null; | |
| function fill(id, items, def){ const el=$(id); items.forEach(([v,l])=>{ | |
| const o=document.createElement("option"); o.value=v; o.textContent=l; if(String(v)===String(def))o.selected=true; el.appendChild(o);});} | |
| function buildForm(){ | |
| fill("brand", [...ARTIFACTS.brands_top.map(b=>[b,cap(b)]), ["other","Other / smaller brand"]], "apple"); | |
| fill("tier", Object.entries(TIER_LABELS), "none"); | |
| fill("storageGb", [...STORAGES.map(s=>[s,s+" GB"]), ["unknown","Unknown"]], "128"); | |
| fill("ramGb", [...RAMS.map(r=>[r,r+" GB"]), ["unknown","Unknown"]], "6"); | |
| fill("releaseYear", [...YEARS.map(y=>[y,y]), ["unknown","Unknown"]], "2022"); | |
| fill("condition", Object.entries(CONDITION_LABELS), "good"); | |
| fill("region", [...ARTIFACTS.regions_top.map(r=>[r,cap(r)]), ["other","Other wilaya"]], "alger"); | |
| fill("priceType", Object.entries(PRICE_TYPE_LABELS), "FIXED"); | |
| const tg = $("toggles"); | |
| TOGGLES.forEach(([id,label],i)=>{ | |
| const l=document.createElement("label"); l.className="tg"; | |
| l.innerHTML = `<input type="checkbox" id="${id}" ${(["is5g","dualSim","acc_box","acc_charger"].includes(id))?"checked":""}> ${label}`; | |
| tg.appendChild(l); | |
| }); | |
| $("batteryHealth").addEventListener("input", e => $("batteryVal").textContent = e.target.value+"%"); | |
| $("batteryUnknown").addEventListener("change", e => { $("batteryHealth").disabled = e.target.checked; }); | |
| document.querySelectorAll("select, input[type=checkbox]").forEach(el=>el.addEventListener("change", schedule)); | |
| $("batteryHealth").addEventListener("change", schedule); | |
| $("estimateBtn").addEventListener("click", estimate); | |
| } | |
| function readInput(){ | |
| const num = v => v==="unknown" ? null : Number(v); | |
| const battUnknown = $("batteryUnknown").checked; | |
| return { | |
| brand: $("brand").value, tier: $("tier").value, | |
| storageGb: num($("storageGb").value), ramGb: num($("ramGb").value), | |
| releaseYear: num($("releaseYear").value), | |
| condition: $("condition").value, | |
| batteryHealth: battUnknown ? null : Number($("batteryHealth").value), | |
| damage: $("damage").checked, originalParts: $("originalParts").checked, | |
| is5g: $("is5g").checked, dualSim: $("dualSim").checked, | |
| accessories: { box: $("acc_box").checked, charger: $("acc_charger").checked, case: $("acc_case").checked }, | |
| region: $("region").value, priceType: $("priceType").value, | |
| }; | |
| } | |
| function render(r){ | |
| $("pred-value").textContent = fmt(r.price); | |
| $("band-lo").textContent = fmt(r.lo); | |
| $("band-hi").textContent = fmt(r.hi); | |
| // the bar spans the P10–P90 band; the dot sits at the point (log domain) | |
| const lo=Math.log10(Math.max(r.lo,1)), hi=Math.log10(Math.max(r.hi,1)), p=Math.log10(Math.max(r.priceRaw,1)); | |
| const dotPct=Math.min(100,Math.max(0,(p-lo)/(hi-lo)*100)); | |
| $("band-fill").style.left="0%"; $("band-fill").style.width="100%"; | |
| $("band-dot").style.left=dotPct+"%"; | |
| $("pred-sub").textContent = "DZD · point estimate · 80% band"; | |
| $("mc-version").textContent = r.modelVersion; | |
| } | |
| function buildModelCard(){ | |
| const cm = ARTIFACTS.card_metrics_time_split, ir = cm.interval_reference; | |
| const M = [ | |
| ["MAE", fmt(cm.mae)+" DZD"], ["R² (price)", cm.r2.toFixed(3)], | |
| ["Median APE", cm.med_ape_pct.toFixed(1)+"%"], ["Bias", cm.bias_pct.toFixed(1)+"%"], | |
| ["Training rows", ARTIFACTS.n_rows.toLocaleString("en")], ["Features", ARTIFACTS.b_cols.length], | |
| ]; | |
| $("metrics").innerHTML = M.map(([k,v])=>`<div class="metric"><div class="k">${k}</div><div class="v">${v}</div></div>`).join(""); | |
| $("mc-rows").textContent = ARTIFACTS.n_rows.toLocaleString("en"); | |
| $("mc-cov").textContent = ir.coverage_pct+"%"; | |
| $("mc-width").textContent = ir.median_width_pct+"%"; | |
| $("mc-version").textContent = ARTIFACTS.model_version; | |
| } | |
| let timer=null; | |
| function schedule(){ clearTimeout(timer); timer=setTimeout(estimate,150); } | |
| async function estimate(){ | |
| if(!session) return; | |
| $("estimateBtn").disabled = true; | |
| $("status").className="status"; $("status").textContent="running inference…"; | |
| try{ | |
| const r = await __spEngine.predictAsync(readInput(), session); | |
| render(r); | |
| $("status").textContent = ""; | |
| }catch(e){ | |
| $("status").className="status err"; $("status").textContent = "Inference error: "+e.message; | |
| }finally{ $("estimateBtn").disabled = false; } | |
| } | |
| (async function boot(){ | |
| $("boot").classList.add("on"); | |
| try{ | |
| buildForm(); buildModelCard(); | |
| session = await ort.InferenceSession.create("model.onnx", { executionProviders:["wasm"] }); | |
| window.__spSession = session; // parity bridge / debugging | |
| await estimate(); | |
| }catch(e){ | |
| $("status").className="status err"; $("status").textContent="Failed to load model: "+e.message; | |
| }finally{ $("boot").classList.remove("on"); } | |
| })(); | |
| </script> | |
| </body> | |
| </html> | |