Spaces:
Running
Running
Update log.html
Browse files
log.html
CHANGED
|
@@ -23,6 +23,13 @@ body {
|
|
| 23 |
border: 1px solid #10b981;
|
| 24 |
box-shadow: 0 20px 30px rgba(0,0,0,0.08);
|
| 25 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
</style>
|
| 27 |
</head>
|
| 28 |
|
|
@@ -44,8 +51,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
|
| 48 |
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
</section>
|
| 50 |
|
| 51 |
<!-- INPUT -->
|
|
@@ -76,13 +88,13 @@ body {
|
|
| 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
|
| 86 |
</div>
|
| 87 |
|
| 88 |
<button onclick="runAI()"
|
|
@@ -140,13 +152,59 @@ portions.addEventListener("input", () => {
|
|
| 140 |
portionValue.innerText = portions.value;
|
| 141 |
});
|
| 142 |
|
| 143 |
-
//
|
| 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,11 +215,9 @@ async function runAI() {
|
|
| 157 |
let hours = expiryText.includes("6") ? 3 : expiryText.includes("24") ? 12 : 30;
|
| 158 |
|
| 159 |
const prompt = `
|
| 160 |
-
You are NourishNet AI (
|
| 161 |
-
|
| 162 |
-
DO NOT give diets or meals.
|
| 163 |
|
| 164 |
-
|
| 165 |
|
| 166 |
INPUT:
|
| 167 |
Meals: ${meals}
|
|
@@ -169,10 +225,10 @@ Hours: ${hours}
|
|
| 169 |
Food: ${foodType}
|
| 170 |
|
| 171 |
OUTPUT FORMAT:
|
| 172 |
-
Priority:
|
| 173 |
-
Recipient:
|
| 174 |
-
Reason:
|
| 175 |
-
Action:
|
| 176 |
`;
|
| 177 |
|
| 178 |
try {
|
|
@@ -181,7 +237,7 @@ Action: short
|
|
| 181 |
method: "POST",
|
| 182 |
headers: {
|
| 183 |
"Content-Type": "application/json",
|
| 184 |
-
"Authorization": "Bearer
|
| 185 |
},
|
| 186 |
body: JSON.stringify({
|
| 187 |
model: "llama-3.1-8b-instant",
|
|
@@ -192,9 +248,11 @@ Action: short
|
|
| 192 |
const data = await response.json();
|
| 193 |
const result = data.choices[0].message.content;
|
| 194 |
|
| 195 |
-
//
|
| 196 |
document.getElementById("aiText").innerHTML =
|
| 197 |
-
`<
|
|
|
|
|
|
|
| 198 |
|
| 199 |
// detect recipient
|
| 200 |
let recipient = "Refugee Center";
|
|
|
|
| 23 |
border: 1px solid #10b981;
|
| 24 |
box-shadow: 0 20px 30px rgba(0,0,0,0.08);
|
| 25 |
}
|
| 26 |
+
|
| 27 |
+
/* AI TEXT STYLE */
|
| 28 |
+
#aiText {
|
| 29 |
+
font-family: 'Inter', sans-serif;
|
| 30 |
+
line-height: 1.6;
|
| 31 |
+
font-size: 15px;
|
| 32 |
+
}
|
| 33 |
</style>
|
| 34 |
</head>
|
| 35 |
|
|
|
|
| 51 |
<section class="px-10 py-10">
|
| 52 |
<h1 class="text-4xl font-extrabold">Log Surplus Food</h1>
|
| 53 |
<p class="text-gray-600 mt-2 text-lg">
|
| 54 |
+
AI + Location-based redistribution system
|
| 55 |
</p>
|
| 56 |
+
|
| 57 |
+
<button onclick="getUserLocation()"
|
| 58 |
+
class="mt-4 bg-emerald-600 text-white px-4 py-2 rounded-full">
|
| 59 |
+
📍 Use My Location
|
| 60 |
+
</button>
|
| 61 |
</section>
|
| 62 |
|
| 63 |
<!-- INPUT -->
|
|
|
|
| 88 |
|
| 89 |
</div>
|
| 90 |
|
| 91 |
+
<!-- AI OUTPUT -->
|
| 92 |
<div class="card bg-white p-8 rounded-xl">
|
| 93 |
|
| 94 |
<h2 class="text-2xl font-bold mb-4">AI Recommendation</h2>
|
| 95 |
|
| 96 |
<div id="aiText" class="text-gray-600">
|
| 97 |
+
Click “Ask AI” to generate analysis...
|
| 98 |
</div>
|
| 99 |
|
| 100 |
<button onclick="runAI()"
|
|
|
|
| 152 |
portionValue.innerText = portions.value;
|
| 153 |
});
|
| 154 |
|
| 155 |
+
// map locations
|
| 156 |
const locations = {
|
| 157 |
"Elderly Home": "Al Rahma Elderly Home Dubai",
|
| 158 |
"Refugee Center": "Hope Refugee Center Dubai",
|
| 159 |
"Food Bank": "Dubai Food Bank"
|
| 160 |
};
|
| 161 |
|
| 162 |
+
// clean AI formatter
|
| 163 |
+
function formatAIText(text) {
|
| 164 |
+
|
| 165 |
+
text = text.replace(/\*\*/g, "");
|
| 166 |
+
|
| 167 |
+
const lines = text.split("\n").filter(l => l.trim() !== "");
|
| 168 |
+
|
| 169 |
+
let html = "";
|
| 170 |
+
|
| 171 |
+
lines.forEach(line => {
|
| 172 |
+
|
| 173 |
+
if (line.toLowerCase().includes("priority")) {
|
| 174 |
+
html += `<div class="text-lg font-bold text-emerald-700 mt-3">${line}</div>`;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
else if (line.toLowerCase().includes("recipient")) {
|
| 178 |
+
html += `<div class="text-md font-semibold text-gray-800 mt-2">${line}</div>`;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
else if (line.toLowerCase().includes("action")) {
|
| 182 |
+
html += `<div class="text-md font-semibold text-blue-700 mt-2">${line}</div>`;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
else {
|
| 186 |
+
html += `<div class="text-gray-600 mt-1">${line}</div>`;
|
| 187 |
+
}
|
| 188 |
+
});
|
| 189 |
+
|
| 190 |
+
return html;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
// get location
|
| 194 |
+
function getUserLocation() {
|
| 195 |
+
|
| 196 |
+
navigator.geolocation.getCurrentPosition((pos) => {
|
| 197 |
+
|
| 198 |
+
const lat = pos.coords.latitude;
|
| 199 |
+
const lng = pos.coords.longitude;
|
| 200 |
+
|
| 201 |
+
document.getElementById("mapFrame").src =
|
| 202 |
+
`https://www.google.com/maps?q=${lat},${lng}&output=embed`;
|
| 203 |
+
|
| 204 |
+
});
|
| 205 |
+
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
// AI FUNCTION
|
| 209 |
async function runAI() {
|
| 210 |
|
|
|
|
| 215 |
let hours = expiryText.includes("6") ? 3 : expiryText.includes("24") ? 12 : 30;
|
| 216 |
|
| 217 |
const prompt = `
|
| 218 |
+
You are NourishNet AI (logistics system ONLY).
|
|
|
|
|
|
|
| 219 |
|
| 220 |
+
Do NOT give diet or meal suggestions.
|
| 221 |
|
| 222 |
INPUT:
|
| 223 |
Meals: ${meals}
|
|
|
|
| 225 |
Food: ${foodType}
|
| 226 |
|
| 227 |
OUTPUT FORMAT:
|
| 228 |
+
Priority:
|
| 229 |
+
Recipient:
|
| 230 |
+
Reason:
|
| 231 |
+
Action:
|
| 232 |
`;
|
| 233 |
|
| 234 |
try {
|
|
|
|
| 237 |
method: "POST",
|
| 238 |
headers: {
|
| 239 |
"Content-Type": "application/json",
|
| 240 |
+
"Authorization": "Bearer YOUR_GROQ_API_KEY"
|
| 241 |
},
|
| 242 |
body: JSON.stringify({
|
| 243 |
model: "llama-3.1-8b-instant",
|
|
|
|
| 248 |
const data = await response.json();
|
| 249 |
const result = data.choices[0].message.content;
|
| 250 |
|
| 251 |
+
// clean UI output
|
| 252 |
document.getElementById("aiText").innerHTML =
|
| 253 |
+
`<div class="bg-emerald-50 border border-emerald-200 rounded-xl p-5 shadow-sm">
|
| 254 |
+
${formatAIText(result)}
|
| 255 |
+
</div>`;
|
| 256 |
|
| 257 |
// detect recipient
|
| 258 |
let recipient = "Refugee Center";
|