Shaikhsarib commited on
Commit
9fdc8d6
·
verified ·
1 Parent(s): 219bcc0

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +21 -90
index.html CHANGED
@@ -1301,26 +1301,16 @@ function renderReport(d) {
1301
  }, 160);
1302
  });
1303
  }
1304
- // ── Severity config for rule warnings ────────────────────────────────
1305
- const SEV_CONFIG = {
1306
- critical: { bg:'#FFF0F0', border:'#FECACA', badge:'#991B1B', badgeBg:'#FEE2E2', icon:'🚫', label:'CRITICAL' },
1307
- high: { bg:'#FFF7ED', border:'#FED7AA', badge:'#9A3412', badgeBg:'#FED7AA', icon:'⚠️', label:'HIGH' },
1308
- moderate: { bg:'#FFFBEB', border:'#FDE68A', badge:'#92400E', badgeBg:'#FEF3C7', icon:'🔶', label:'MODERATE' },
1309
- info: { bg:'#EFF6FF', border:'#BFDBFE', badge:'#1E40AF', badgeBg:'#DBEAFE', icon:'ℹ️', label:'INFO' },
1310
- };
1311
-
1312
  function buildBody(d) {
1313
  const nutrients = Array.isArray(d.nutrient_breakdown) ? d.nutrient_breakdown : [];
1314
- const verbatim = Array.isArray(d.verbatim_nutrients) ? d.verbatim_nutrients : [];
1315
- const ruleWarns = Array.isArray(d.rule_warnings) ? d.rule_warnings : [];
1316
- const pros = Array.isArray(d.pros) ? d.pros : [];
1317
- const cons = Array.isArray(d.cons) ? d.cons : [];
1318
- const ageW = Array.isArray(d.age_warnings) ? d.age_warnings : [];
1319
  let html = '';
1320
-
1321
- // 0. Blur info section
1322
  const bi = d.blur_info;
1323
  if (bi && bi.detected) {
 
1324
  if (bi.deblurred && bi.image_b64) {
1325
  html += `<div class="r-section" style="padding:14px">
1326
  <div class="deblur-report-badge">🔧 Blur Corrected — Enhanced Image Used</div>
@@ -1329,21 +1319,22 @@ function buildBody(d) {
1329
  </div>
1330
  <div style="font-size:0.76rem;color:var(--mist);line-height:1.5">
1331
  The original image was <strong>${escHtml(bi.severity)}ly blurry</strong>
1332
- (score&nbsp;${bi.score}/100). Processed through a multi-stage enhancement pipeline.
 
1333
  ${bi.method_log ? `<br><span style="font-family:monospace;font-size:0.68rem;color:#A16207">Pipeline: ${escHtml(bi.method_log)}</span>` : ''}
1334
  </div>
1335
  </div>`;
1336
- } else {
1337
- html += `<div class="r-section" style="padding:14px;background:#FFFBEB;border:1.5px solid #FCD34D">
1338
  <div class="deblur-report-badge">⚠️ Blur Detected</div>
1339
  <div style="font-size:0.76rem;color:#78350F;line-height:1.5">
1340
- Blur detected (severity:&nbsp;<strong>${escHtml(bi.severity)}</strong>, score&nbsp;${bi.score}/100).
1341
- Original image used. Retake for best results.
 
1342
  </div>
1343
  </div>`;
1344
  }
1345
  }
1346
-
1347
  // 1. Simple Explanation
1348
  if (d.eli5_explanation) {
1349
  html += `<div class="r-section">
@@ -1354,25 +1345,7 @@ function buildBody(d) {
1354
  </div>
1355
  </div>`;
1356
  }
1357
-
1358
- // 2A. Verbatim Nutritional Values (raw from label — never altered)
1359
- if (verbatim.length) {
1360
- html += `<div class="r-section">
1361
- <div class="r-title">Label Values — Verbatim</div>
1362
- <div style="font-size:0.72rem;color:var(--mist);margin-bottom:10px;line-height:1.5">
1363
- Numbers extracted <strong>exactly</strong> as printed on the product label — no rounding or estimation.
1364
- </div>
1365
- <div style="display:grid;grid-template-columns:1fr 1fr;gap:6px">
1366
- ${verbatim.map(n => `
1367
- <div style="background:var(--parchment);border-radius:10px;padding:9px 12px;display:flex;justify-content:space-between;align-items:center">
1368
- <span style="font-size:0.78rem;color:var(--forest);font-weight:600">${escHtml(n.name)}</span>
1369
- <span style="font-size:0.85rem;font-weight:800;color:var(--ink);font-family:'Playfair Display',serif">${escHtml(n.raw)}<span style="font-size:0.68rem;font-weight:400;color:var(--mist);margin-left:2px">${escHtml(n.unit)}</span></span>
1370
- </div>`).join('')}
1371
- </div>
1372
- </div>`;
1373
- }
1374
-
1375
- // 2B. Nutritional Breakdown (visual bars, values from verbatim where available)
1376
  if (nutrients.length) {
1377
  const MAXES = { g:50, mg:2000, '%':100, kcal:500, kj:2000 };
1378
  html += `<div class="r-section">
@@ -1384,59 +1357,21 @@ function buildBody(d) {
1384
  <div class="n-leg"><div class="n-dot" style="background:#8B0000"></div>Bad</div>
1385
  </div>
1386
  ${nutrients.map(n => {
1387
- const r = n.rating || 'moderate';
1388
- const max = MAXES[(n.unit||'').toLowerCase()] || 100;
1389
  const pct = Math.min(100, (parseFloat(n.value) / max) * 100);
1390
- // Display the raw verbatim string if available, else the numeric value
1391
- const displayVal = n.raw ? n.raw : (n.value != null ? n.value : '—');
1392
  return `<div class="nutrient-item">
1393
  <div class="nutrient-row">
1394
  <div class="n-name">${escHtml(n.name)}</div>
1395
  <div class="n-bar-wrap"><div class="n-bar bar-${r}" data-w="${pct.toFixed(1)}"></div></div>
1396
- <div class="n-val">${escHtml(String(displayVal))}${escHtml(n.unit||'')}</div>
1397
  </div>
1398
  ${n.impact ? `<div class="n-impact">${escHtml(n.impact)}</div>` : ''}
1399
  </div>`;
1400
  }).join('')}
1401
  </div>`;
1402
  }
1403
-
1404
- // 3. Rule-Based Health Warnings
1405
- if (ruleWarns.length) {
1406
- // Group by severity for a structured display
1407
- const bySev = { critical:[], high:[], moderate:[], info:[] };
1408
- ruleWarns.forEach(w => { (bySev[w.severity] || bySev.info).push(w); });
1409
-
1410
- let warnHtml = '';
1411
- ['critical','high','moderate','info'].forEach(sev => {
1412
- if (!bySev[sev].length) return;
1413
- const cfg = SEV_CONFIG[sev];
1414
- bySev[sev].forEach(w => {
1415
- warnHtml += `
1416
- <div style="background:${cfg.bg};border:1.5px solid ${cfg.border};border-radius:12px;padding:12px 14px;margin-bottom:8px">
1417
- <div style="display:flex;align-items:center;gap:8px;margin-bottom:5px">
1418
- <span style="font-size:1.1rem">${cfg.icon}</span>
1419
- <span style="font-size:0.78rem;font-weight:800;color:${cfg.badge};background:${cfg.badgeBg};padding:2px 8px;border-radius:50px;letter-spacing:0.5px">${cfg.label}</span>
1420
- <span style="font-size:1.0rem">${escHtml(w.group_emoji||'')}</span>
1421
- <span style="font-size:0.78rem;font-weight:700;color:var(--forest)">${escHtml(w.group_label)}</span>
1422
- ${w.value_raw ? `<span style="margin-left:auto;font-size:0.72rem;color:var(--mist);font-family:monospace">${escHtml(w.value_raw)}${escHtml(w.unit||'')}</span>` : ''}
1423
- </div>
1424
- <div style="font-size:0.83rem;font-weight:700;color:var(--ink);margin-bottom:3px">${escHtml(w.title)}</div>
1425
- <div style="font-size:0.78rem;color:#374151;line-height:1.55">${escHtml(w.detail)}</div>
1426
- </div>`;
1427
- });
1428
- });
1429
-
1430
- html += `<div class="r-section">
1431
- <div class="r-title">Health Warnings</div>
1432
- <div style="font-size:0.72rem;color:var(--mist);margin-bottom:10px">
1433
- Rule-based alerts derived directly from label values — not AI-generated estimates.
1434
- </div>
1435
- ${warnHtml}
1436
- </div>`;
1437
- }
1438
-
1439
- // 4. Pros & Cons
1440
  if (pros.length || cons.length) {
1441
  html += `<div class="r-section">
1442
  <div class="r-title">Pros &amp; Cons</div>
@@ -1452,8 +1387,7 @@ function buildBody(d) {
1452
  </div>
1453
  </div>`;
1454
  }
1455
-
1456
- // 5. Product Description
1457
  if (d.paragraph_benefits || d.paragraph_uniqueness) {
1458
  html += `<div class="r-section">
1459
  <div class="r-title">Product Analysis</div>
@@ -1461,8 +1395,7 @@ function buildBody(d) {
1461
  ${d.paragraph_uniqueness ? `<p class="para-text">${escHtml(d.paragraph_uniqueness)}</p>` : ''}
1462
  </div>`;
1463
  }
1464
-
1465
- // 6. Age Group Warnings (AI-generated, qualitative)
1466
  if (ageW.length) {
1467
  html += `<div class="r-section">
1468
  <div class="r-title">By Age Group</div>
@@ -1476,16 +1409,14 @@ function buildBody(d) {
1476
  </div>
1477
  </div>`;
1478
  }
1479
-
1480
- // 7. Molecular Insight
1481
  if (d.molecular_insight) {
1482
  html += `<div class="r-section">
1483
  <div class="r-title">Molecular Insight</div>
1484
  <div class="mol-box">🔬 ${escHtml(d.molecular_insight)}</div>
1485
  </div>`;
1486
  }
1487
-
1488
- // 8. Better Alternative
1489
  if (d.better_alternative) {
1490
  html += `<div class="r-section" style="padding:0;overflow:hidden">
1491
  <div class="alt-box">
 
1301
  }, 160);
1302
  });
1303
  }
 
 
 
 
 
 
 
 
1304
  function buildBody(d) {
1305
  const nutrients = Array.isArray(d.nutrient_breakdown) ? d.nutrient_breakdown : [];
1306
+ const pros = Array.isArray(d.pros) ? d.pros : [];
1307
+ const cons = Array.isArray(d.cons) ? d.cons : [];
1308
+ const ageW = Array.isArray(d.age_warnings) ? d.age_warnings : [];
 
 
1309
  let html = '';
1310
+ // 0. Blur info section (shown at top of report if blur was detected)
 
1311
  const bi = d.blur_info;
1312
  if (bi && bi.detected) {
1313
+ const sevClass = bi.severity || 'moderate';
1314
  if (bi.deblurred && bi.image_b64) {
1315
  html += `<div class="r-section" style="padding:14px">
1316
  <div class="deblur-report-badge">🔧 Blur Corrected — Enhanced Image Used</div>
 
1319
  </div>
1320
  <div style="font-size:0.76rem;color:var(--mist);line-height:1.5">
1321
  The original image was <strong>${escHtml(bi.severity)}ly blurry</strong>
1322
+ (score&nbsp;${bi.score}/100). It was processed through a
1323
+ multi-stage enhancement pipeline before OCR and analysis.
1324
  ${bi.method_log ? `<br><span style="font-family:monospace;font-size:0.68rem;color:#A16207">Pipeline: ${escHtml(bi.method_log)}</span>` : ''}
1325
  </div>
1326
  </div>`;
1327
+ } else if (bi.detected) {
1328
+ html += `<div class="r-section" style="padding:14px;background:#FFFBEB;border:1.5px solid #FCD34D;border-radius:var(--radius-sm)">
1329
  <div class="deblur-report-badge">⚠️ Blur Detected</div>
1330
  <div style="font-size:0.76rem;color:#78350F;line-height:1.5">
1331
+ Blur was detected in this image (severity:&nbsp;<strong>${escHtml(bi.severity)}</strong>,
1332
+ score&nbsp;${bi.score}/100). The original image was used after comparison.
1333
+ For best results, retake with better lighting and a steady hand.
1334
  </div>
1335
  </div>`;
1336
  }
1337
  }
 
1338
  // 1. Simple Explanation
1339
  if (d.eli5_explanation) {
1340
  html += `<div class="r-section">
 
1345
  </div>
1346
  </div>`;
1347
  }
1348
+ // 2. Nutritional Breakdown
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1349
  if (nutrients.length) {
1350
  const MAXES = { g:50, mg:2000, '%':100, kcal:500, kj:2000 };
1351
  html += `<div class="r-section">
 
1357
  <div class="n-leg"><div class="n-dot" style="background:#8B0000"></div>Bad</div>
1358
  </div>
1359
  ${nutrients.map(n => {
1360
+ const r = n.rating || 'moderate';
1361
+ const max = MAXES[n.unit] || 100;
1362
  const pct = Math.min(100, (parseFloat(n.value) / max) * 100);
 
 
1363
  return `<div class="nutrient-item">
1364
  <div class="nutrient-row">
1365
  <div class="n-name">${escHtml(n.name)}</div>
1366
  <div class="n-bar-wrap"><div class="n-bar bar-${r}" data-w="${pct.toFixed(1)}"></div></div>
1367
+ <div class="n-val">${n.value}${n.unit||''}</div>
1368
  </div>
1369
  ${n.impact ? `<div class="n-impact">${escHtml(n.impact)}</div>` : ''}
1370
  </div>`;
1371
  }).join('')}
1372
  </div>`;
1373
  }
1374
+ // 3. Pros & Cons
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1375
  if (pros.length || cons.length) {
1376
  html += `<div class="r-section">
1377
  <div class="r-title">Pros &amp; Cons</div>
 
1387
  </div>
1388
  </div>`;
1389
  }
1390
+ // 4. Product Description (2 paragraphs)
 
1391
  if (d.paragraph_benefits || d.paragraph_uniqueness) {
1392
  html += `<div class="r-section">
1393
  <div class="r-title">Product Analysis</div>
 
1395
  ${d.paragraph_uniqueness ? `<p class="para-text">${escHtml(d.paragraph_uniqueness)}</p>` : ''}
1396
  </div>`;
1397
  }
1398
+ // 5. Age Group Warnings
 
1399
  if (ageW.length) {
1400
  html += `<div class="r-section">
1401
  <div class="r-title">By Age Group</div>
 
1409
  </div>
1410
  </div>`;
1411
  }
1412
+ // 6. Molecular Insight
 
1413
  if (d.molecular_insight) {
1414
  html += `<div class="r-section">
1415
  <div class="r-title">Molecular Insight</div>
1416
  <div class="mol-box">🔬 ${escHtml(d.molecular_insight)}</div>
1417
  </div>`;
1418
  }
1419
+ // 7. Better Alternative
 
1420
  if (d.better_alternative) {
1421
  html += `<div class="r-section" style="padding:0;overflow:hidden">
1422
  <div class="alt-box">