Spaces:
e
Sleeping

Shaikhsarib commited on
Commit
1e40fc1
·
verified ·
1 Parent(s): 6091ebd

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +145 -169
index.html CHANGED
@@ -10,178 +10,108 @@
10
 
11
  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
12
  <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
 
13
 
14
  <style>
15
- :root {
16
- --primary: #0f172a;
17
- --accent: #22c55e;
18
- --accent-light: #dcfce7;
19
- --danger: #ef4444;
20
- --bg: #ffffff;
21
- --surface: #f8fafc;
22
- --border: #e2e8f0;
23
- --text-secondary: #64748b;
24
- }
25
- * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Plus Jakarta Sans', sans-serif; -webkit-tap-highlight-color: transparent; }
26
- body {
27
- background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
28
- color: var(--primary);
29
- height: 100vh;
30
- display: flex;
31
- flex-direction: column;
32
- overflow: hidden;
33
- }
34
 
35
- /* HEADER */
36
- .header {
37
- padding: 20px 24px;
38
- background: rgba(255,255,255,0.95);
39
- backdrop-filter: blur(20px);
40
- display: flex;
41
- justify-content: space-between;
42
- align-items: center;
43
- z-index: 10;
44
- border-bottom: 1px solid var(--border);
45
- box-shadow: 0 2px 20px rgba(0,0,0,0.03);
46
- }
47
- .logo { font-weight: 800; font-size: 1.4rem; letter-spacing: -1px; }
48
  .logo span { color: var(--accent); }
49
- .beta-badge {
50
- background: linear-gradient(135deg, var(--accent) 0%, #16a34a 100%);
51
- color: white;
52
- padding: 4px 12px;
53
- border-radius: 20px;
54
- font-size: 0.7rem;
55
- font-weight: 800;
56
- letter-spacing: 0.5px;
57
- }
58
 
59
- .main-container { flex: 1; overflow-y: auto; padding: 32px 20px; display: flex; flex-direction: column; align-items: center; gap: 28px; }
60
 
61
- /* PERSONA CHIPS */
62
- .persona-section {
63
- width: 100%; max-width: 440px; background: white; padding: 24px;
64
- border-radius: 20px; box-shadow: 0 8px 32px rgba(0,0,0,0.04); border: 1px solid var(--border);
65
- }
66
- .persona-label { font-size: 0.75rem; font-weight: 800; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 16px; }
67
- .persona-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 10px; }
68
- .chip {
69
- padding: 12px; background: var(--surface); border-radius: 12px; border: 2px solid transparent;
70
- font-size: 0.85rem; font-weight: 700; cursor: pointer; text-align: center; transition: 0.2s;
71
- }
72
- .chip.active {
73
- background: var(--accent-light); color: var(--primary); border-color: var(--accent);
74
- }
75
 
76
- /* SCAN CARD */
77
- .scan-card {
78
- width: 100%; max-width: 440px; background: white; padding: 40px 30px;
79
- border-radius: 28px; text-align: center; border: 2px solid var(--border);
80
- box-shadow: 0 20px 60px -10px rgba(0,0,0,0.08); cursor: pointer; transition: 0.3s;
81
- }
82
- .scan-card:active { transform: scale(0.98); }
83
- .scan-icon-wrapper {
84
- background: var(--accent-light); width: 80px; height: 80px; border-radius: 50%;
85
- display: flex; align-items: center; justify-content: center; margin: 0 auto 20px auto;
86
- }
87
 
88
- #preview-area { display: none; width: 100%; max-width: 440px; }
89
- #preview-img { width: 100%; height: 300px; object-fit: cover; border-radius: 24px; margin-bottom: 20px; border: 4px solid white; box-shadow: 0 10px 30px rgba(0,0,0,0.1); }
90
 
91
- .btn { width: 100%; padding: 18px; border-radius: 16px; font-weight: 800; font-size: 1rem; border: none; cursor: pointer; }
92
- .btn-primary { background: var(--primary); color: white; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.3); }
93
- .btn-ghost { background: transparent; color: var(--text-secondary); margin-top: 10px; }
94
 
