Infinity-1995 commited on
Commit
bc40091
·
verified ·
1 Parent(s): ebcec16

Update log.html

Browse files
Files changed (1) hide show
  1. log.html +44 -52
log.html CHANGED
@@ -44,19 +44,13 @@ body {
44
  <section class="px-10 py-10">
45
  <h1 class="text-4xl font-extrabold">Log Surplus Food</h1>
46
  <p class="text-gray-600 mt-2 text-lg">
47
- AI + Location-based smart food redistribution system
48
  </p>
49
-
50
- <button onclick="getUserLocation()"
51
- class="mt-4 bg-emerald-600 text-white px-4 py-2 rounded-full">
52
- 📍 Use My Location
53
- </button>
54
  </section>
55
 
56
- <!-- MAIN -->
57
  <section class="px-10 space-y-8">
58
 
59
- <!-- INPUT -->
60
  <div class="card bg-white p-8 rounded-xl">
61
 
62
  <h2 class="text-2xl font-bold mb-6">Food Details</h2>
@@ -82,13 +76,13 @@ body {
82
 
83
  </div>
84
 
85
- <!-- AI CARD -->
86
  <div class="card bg-white p-8 rounded-xl">
87
 
88
  <h2 class="text-2xl font-bold mb-4">AI Recommendation</h2>
89
 
90
  <div id="aiText" class="text-gray-600">
91
- Click “Ask AI” to generate analysis...
92
  </div>
93
 
94
  <button onclick="runAI()"
@@ -118,54 +112,27 @@ body {
118
 
119
  <!-- CONFIRM BUTTON -->
120
  <section class="flex justify-center mt-10 mb-10">
121
- <button id="confirmBtn"
122
- class="bg-emerald-600 text-white px-10 py-4 rounded-full font-semibold text-lg hover:scale-105 transition shadow-lg">
123
  Confirm Donation
124
  </button>
125
  </section>
126
 
127
  <!-- FOOTER -->
128
  <footer class="bg-emerald-600 text-white py-12 mt-20">
129
-
130
  <div class="px-10 text-center">
131
-
132
  <h2 class="text-2xl font-extrabold">NourishNet</h2>
133
-
134
  <p class="text-white/80 mt-2">
135
  AI-powered food surplus redistribution for a zero-waste UAE.
136
  </p>
137
-
138
  <div class="mt-6 text-white/70 text-sm">
139
  © 2026 NourishNet. All rights reserved.
140
  </div>
141
-
142
  </div>
143
-
144
  </footer>
145
 
146
  <!-- SCRIPT -->
147
  <script>
148
 
149
- let userLocation = null;
150
-
151
- // get location
152
- function getUserLocation() {
153
-
154
- navigator.geolocation.getCurrentPosition((pos) => {
155
-
156
- userLocation = {
157
- lat: pos.coords.latitude,
158
- lng: pos.coords.longitude
159
- };
160
-
161
- document.getElementById("mapFrame").src =
162
- `https://www.google.com/maps?q=${userLocation.lat},${userLocation.lng}&output=embed`;
163
-
164
- });
165
-
166
- }
167
-
168
- // slider
169
  const portions = document.getElementById("portions");
170
  const portionValue = document.getElementById("portionValue");
171
 
@@ -173,6 +140,13 @@ portions.addEventListener("input", () => {
173
  portionValue.innerText = portions.value;
174
  });
175
 
 
 
 
 
 
 
 
176
  // AI FUNCTION
177
  async function runAI() {
178
 
@@ -183,14 +157,22 @@ async function runAI() {
183
  let hours = expiryText.includes("6") ? 3 : expiryText.includes("24") ? 12 : 30;
184
 
185
  const prompt = `
186
- You are NourishNet AI.
187
 
 
 
 
 
 
188
  Meals: ${meals}
189
  Hours: ${hours}
190
  Food: ${foodType}
191
 
192
- Return:
193
- Priority, Reason, Action
 
 
 
194
  `;
195
 
196
  try {
@@ -199,28 +181,38 @@ Priority, Reason, Action
199
  method: "POST",
200
  headers: {
201
  "Content-Type": "application/json",
202
- "Authorization": "Bearer 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 "
203
  },
204
  body: JSON.stringify({
205
  model: "llama-3.1-8b-instant",
206
- messages: [
207
- { role: "user", content: prompt }
208
- ]
209
  })
210
  });
211
 
212
  const data = await response.json();
213
  const result = data.choices[0].message.content;
214
 
215
- document.getElementById("aiText").innerHTML = `
216
- <div class="bg-emerald-50 border border-emerald-200 p-4 rounded-lg">
217
- <pre class="whitespace-pre-wrap text-gray-800">${result}</pre>
218
- </div>
219
- `;
 
 
 
 
 
 
 
 
 
 
 
 
 
220
 
221
  } catch (err) {
222
- document.getElementById("aiText").innerText =
223
- "AI failed. Check API key or connection.";
224
  }
225
  }
226
 
 
44
  <section class="px-10 py-10">
45
  <h1 class="text-4xl font-extrabold">Log Surplus Food</h1>
46
  <p class="text-gray-600 mt-2 text-lg">
47
+ AI-powered food redistribution system
48
  </p>
 
 
 
 
 
49
  </section>
50
 
51
+ <!-- INPUT -->
52
  <section class="px-10 space-y-8">
53
 
 
54
  <div class="card bg-white p-8 rounded-xl">
55
 
56
  <h2 class="text-2xl font-bold mb-6">Food Details</h2>
 
76
 
77
  </div>
78
 
79
+ <!-- AI -->
80
  <div class="card bg-white p-8 rounded-xl">
81
 
82
  <h2 class="text-2xl font-bold mb-4">AI Recommendation</h2>
83
 
84
  <div id="aiText" class="text-gray-600">
85
+ Click “Ask AI” to generate recommendation...
86
  </div>
87
 
88
  <button onclick="runAI()"
 
112
 
113
  <!-- CONFIRM BUTTON -->
114
  <section class="flex justify-center mt-10 mb-10">
115
+ <button class="bg-emerald-600 text-white px-10 py-4 rounded-full font-semibold text-lg hover:scale-105 transition shadow-lg">
 
116
  Confirm Donation
117
  </button>
118
  </section>
119
 
120
  <!-- FOOTER -->
121
  <footer class="bg-emerald-600 text-white py-12 mt-20">
 
122
  <div class="px-10 text-center">
 
123
  <h2 class="text-2xl font-extrabold">NourishNet</h2>
 
124
  <p class="text-white/80 mt-2">
125
  AI-powered food surplus redistribution for a zero-waste UAE.
126
  </p>
 
127
  <div class="mt-6 text-white/70 text-sm">
128
  © 2026 NourishNet. All rights reserved.
129
  </div>
 
130
  </div>
 
131
  </footer>
132
 
133
  <!-- SCRIPT -->
134
  <script>
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  const portions = document.getElementById("portions");
137
  const portionValue = document.getElementById("portionValue");
138
 
 
140
  portionValue.innerText = portions.value;
141
  });
