Spaces:
Running
Running
Update log.html
Browse files16 unmodified lines171819202122232425262728293031323334353637383940414243444546474849505152535455565758591 unmodified line6162636465666768697071727374757677787980818283848586878889909192931 unmodified line95969798991001011021031041051061071081091101111121131141151161171181191201211 unmodified line1231241251261271281297 unmodified lines1371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012026 unmodified lines20921021121221321421521621721821922022122222322422522622715 unmodified lines2432442452462472482492502512522537 unmodified lines2612622632642652662673 unmodified lines2712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023034 unmodified lines30830931031131231331416 unmodified lines.card{background:white;border:1px solid #e5e7eb;border-radius:18px;padding:24px;margin-bottom:22px;}.btn{padding:10px 16px;border-radius:999px;font-weight:700;cursor:pointer;margin-right:8px;font-size:15px;}.accept{background:#10b981;color:white;}.reject{background:#ef4444;color:white;}.priority-high{color:#dc2626;font-weight:800;}.priority-medium{color:#d97706;font-weight:800;}.priority-low{color:#16a34a;font-weight:800;}</style></head>1 unmodified line<body><!-- HEADER --><div class="bg-emerald-600 text-white p-7 text-3xl font-extrabold">NourishNet AI System</div><div class="p-8 space-y-8 max-w-5xl mx-auto"><!-- INPUT --><div class="card"><h2 class="text-3xl font-bold mb-6">Food Input</h2><label class="font-semibold text-lg">Food Type</label><select id="foodType" class="w-full border p-4 rounded-xl mt-2 mb-5 text-lg"><option>Halal Cooked</option><option>Baked Goods</option><option>Raw Ingredients</option><option>Packaged Food</option></select><label class="font-semibold text-lg">Portions: <span id="portionValue">50</span></label><input type="range" min="1" max="250" value="50" id="portions" class="w-full mb-5 mt-2"><label class="font-semibold text-lg">Expiry</label><select id="expiry" class="w-full border p-4 rounded-xl mt-2 text-lg"><option value="6">6 hours</option><option value="24">24 hours</option><option value="48">48 hours</option>1 unmodified line</div><!-- AI --><div class="card"><h2 class="text-3xl font-bold mb-5">AI Recommendations</h2><div id="aiBox" class="text-gray-600 text-lg">Click "Ask AI" to generate matches</div><button onclick="runAI()" class="mt-5 bg-emerald-600 text-white px-8 py-3 rounded-full text-lg font-bold">Ask AI</button></div><!-- MATCHED --><div class="card"><h2 class="text-3xl font-bold mb-5">Matched Recipients</h2><div id="matchedBox" class="text-gray-500 text-lg">No accepted recipients yet</div>1 unmodified line<!-- CONFIRM --><div class="text-center"><button onclick="confirmDonation()" class="bg-emerald-600 text-white px-10 py-4 rounded-full font-bold text-xl">Confirm Donation</button></div>7 unmodified lineslet accepted = [];/* ---------------- API ---------------- */const API_URL = "https://Infinity-1995-NourishAI.hf.space/analyze";/* ---------------- SLIDER ---------------- */document.getElementById("portions").addEventListener("input", e=>{document.getElementById("portionValue").innerText = e.target.value;});/* ---------------- RUN AI ---------------- */async function runAI(){const meals = document.getElementById("portions").value;const expiry = document.getElementById("expiry").value;const foodType = document.getElementById("foodType").value;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,expiry,foodType})});const data = await res.json();currentMatches = data.sort((a,b)=>{const rank = {High:3, Medium:2, Low:1};if(rank[b.priority] !== rank[a.priority]){return rank[b.priority] - rank[a.priority];}return a.km - b.km;});renderAI();}catch(err){document.getElementById("aiBox").innerHTML ="β AI request failed";}}/* ---------------- PRIORITY CLASS ---------------- */function getPriorityClass(priority){if(priority === "High") return "priority-high";if(priority === "Medium") return "priority-medium";return "priority-low";}/* ---------------- AI LIST ---------------- */function renderAI(){6 unmodified linesdocument.getElementById("aiBox").innerHTML =currentMatches.map((d,i)=>`<div class="border p-5 rounded-2xl mb-4"><div class="text-2xl font-bold">${d.recipient}</div><div class="text-gray-500 text-lg mt-1">π ${d.km} km away</div><div class="text-lg mt-3">${d.reason}</div><div class="${getPriorityClass(d.priority)} text-xl mt-3">${d.priority} Priority</div><div class="mt-4"><button class="btn accept"onclick="acceptItem(${i})">Accept</button>15 unmodified linesaccepted.push(item);currentMatches.splice(index,1);alert(`β ${item.recipient} accepted successfully!`);renderAI();renderAccepted();}7 unmodified lines}/* ---------------- MATCHED ---------------- */function renderAccepted(){const box = document.getElementById("matchedBox");3 unmodified linesreturn;}box.innerHTML = accepted.map((a,i)=>`<div class="border p-4 rounded-2xl mb-3"><div class="text-xl font-bold">${a.recipient}</div><div class="text-lg mt-1">π ${a.km} km away</div><button class="btn reject mt-3"onclick="removeAccepted(${i})">Reject</button></div>`).join("");}/* ---------------- REMOVE ---------------- */function removeAccepted(i){accepted.splice(i,1);renderAccepted();}/* ---------------- CONFIRM ---------------- */function confirmDonation(){4 unmodified lineslocalStorage.setItem("donationData", JSON.stringify({portions: document.getElementById("portions").value,foodType: document.getElementById("foodType").value,accepted: accepted}));16 unmodified lines1718192021222324252627282930313233343536373839404142434445461 unmodified line4849505152535455565758596061626364656667686970717273747576777879801 unmodified line8283848586878889909192939495969798991001011021031041051061071081 unmodified line1101111121131141151167 unmodified lines1241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741756 unmodified lines18218318418518618718818919019119219319419519619719815 unmodified lines2142152162172182192202217 unmodified lines2292302312322332342353 unmodified lines2392402412422432442452462472482492502512522532542552562574 unmodified lines26226326426526626716 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:6px;}.accept{background:#10b981;color:white;}.reject{background:#ef4444;color:white;}.badge{background:#ecfdf5;color:#059669;padding:4px 10px;border-radius:999px;font-size:12px;display:inline-block;margin-top:6px;}</style></head>1 unmodified line<body><!-- HEADER --><div class="bg-emerald-600 text-white p-6 text-2xl font-bold">NourishNet AI System</div><div class="p-8 space-y-8"><!-- INPUT SECTION --><div class="card"><h2 class="text-2xl font-bold mb-4">Food Input</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>1 unmodified line</div><!-- 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 RECIPIENTS --><div class="card"><h2 class="text-2xl font-bold mb-4">Matched Recipients</h2><div id="matchedBox" class="text-gray-500">No accepted recipients yet</div>1 unmodified line<!-- CONFIRM --><div class="text-center"><button onclick="confirmDonation()" class="bg-emerald-600 text-white px-8 py-3 rounded-full font-semibold">Confirm Donation</button></div>7 unmodified lineslet accepted = [];/* ---------------- API ---------------- */const API_URL = "https://YOUR-SPACE-NAME.hf.space/analyze";/* ---------------- SLIDER ---------------- */document.getElementById("portions").addEventListener("input", e=>{document.getElementById("portionValue").innerText = e.target.value;});/* ---------------- RUN AI (FIXED) ---------------- */async function runAI(){const meals = document.getElementById("portions").value;const expiry = document.getElementById("expiry").value;const foodType = document.getElementById("foodType").value;// π₯ FIX: RESET STATE EVERY RUN (IMPORTANT)currentMatches = [];accepted = [];document.getElementById("matchedBox").innerHTML = "";document.getElementById("aiBox").innerHTML ="π§ AI analyzing new input...";try{const res = await fetch(API_URL,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({meals,foodType,expiry})});const data = await res.json();currentMatches = data;renderAI();}catch(err){document.getElementById("aiBox").innerHTML ="β AI request failed";}}/* ---------------- AI LIST ---------------- */function renderAI(){6 unmodified linesdocument.getElementById("aiBox").innerHTML =currentMatches.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="font-semibold mt-1">${d.priority} Priority</div><div class="mt-3"><button class="btn accept"onclick="acceptItem(${i})">Accept</button>15 unmodified linesaccepted.push(item);alert(`β ${item.recipient} accepted successfully!`);renderAccepted();}7 unmodified lines}/* ---------------- MATCHED LIST ---------------- */function renderAccepted(){const box = document.getElementById("matchedBox");3 unmodified linesreturn;}box.innerHTML = accepted.map(a=>`<div class="border p-3 rounded-xl mb-2"><div class="font-bold">${a.recipient}</div><div>π ${a.km} km away</div></div>`).join("");}/* ---------------- CONFIRM ---------------- */function confirmDonation(){4 unmodified lineslocalStorage.setItem("donationData", JSON.stringify({portions: document.getElementById("portions").value,accepted: accepted}));
log.html+58-105