Spaces:
Running
Running
Update log.html
Browse files2 unmodified lines34567895 unmodified lines1516171819202122232425262728293031325 unmodified lines38394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112 unmodified lines<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>Log Surplus - NourishNet</title><script src="https://cdn.tailwindcss.com"></script><link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">5 unmodified lines}.card{border:1px solid #e5e7eb;border-radius:16px;padding:24px;background:white;margin-bottom:20px;}.btn{padding:10px 18px;border-radius:999px;cursor:pointer;font-weight:600;}.accept{background:#10b981;color:white;}5 unmodified linespadding:4px 10px;border-radius:999px;font-size:12px;font-weight:700;}.high{color:#dc2626;font-weight:700;}.medium{color:#d97706;font-weight:700;}.low{color:#16a34a;font-weight:700;}</style></head><body><!-- HEADER --><div class="bg-emerald-600 text-white p-6 text-2xl font-bold">NourishNet AI</div><div class="p-10 space-y-8"><!-- INPUT --><div class="card"><h2 class="text-2xl font-bold mb-4">Food Details</h2><label class="font-semibold">Food Type</label><select id="foodType" class="w-full border p-3 rounded-lg mt-2 mb-4"><option>Halal Cooked</option><option>Baked Goods</option><option>Raw Ingredients</option><option>Packaged Food</option></select><label class="font-semibold">Portions: <span id="portionValue">50</span></label><input type="range" min="1" max="250" value="50" id="portions" class="w-full mb-4"><label class="font-semibold">Expiry</label><select id="expiry" class="w-full border p-3 rounded-lg mt-2"><option value="6">6 hours</option><option value="24">24 hours</option><option value="48">48 hours</option></select></div><!-- AI BUTTON --><div class="card"><h2 class="text-2xl font-bold mb-4">AI Matching</h2><div id="aiText" class="text-gray-600">Click Ask AI to generate matches...</div><button onclick="runAI()" class="mt-4 bg-emerald-600 text-white px-6 py-2 rounded-full">Ask AI</button></div><!-- RESULTS --><div class="card"><h2 class="text-2xl font-bold mb-4">Matched Recipients</h2><div id="matchBox" class="text-gray-500">No results yet</div></div></div><script>/* ---------------- SLIDER ---------------- */let portionSize = 50;document.getElementById("portions").addEventListener("input", e=>{portionSize = e.target.value;document.getElementById("portionValue").innerText = portionSize;});/* ---------------- API ---------------- *//* 🔥 REPLACE THIS WITH YOUR SPACE URL */const API_URL = "https://Infinity-1995-NourishAI.hf.space/analyze";/* ---------------- FETCH AI ---------------- */async function runAI(){const foodType = document.getElementById("foodType").value;const expiry = document.getElementById("expiry").value;document.getElementById("aiText").innerHTML ="🧠 AI is analyzing food redistribution...";try{const res = await fetch(API_URL,{method:"POST",headers:{"Content-Type":"application/json"},body: JSON.stringify({meals: portionSize,expiry: expiry,foodType: foodType})});const data = await res.json();if(!Array.isArray(data)){document.getElementById("aiText").innerHTML ="❌ Invalid response from AI backend";return;}document.getElementById("aiText").innerHTML =renderAI(data);document.getElementById("matchBox").innerHTML =renderMatches(data);}catch(err){console.error(err);document.getElementById("aiText").innerHTML ="❌ AI request failed. Check backend or API URL.";}}/* ---------------- UI RENDER ---------------- */function renderAI(items){if(items.length === 0){return "No recommendations found.";}return items.map((m,i)=>`<div class="mb-4"><div class="font-bold">${i+1}. ${m.recipient}</div><div class="${m.priority.toLowerCase()}">${m.priority} Priority</div><div class="text-gray-600">${m.reason}</div></div>`).join("");}function renderMatches(items){return items.map((m)=>`<div class="border p-4 rounded-xl mb-3"><div class="font-bold text-lg">${m.recipient}</div><div class="text-gray-500">${m.city} • ${m.km} km away</div><div class="${m.priority.toLowerCase()} font-bold mt-1">${m.priority}</div><div class="text-gray-600 mt-2">${m.reason}</div><div class="badge mt-2">${m.type}</div></div>`).join("");}2 unmodified lines34567895 unmodified lines151617181920212223242526272829303132335 unmodified lines394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062 unmodified lines<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>NourishNet AI</title><script src="https://cdn.tailwindcss.com"></script><link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">5 unmodified lines}.card{background:white;border:1px solid #e5e7eb;border-radius:16px;padding:20px;margin-bottom:20px;}.btn{padding:8px 14px;border-radius:999px;font-weight:600;cursor:pointer;margin-right:8px;}.accept{background:#10b981;color:white;}5 unmodified linespadding:4px 10px;border-radius:999px;font-size:12px;display:inline-block;margin-top:8px;}</style></head><body><div class="bg-emerald-600 text-white p-6 text-2xl font-bold">NourishNet AI Matching</div><div class="p-8 space-y-8"><!-- AI RESULTS --><div class="card"><h2 class="text-2xl font-bold mb-4">AI Recommendations</h2><div id="aiBox" class="text-gray-600">Click Ask AI to generate matches</div><button onclick="runAI()" class="mt-4 bg-emerald-600 text-white px-6 py-2 rounded-full">Ask AI</button></div><!-- MATCHED --><div class="card"><h2 class="text-2xl font-bold mb-4">Matched Recipients (Accepted)</h2><div id="matchedBox" class="text-gray-500">No accepted recipients yet</div></div></div><script>/* ---------------- STATE ---------------- */let accepted = [];let lastData = [];/* ---------------- API ---------------- */const API_URL = "https://Infinity-1995-NourishAI.hf.space/analyze";/* ---------------- FETCH AI ---------------- */async function runAI(){document.getElementById("aiBox").innerHTML ="🧠 AI analyzing food distribution...";try{const res = await fetch(API_URL,{method:"POST",headers:{ "Content-Type":"application/json" },body: JSON.stringify({meals: 50,expiry: 24,foodType: "Mixed"})});const data = await res.json();lastData = data;renderAI(data);}catch(err){document.getElementById("aiBox").innerHTML ="❌ AI failed. Check backend.";}}/* ---------------- RENDER AI LIST ---------------- */function renderAI(data){document.getElementById("aiBox").innerHTML =data.map((d,i)=>`<div class="border p-4 rounded-xl mb-3"><div class="font-bold text-lg">${d.recipient}</div><div class="text-gray-500">📍 ${d.km} km away</div><div class="text-sm mt-1">${d.reason}</div><div class="badge">${d.priority} Priority</div><div class="mt-3"><button class="btn accept"onclick="acceptRecipient(${i})">Accept</button><button class="btn reject"onclick="rejectRecipient(${i})">Reject</button></div></div>`).join("");}/* ---------------- ACCEPT ---------------- */function acceptRecipient(index){const item = lastData[index];accepted.push(item);renderAccepted();}/* ---------------- REJECT ---------------- */function rejectRecipient(index){lastData.splice(index,1);renderAI(lastData);}/* ---------------- RENDER ACCEPTED ---------------- */function renderAccepted(){if(accepted.length === 0){document.getElementById("matchedBox").innerHTML ="No accepted recipients yet";return;}document.getElementById("matchedBox").innerHTML =accepted.map(a=>`<div class="border p-3 rounded-xl mb-2"><div class="font-bold">${a.recipient}</div><div class="text-gray-600">📍 ${a.km} km away</div></div>`).join("");}
log.html+106-111