Spaces:
Running
Running
Update log.html
Browse files
log.html
CHANGED
|
@@ -44,14 +44,19 @@ 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 |
-
|
| 48 |
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
</section>
|
| 50 |
|
| 51 |
<!-- MAIN -->
|
| 52 |
<section class="px-10 space-y-8">
|
| 53 |
|
| 54 |
-
<!-- INPUT
|
| 55 |
<div class="card bg-white p-8 rounded-xl">
|
| 56 |
|
| 57 |
<h2 class="text-2xl font-bold mb-6">Food Details</h2>
|
|
@@ -80,11 +85,11 @@ body {
|
|
| 80 |
<!-- AI CARD -->
|
| 81 |
<div class="card bg-white p-8 rounded-xl">
|
| 82 |
|
| 83 |
-
<h2 class="text-2xl font-bold">AI Recommendation</h2>
|
| 84 |
|
| 85 |
-
<
|
| 86 |
-
Click “Ask AI” to
|
| 87 |
-
</
|
| 88 |
|
| 89 |
<button onclick="runAI()"
|
| 90 |
class="mt-5 bg-emerald-600 text-white px-6 py-2 rounded-full">
|
|
@@ -93,41 +98,74 @@ body {
|
|
| 93 |
|
| 94 |
</div>
|
| 95 |
|
| 96 |
-
<!-- MAP
|
| 97 |
<div class="card bg-white p-8 rounded-xl">
|
| 98 |
|
| 99 |
<h2 class="text-2xl font-bold mb-4">Delivery Route Map</h2>
|
| 100 |
|
| 101 |
-
<
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
</div>
|
| 122 |
|
| 123 |
</div>
|
| 124 |
|
| 125 |
-
</
|
| 126 |
|
| 127 |
<!-- SCRIPT -->
|
| 128 |
<script>
|
| 129 |
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
const portions = document.getElementById("portions");
|
| 132 |
const portionValue = document.getElementById("portionValue");
|
| 133 |
|
|
@@ -135,7 +173,7 @@ portions.addEventListener("input", () => {
|
|
| 135 |
portionValue.innerText = portions.value;
|
| 136 |
});
|
| 137 |
|
| 138 |
-
//
|
| 139 |
async function runAI() {
|
| 140 |
|
| 141 |
const meals = document.getElementById("portions").value;
|
|
@@ -144,30 +182,24 @@ async function runAI() {
|
|
| 144 |
|
| 145 |
let hours = expiryText.includes("6") ? 3 : expiryText.includes("24") ? 12 : 30;
|
| 146 |
|
| 147 |
-
const distance = 5;
|
| 148 |
-
|
| 149 |
const prompt = `
|
| 150 |
-
You are NourishNet AI
|
| 151 |
-
|
| 152 |
-
Analyze:
|
| 153 |
|
| 154 |
Meals: ${meals}
|
| 155 |
-
Hours
|
| 156 |
-
|
| 157 |
-
Food type: ${foodType}
|
| 158 |
|
| 159 |
Return:
|
| 160 |
-
Priority
|
| 161 |
-
Reason (2 lines)
|
| 162 |
-
Action (clear next step)
|
| 163 |
`;
|
| 164 |
|
| 165 |
try {
|
|
|
|
| 166 |
const response = await fetch("https://api.groq.com/openai/v1/chat/completions", {
|
| 167 |
method: "POST",
|
| 168 |
headers: {
|
| 169 |
"Content-Type": "application/json",
|
| 170 |
-
"Authorization": "Bearer
|
| 171 |
},
|
| 172 |
body: JSON.stringify({
|
| 173 |
model: "llama-3.1-8b-instant",
|
|
@@ -180,11 +212,15 @@ Action (clear next step)
|
|
| 180 |
const data = await response.json();
|
| 181 |
const result = data.choices[0].message.content;
|
| 182 |
|
| 183 |
-
document.getElementById("aiText").
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
} catch (err) {
|
| 186 |
document.getElementById("aiText").innerText =
|
| 187 |
-
"AI failed. Check API key or
|
| 188 |
}
|
| 189 |
}
|
| 190 |
|
|
|
|
| 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>
|
|
|
|
| 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()"
|
| 95 |
class="mt-5 bg-emerald-600 text-white px-6 py-2 rounded-full">
|
|
|
|
| 98 |
|
| 99 |
</div>
|
| 100 |
|
| 101 |
+
<!-- MAP -->
|
| 102 |
<div class="card bg-white p-8 rounded-xl">
|
| 103 |
|
| 104 |
<h2 class="text-2xl font-bold mb-4">Delivery Route Map</h2>
|
| 105 |
|
| 106 |
+
<iframe
|
| 107 |
+
id="mapFrame"
|
| 108 |
+
src="https://www.google.com/maps?q=Dubai+UAE&output=embed"
|
| 109 |
+
width="100%"
|
| 110 |
+
height="350"
|
| 111 |
+
style="border:0;"
|
| 112 |
+
loading="lazy">
|
| 113 |
+
</iframe>
|
| 114 |
|
| 115 |
+
</div>
|
| 116 |
+
|
| 117 |
+
</section>
|
| 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 |
portionValue.innerText = portions.value;
|
| 174 |
});
|
| 175 |
|
| 176 |
+
// AI FUNCTION
|
| 177 |
async function runAI() {
|
| 178 |
|
| 179 |
const meals = document.getElementById("portions").value;
|
|
|
|
| 182 |
|
| 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 {
|
| 197 |
+
|
| 198 |
const response = await fetch("https://api.groq.com/openai/v1/chat/completions", {
|
| 199 |
method: "POST",
|
| 200 |
headers: {
|
| 201 |
"Content-Type": "application/json",
|
| 202 |
+
"Authorization": "Bearer YOUR_GROQ_API_KEY"
|
| 203 |
},
|
| 204 |
body: JSON.stringify({
|
| 205 |
model: "llama-3.1-8b-instant",
|
|
|
|
| 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 |
|