95
  /* LOADER */
96
  #loader { position: fixed; inset: 0; background: rgba(255,255,255,0.9); z-index: 600; display: none; flex-direction: column; align-items: center; justify-content: center; }
97
- .spinner { width: 50px; height: 50px; border: 4px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin-bottom: 20px; }
98
  @keyframes spin { to { transform: rotate(360deg); } }
99
 
100
  /* REPORT */
101
- #report { position: fixed; inset: 0; background: #fff; z-index: 400; transform: translateY(100%); transition: 0.5s cubic-bezier(0.4, 0, 0.2, 1); padding: 0; overflow-y: auto; }
102
  #report.open { transform: translateY(0); }
103
 
104
- .report-header { padding: 40px 20px; background: linear-gradient(180deg, var(--surface) 0%, #ffffff 100%); text-align: center; border-radius: 0 0 30px 30px; }
105
- .chart-wrapper { width: 180px; height: 180px; margin: 0 auto 20px auto; position: relative; }
106
  .score-center { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; }
107
- .score-num { font-size: 2.8rem; font-weight: 900; line-height: 1; color: var(--primary); }
108
-
109
- .report-body { padding: 30px 20px; max-width: 600px; margin: 0 auto; padding-bottom: 100px; }
110
-
111
- .science-card { background: #eff6ff; border: 1px solid #bfdbfe; padding: 20px; border-radius: 16px; margin-bottom: 20px; }
112
- .pill-badge { background: white; padding: 5px 10px; border-radius: 10px; font-size: 0.7rem; font-weight: 800; color: #2563eb; margin-bottom: 10px; display: inline-block; }
113
 
114
- .eli5-box { background: #fffbeb; border: 1px solid #fcd34d; padding: 0 20px; border-radius: 16px; margin-bottom: 10px; overflow: hidden; max-height: 0; transition: 0.3s; }
115
  .eli5-box.active { max-height: 500px; padding: 20px; }
116
 
117
  .btn-row { display: flex; gap: 10px; margin: 20px 0; }
118
- .list-item { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px; font-size: 0.95rem; color: #334155; }
119
  .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
120
- .dot.green { background: var(--accent); } .dot.red { background: var(--danger); }
121
-
122
- #toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(100px); background: var(--primary); color: white; padding: 12px 24px; border-radius: 50px; opacity: 0; transition: 0.3s; z-index: 1000; font-weight: 700; box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
123
- #toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
124
 
125
  #story-canvas { position: fixed; top: -9999px; left: -9999px; width: 1080px; height: 1920px; background: white; display: flex; flex-direction: column; align-items: center; justify-content: center; }
126
-
127
- #cam-overlay { position: fixed; inset: 0; background: black; z-index: 500; display: none; flex-direction: column; }
128
- #cam-overlay.active { display: flex; }
129
- video { flex: 1; object-fit: cover; }
130
- .controls { height: 140px; background: rgba(0,0,0,0.8); display: flex; justify-content: center; align-items: center; }
131
- .shutter { width: 70px; height: 70px; background: white; border-radius: 50%; border: 4px solid rgba(255,255,255,0.3); }
132
  </style>
133
  </head>
134
  <body>
135
 
136
  <div class="header">
137
  <div class="logo">Eatlytic<span>.ai</span></div>
138
- <div class="beta-badge">BETA</div>
139
  </div>
140
 
141
  <div class="main-container">
142
- <div class="persona-section">
143
- <div class="persona-label">Select Your Profile</div>
144
  <div class="persona-row">
145
  <div class="chip active" onclick="setPersona(this, 'General')">🏠 General</div>
146
  <div class="chip" onclick="setPersona(this, 'Gym Athlete')">💪 Gym</div>
147
- <div class="chip" onclick="setPersona(this, 'Parent')">👶 Parent</div>
148
  <div class="chip" onclick="setPersona(this, 'Skincare')">✨ Skin</div>
149
  </div>
150
  </div>
151
 
152
- <div id="landing-ui" style="width:100%; display:flex; flex-direction:column; align-items:center; gap:20px;">
153
- <div class="scan-card" onclick="startCamera()">
154
- <div class="scan-icon-wrapper"><i class="fas fa-camera fa-3x" style="color:var(--accent)"></i></div>
155
- <h2 style="font-weight:800; font-size:1.6rem;">Scan Product</h2>
156
- <p style="color:var(--text-secondary)">AI-Powered Health Analysis</p>
 
 
157
  </div>
158
 
159
- <div onclick="document.getElementById('fileInput').click()" style="color:var(--text-secondary); font-weight:700; cursor:pointer;">
160
- <i class="fas fa-image"></i> Upload from Gallery
161
- </div>
162
  </div>
163
 
164
  <div id="preview-area">
165
  <img id="preview-img" src="">
166
- <button class="btn btn-primary" onclick="analyze()"><span>🚀 Analyze Now</span></button>
167
  <button class="btn btn-ghost" onclick="reset()">Cancel</button>
168
  </div>
169
 
170
  <input type="file" id="fileInput" hidden accept="image/*" onchange="handleFile(this.files[0])">
171
  </div>
172
 
173
- <div id="cam-overlay">
174
- <video id="video" autoplay playsinline></video>
175
- <canvas id="canvas" hidden></canvas>
176
- <div class="controls">
177
- <button onclick="stopCamera()" style="position:absolute; left:30px; background:none; border:none; color:white; font-size:1.1rem; font-weight:700;">Cancel</button>
178
- <div class="shutter" onclick="capture()"></div>
179
- </div>
180
- </div>
181
-
182
  <div id="loader">
183
  <div class="spinner"></div>
184
- <h3 id="load-msg" style="color:var(--primary); font-weight:700;">Processing...</h3>
185
  </div>
186
 
187
  <div id="report">
@@ -189,7 +119,7 @@
189
  </div>
190
 
191
  <div id="story-canvas"></div>
192
- <div id="toast">Story saved to gallery! 📸</div>
193
 
194
  <script>
195
  const API = window.location.origin;
@@ -197,55 +127,91 @@
197
  let myChart = null;
198
  let currentPersona = "General";
199
  let lastResult = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
 
 
201
  function setPersona(el, p) {
202
  document.querySelectorAll('.chip').forEach(c => c.classList.remove('active'));
203
  el.classList.add('active');
204
  currentPersona = p;
205
  }
206
- function handleFile(f) {
207
- if(!f) return; blob = f;
 
 
 
 
208
  document.getElementById('landing-ui').style.display = 'none';
209
- document.getElementById('preview-img').src = URL.createObjectURL(f);
210
  document.getElementById('preview-area').style.display = 'block';
 
 
 
 
 
 
 
 
 
 
 
211
  }
 
212
  function reset() {
213
  blob = null;
214
  document.getElementById('preview-area').style.display = 'none';
215
  document.getElementById('landing-ui').style.display = 'flex';
216
  }
217
- async function startCamera() {
218
- try {
219
- const s = await navigator.mediaDevices.getUserMedia({video:{facingMode:'environment'}});
220
- document.getElementById('video').srcObject = s;
221
- document.getElementById('cam-overlay').classList.add('active');
222
- } catch { alert("Permission needed. Try running on Localhost or HTTPS."); }
223
- }
224
- function stopCamera() {
225
- const s = document.getElementById('video').srcObject;
226
- if(s) s.getTracks().forEach(t=>t.stop());
227
- document.getElementById('cam-overlay').classList.remove('active');
228
- }
229
- function capture() {
230
- const v = document.getElementById('video');
231
- const c = document.getElementById('canvas');
232
- c.width = v.videoWidth; c.height = v.videoHeight;
233
- c.getContext('2d').drawImage(v,0,0);
234
- c.toBlob(b => { stopCamera(); handleFile(b); }, 'image/jpeg', 0.9);
235
- }
236
  async function analyze() {
237
  if(!blob) return;
238
  const loader = document.getElementById('loader');
239
  const msg = document.getElementById('load-msg');
240
  loader.style.display = 'flex';
241
 
242
- const txts = ["Extracting Ingredients...", "Checking Toxicity...", "Analyzing Molecular Impact...", "Generating Charts..."];
243
- let i=0; const t = setInterval(()=> { if(i<txts.length) msg.innerText=txts[i++]; }, 1500);
244
-
245
  const fd = new FormData();
246
  fd.append('image', blob);
247
- fd.append('persona', currentPersona);
248
-
 
 
249
  try {
250
  const res = await fetch(`${API}/analyze`, {method:'POST', body:fd});
251
  const data = await res.json();
@@ -253,10 +219,12 @@
253
  if(data.error) throw new Error(data.error);
254
  lastResult = data;
255
  renderReport(data);
 
256
  } catch(e) {
257
  clearInterval(t); alert(e.message); loader.style.display='none';
258
  }
259
  }
 
260
  function renderReport(d) {
261
  document.getElementById('loader').style.display='none';
262
 
@@ -269,39 +237,44 @@
269
  <div class="score-label">Score</div>
270
  </div>
271
  </div>
272
- <h2 style="margin:12px 0 6px 0; font-size:1.6rem; font-weight:800;">${d.product_name}</h2>
273
- <div style="font-weight:800; font-size:1.1rem; color:${d.score>=7?'#22c55e':(d.score>=4?'#eab308':'#ef4444')}">${d.verdict}</div>
274
- <p style="margin-top:12px; color:#64748b; font-size:1rem; line-height:1.6; max-width:400px; margin-left:auto; margin-right:auto;">${d.summary}</p>
275
  </div>
276
- <div class="report-body">
277
- <div class="science-card">
278
- <div class="pill-badge">🧬 MOLECULAR INSIGHT</div>
279
- <p style="font-size:0.95rem; color:#1e3a8a; line-height:1.7;">
280
- <b>Reaction:</b> ${d.molecular_insight}
281
- </p>
282
  </div>
 
283
  <div class="btn-row">
284
- <button class="btn" onclick="toggleELI5()" style="flex:1; border:2px solid var(--border); background:white; font-weight:700;">🭐 ELI5 Mode</button>
285
- <button class="btn" onclick="shareStory()" style="flex:1; background:linear-gradient(135deg, #833ab4 0%, #fd1d1d 100%); color:white; font-weight:700;">📸 Share</button>
286
  </div>
 
287
  <div id="eli5-display" class="eli5-box">
288
- <p style="font-size:1rem; line-height:1.6; color:#92400e;">
289
- 🭐 <b>Kids Version:</b><br>${d.eli5_explanation}
290
  </p>
291
  </div>
292
- <div class="list-item" style="color:#64748b; font-weight:800; font-size:0.75rem; margin-top:28px; letter-spacing:1px;">PROS</div>
293
- ${(d.pros||[]).map(p => `<div class="list-item"><div class="dot green"></div><div>${p}</div></div>`).join('')}
294
- <div class="list-item" style="color:#64748b; font-weight:800; font-size:0.75rem; margin-top:28px; letter-spacing:1px;">CONS</div>
295
- ${(d.cons||[]).map(p => `<div class="list-item"><div class="dot red"></div><div>${p}</div></div>`).join('')}
 
 
 
 
 
 
296
 
297
- <div style="margin-top:32px; padding:24px; background:linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%); border-radius:20px; border:2px solid #fed7aa; text-align:center; box-shadow:0 4px 16px rgba(251, 146, 60, 0.1);">
298
- <div style="font-size:0.75rem; font-weight:900; color:#c2410c; margin-bottom:8px; letter-spacing:1px;">💡 BETTER ALTERNATIVE</div>
299
- <div style="font-weight:800; color:#9a3412; font-size:1.1rem;">${d.better_alternative}</div>
300
  </div>
301
 
302
- <button class="btn btn-primary" onclick="location.reload()" style="margin-top:28px;">
303
- <span>Scan Next Product</span>
304
- </button>
305
  </div>
306
  `;
307
 
@@ -323,14 +296,17 @@
323
  options: { cutout: '80%', responsive: true, plugins: { legend: { display: false } } }
324
  });
325
  }
 
326
  function toggleELI5() {
327
  document.getElementById('eli5-display').classList.toggle('active');
328
  }
 
329
  function showToast() {
330
  const t = document.getElementById('toast');
331
  t.classList.add('show');
332
  setTimeout(() => t.classList.remove('show'), 3000);
333
  }
 
334
  async function shareStory() {
335
  const canvas = document.getElementById('story-canvas');
336
  canvas.innerHTML = `
@@ -351,7 +327,7 @@
351
  link.href = shot.toDataURL("image/jpeg");
352
  link.click();
353
  showToast();
354
- } catch(e) { alert("Sharing not supported on this browser context."); }
355
  }
356
  </script>
357
  </body>
 
10
 
11
  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
12
  <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
13
+ <script src="https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js"></script>
14
 
15
  <style>
16
+ :root { --primary: #0f172a; --accent: #22c55e; --bg: #f8fafc; }
17
+ * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Plus Jakarta Sans', sans-serif; }
18
+ body { background: var(--bg); color: var(--primary); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ .header { padding: 15px 20px; background: rgba(255,255,255,0.9); backdrop-filter: blur(10px); display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #e2e8f0; z-index: 10; }
21
+ .logo { font-weight: 800; font-size: 1.3rem; letter-spacing: -0.5px; }
 
 
 
 
 
 
 
 
 
 
 
22
  .logo span { color: var(--accent); }
 
 
 
 
 
 
 
 
 
23
 
24
+ .main-container { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 20px; }
25
 
26
+ /* HISTORY PANEL */
27
+ #history-panel { width: 100%; max-width: 440px; margin-top: 10px; }
28
+ .history-item { background: white; padding: 12px; border-radius: 12px; border: 1px solid #e2e8f0; margin-bottom: 8px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
29
+ .history-score { font-weight: 800; color: var(--accent); }
 
 
 
 
 
 
 
 
 
 
30
 
31
+ /* PERSONA */
32
+ .persona-label { font-size: 0.8rem; font-weight: 700; color: #64748b; text-transform: uppercase; align-self: flex-start; margin-left: 10px; }
33
+ .persona-row { display: flex; gap: 10px; overflow-x: auto; padding: 5px 5px 15px 5px; width: 100%; scrollbar-width: none; }
34
+ .chip { flex-shrink: 0; padding: 10px 16px; background: white; border-radius: 50px; border: 1px solid #e2e8f0; font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: 0.2s; }
35
+ .chip.active { background: var(--primary); color: white; border-color: var(--primary); transform: scale(1.05); }
36
+
37
+ /* CARDS */
38
+ .scan-card { width: 100%; max-width: 400px; background: white; padding: 30px; border-radius: 24px; text-align: center; border: 1px solid #f1f5f9; box-shadow: 0 10px 40px -10px rgba(0,0,0,0.05); cursor: pointer; }
 
 
 
39
 
40
+ #preview-area { display: none; width: 100%; max-width: 400px; }
41
+ #preview-img { width: 100%; height: 280px; object-fit: cover; border-radius: 20px; margin-bottom: 20px; border: 4px solid white; box-shadow: 0 10px 20px rgba(0,0,0,0.1); }
42
 
43
+ .btn { width: 100%; padding: 16px; border-radius: 14px; font-weight: 700; font-size: 1rem; border: none; cursor: pointer; transition: 0.2s; }
44
+ .btn-primary { background: var(--primary); color: white; box-shadow: 0 4px 12px rgba(15, 23, 42, 0.2); }
45
+ .btn-ghost { background: transparent; color: #64748b; margin-top: 10px; }
46
 
47
  /* LOADER */
48
  #loader { position: fixed; inset: 0; background: rgba(255,255,255,0.9); z-index: 600; display: none; flex-direction: column; align-items: center; justify-content: center; }
49
+ .spinner { width: 50px; height: 50px; border: 4px solid #e2e8f0; border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin-bottom: 20px; }
50
  @keyframes spin { to { transform: rotate(360deg); } }
51
 
52
  /* REPORT */
53
+ #report { position: fixed; inset: 0; background: #fff; z-index: 400; transform: translateY(100%); transition: 0.4s cubic-bezier(0.16, 1, 0.3, 1); padding: 0; overflow-y: auto; }
54
  #report.open { transform: translateY(0); }
55
 
56
+ .report-header { padding: 30px 20px; background: #f8fafc; text-align: center; border-bottom-left-radius: 30px; border-bottom-right-radius: 30px; }
57
+ .chart-wrapper { width: 160px; height: 160px; margin: 0 auto 15px auto; position: relative; }
58
  .score-center { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; }
59
+ .score-num { font-size: 2.2rem; font-weight: 800; line-height: 1; color: var(--primary); }
 
 
 
 
 
60
 
61
+ .eli5-box { background: #fffbeb; border: 1px solid #fcd34d; padding: 0 20px; border-radius: 12px; margin-bottom: 10px; overflow: hidden; max-height: 0; transition: 0.3s; }
62
  .eli5-box.active { max-height: 500px; padding: 20px; }
63
 
64
  .btn-row { display: flex; gap: 10px; margin: 20px 0; }
65
+ .list-item { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; font-size: 0.95rem; color: #334155; }
66
  .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
67
+ .dot.green { background: var(--accent); } .dot.red { background: #ef4444; }
 
 
 
68
 
69
  #story-canvas { position: fixed; top: -9999px; left: -9999px; width: 1080px; height: 1920px; background: white; display: flex; flex-direction: column; align-items: center; justify-content: center; }
70
+ #toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(100px); background: #333; color: white; padding: 12px 24px; border-radius: 50px; opacity: 0; transition: 0.3s; z-index: 1000; font-weight: 600; }
71
+ #toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
 
 
 
 
72
  </style>
73
  </head>
74
  <body>
75
 
76
  <div class="header">
77
  <div class="logo">Eatlytic<span>.ai</span></div>
 
78
  </div>
79
 
80
  <div class="main-container">
81
+ <div style="width:100%; max-width:400px;">
82
+ <div class="persona-label">Select Profile</div>
83
  <div class="persona-row">
84
  <div class="chip active" onclick="setPersona(this, 'General')">🏠 General</div>
85
  <div class="chip" onclick="setPersona(this, 'Gym Athlete')">💪 Gym</div>
86
+ <div class="chip" onclick="setPersona(this, 'Parent/Baby')">👶 Baby</div>
87
  <div class="chip" onclick="setPersona(this, 'Skincare')">✨ Skin</div>
88
  </div>
89
  </div>
90
 
91
+ <div id="landing-ui" style="width:100%; display:flex; flex-direction:column; align-items:center; gap:15px; margin-top:10px;">
92
+ <div class="scan-card" onclick="document.getElementById('fileInput').click()">
93
+ <div style="background:#f0fdf4; width:80px; height:80px; border-radius:50%; display:flex; align-items:center; justify-content:center; margin:0 auto 20px auto;">
94
+ <i class="fas fa-camera fa-2x" style="color:var(--accent)"></i>
95
+ </div>
96
+ <h2>Scan Product</h2>
97
+ <p style="color:#64748b; margin-top:5px">Instant Health Analysis</p>
98
  </div>
99
 
100
+ <div id="history-panel"></div>
 
 
101
  </div>
102
 
103
  <div id="preview-area">
104
  <img id="preview-img" src="">
105
+ <button class="btn btn-primary" onclick="analyze()">🚀 Analyze Now</button>
106
  <button class="btn btn-ghost" onclick="reset()">Cancel</button>
107
  </div>
108
 
109
  <input type="file" id="fileInput" hidden accept="image/*" onchange="handleFile(this.files[0])">
110
  </div>
111
 
 
 
 
 
 
 
 
 
 
112
  <div id="loader">
113
  <div class="spinner"></div>
114
+ <h3 id="load-msg" style="color:#334155">Processing...</h3>
115
  </div>
116
 
117
  <div id="report">
 
119
  </div>
120
 
121
  <div id="story-canvas"></div>
122
+ <div id="toast">Story saved! 📸</div>
123
 
124
  <script>
125
  const API = window.location.origin;
 
127
  let myChart = null;
128
  let currentPersona = "General";
129
  let lastResult = null;
130
+
131
+ // --- 1. HISTORY LOGIC ---
132
+ let scanHistory = JSON.parse(localStorage.getItem('eatlytic_history') || '[]');
133
+ renderHistory();
134
+
135
+ function addToHistory(d) {
136
+ scanHistory.unshift({
137
+ id: Date.now(),
138
+ name: d.product_name,
139
+ score: d.score,
140
+ date: new Date().toLocaleDateString()
141
+ });
142
+ scanHistory = scanHistory.slice(0, 10); // Keep last 10
143
+ localStorage.setItem('eatlytic_history', JSON.stringify(scanHistory));
144
+ renderHistory();
145
+ }
146
+
147
+ function renderHistory() {
148
+ const container = document.getElementById('history-panel');
149
+ if (scanHistory.length === 0) {
150
+ container.innerHTML = '<div style="text-align:center; color:#94a3b8; font-size:0.9rem;">No recent scans</div>';
151
+ return;
152
+ }
153
+ container.innerHTML = '<div class="persona-label" style="margin-bottom:10px">Recent Scans</div>' +
154
+ scanHistory.map(item => `
155
+ <div class="history-item">
156
+ <div>
157
+ <div style="font-weight:700; font-size:0.95rem;">${item.name}</div>
158
+ <div style="font-size:0.8rem; color:#64748b;">${item.date}</div>
159
+ </div>
160
+ <div class="history-score" style="color:${item.score >= 7 ? '#22c55e' : (item.score >= 4 ? '#eab308' : '#ef4444')}">${item.score}/10</div>
161
+ </div>
162
+ `).join('');
163
+ }
164
 
165
+ // --- 2. CLIENT-SIDE OCR & PREVIEW ---
166
  function setPersona(el, p) {
167
  document.querySelectorAll('.chip').forEach(c => c.classList.remove('active'));
168
  el.classList.add('active');
169
  currentPersona = p;
170
  }
171
+
172
+ async function handleFile(file) {
173
+ if(!file) return;
174
+ blob = file;
175
+
176
+ // Show preview immediately
177
  document.getElementById('landing-ui').style.display = 'none';
178
+ document.getElementById('preview-img').src = URL.createObjectURL(file);
179
  document.getElementById('preview-area').style.display = 'block';
180
+
181
+ // Run OCR in background immediately
182
+ const loader = document.getElementById('loader');
183
+ // loader.style.display = 'flex'; // Optional: show loader during OCR if slow
184
+
185
+ try {
186
+ const { data: { text } } = await Tesseract.recognize(file, 'eng', {
187
+ logger: m => console.log(m)
188
+ });
189
+ window.ocrText = text; // Save for analyze()
190
+ } catch (e) { console.error("OCR Failed", e); }
191
  }
192
+
193
  function reset() {
194
  blob = null;
195
  document.getElementById('preview-area').style.display = 'none';
196
  document.getElementById('landing-ui').style.display = 'flex';
197
  }
198
+
199
+ // --- 3. ANALYZE (Sends OCR Text) ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  async function analyze() {
201
  if(!blob) return;
202
  const loader = document.getElementById('loader');
203
  const msg = document.getElementById('load-msg');
204
  loader.style.display = 'flex';
205
 
206
+ const txts = ["Checking Ingredients...", "Consulting Expert...", "Finalizing..."];
207
+ let i=0; const t = setInterval(()=> { if(i<txts.length) msg.innerText=txts[i++]; }, 1000);
208
+
209
  const fd = new FormData();
210
  fd.append('image', blob);
211
+ fd.append('persona', currentPersona);
212
+ // SEND CLIENT OCR TEXT (Falls back to server if empty)
213
+ fd.append('extracted_text', window.ocrText || '');
214
+
215
  try {
216
  const res = await fetch(`${API}/analyze`, {method:'POST', body:fd});
217
  const data = await res.json();
 
219
  if(data.error) throw new Error(data.error);
220
  lastResult = data;
221
  renderReport(data);
222
+ addToHistory(data); // Save to history
223
  } catch(e) {
224
  clearInterval(t); alert(e.message); loader.style.display='none';
225
  }
226
  }
227
+
228
  function renderReport(d) {
229
  document.getElementById('loader').style.display='none';
230
 
 
237
  <div class="score-label">Score</div>
238
  </div>
239
  </div>
240
+ <h2 style="margin:10px 0 5px 0">${d.product_name}</h2>
241
+ <div style="font-weight:700; color:${d.score>=7?'#22c55e':(d.score>=4?'#eab308':'#ef4444')}">${d.verdict}</div>
242
+ <p style="margin-top:10px; color:#64748b; font-size:0.95rem; line-height:1.5">${d.summary}</p>
243
  </div>
244
+
245
+ <div class="report-body" style="padding:25px; padding-bottom:100px;">
246
+ <div style="background:#eff6ff; padding:15px; border-radius:12px; margin-bottom:20px; border:1px solid #dbeafe;">
247
+ <span style="background:white; padding:4px 10px; border-radius:10px; font-size:0.7rem; font-weight:800; color:#2563eb;">🧬 SCIENCE</span>
248
+ <p style="font-size:0.9rem; color:#1e3a8a; margin-top:8px;">${d.molecular_insight}</p>
 
249
  </div>
250
+
251
  <div class="btn-row">
252
+ <button class="btn" onclick="toggleELI5()" style="flex:1; border:1px solid #e2e8f0; background:white;">🍭 ELI5 Mode</button>
253
+ <button class="btn" onclick="shareStory()" style="flex:1; background:#833ab4; color:white;">📸 Share</button>
254
  </div>
255
+
256
  <div id="eli5-display" class="eli5-box">
257
+ <p style="font-size:1rem; line-height:1.5; color:#92400e;">
258
+ 🍭 <b>Kids Version:</b><br>${d.eli5_explanation}
259
  </p>
260
  </div>
261
+
262
+ <div style="margin-top:20px;">
263
+ <div style="font-weight:700; color:#64748b; font-size:0.8rem; margin-bottom:10px;">PROS</div>
264
+ ${(d.pros||[]).map(p => `<div class="list-item"><div class="dot green"></div><div>${p}</div></div>`).join('')}
265
+ </div>
266
+
267
+ <div style="margin-top:20px;">
268
+ <div style="font-weight:700; color:#64748b; font-size:0.8rem; margin-bottom:10px;">CONS</div>
269
+ ${(d.cons||[]).map(p => `<div class="list-item"><div class="dot red"></div><div>${p}</div></div>`).join('')}
270
+ </div>
271
 
272
+ <div style="margin-top:30px; padding:20px; background:#fff7ed; border-radius:16px; border:1px solid #ffedd5; text-align:center;">
273
+ <div style="font-size:0.8rem; font-weight:700; color:#c2410c; margin-bottom:5px">💡 BETTER ALTERNATIVE</div>
274
+ <div style="font-weight:800; color:#9a3412">${d.better_alternative}</div>
275
  </div>
276
 
277
+ <button class="btn btn-primary" onclick="location.reload()" style="margin-top:20px;">Scan Next</button>
 
 
278
  </div>
279
  `;
280
 
 
296
  options: { cutout: '80%', responsive: true, plugins: { legend: { display: false } } }
297
  });
298
  }
299
+
300
  function toggleELI5() {
301
  document.getElementById('eli5-display').classList.toggle('active');
302
  }
303
+
304
  function showToast() {
305
  const t = document.getElementById('toast');
306
  t.classList.add('show');
307
  setTimeout(() => t.classList.remove('show'), 3000);
308
  }
309
+
310
  async function shareStory() {
311
  const canvas = document.getElementById('story-canvas');
312
  canvas.innerHTML = `
 
327
  link.href = shot.toDataURL("image/jpeg");
328
  link.click();
329
  showToast();
330
+ } catch(e) { alert("Sharing not supported on this browser."); }
331
  }
332
  </script>
333
  </body>