142
 
143
+ // locations for map
144
+ const locations = {
145
+ "Elderly Home": "Al Rahma Elderly Home Dubai",
146
+ "Refugee Center": "Hope Refugee Center Dubai",
147
+ "Food Bank": "Dubai Food Bank"
148
+ };
149
+
150
  // AI FUNCTION
151
  async function runAI() {
152
 
 
157
  let hours = expiryText.includes("6") ? 3 : expiryText.includes("24") ? 12 : 30;
158
 
159
  const prompt = `
160
+ You are NourishNet AI (food logistics system).
161
 
162
+ DO NOT give diets or meals.
163
+
164
+ ONLY analyze redistribution.
165
+
166
+ INPUT:
167
  Meals: ${meals}
168
  Hours: ${hours}
169
  Food: ${foodType}
170
 
171
+ OUTPUT FORMAT:
172
+ Priority: HIGH / MEDIUM / LOW
173
+ Recipient: Elderly Home / Refugee Center / Food Bank
174
+ Reason: short
175
+ Action: short
176
  `;
177
 
178
  try {
 
181
  method: "POST",
182
  headers: {
183
  "Content-Type": "application/json",
184
+ "Authorization": "Bearer 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"
185
  },
186
  body: JSON.stringify({
187
  model: "llama-3.1-8b-instant",
188
+ messages: [{ role: "user", content: prompt }]
 
 
189
  })
190
  });
191
 
192
  const data = await response.json();
193
  const result = data.choices[0].message.content;
194
 
195
+ // show AI output
196
+ document.getElementById("aiText").innerHTML =
197
+ `<pre class="whitespace-pre-wrap bg-emerald-50 p-4 rounded-lg border border-emerald-200">${result}</pre>`;
198
+
199
+ // detect recipient
200
+ let recipient = "Refugee Center";
201
+
202
+ if (result.toLowerCase().includes("elderly")) {
203
+ recipient = "Elderly Home";
204
+ } else if (result.toLowerCase().includes("food bank")) {
205
+ recipient = "Food Bank";
206
+ }
207
+
208
+ // update map
209
+ document.getElementById("mapFrame").src =
210
+ "https://www.google.com/maps?q=" +
211
+ encodeURIComponent(locations[recipient]) +
212
+ "&output=embed";
213
 
214
  } catch (err) {
215
+ document.getElementById("aiText").innerText = "AI failed.";
 
216
  }
217
  }
218