Spaces:
Running
Running
Update log.html
Browse files16 unmodified lines17181920212220212223242526262728282930313031323435363738394041424344454647484950515233343554555636373839404142434445461 unmodified line484950645152535468555670575859736061757662636465666768698370717273877475899076777879801 unmodified line828384988586871018889103909192931079495969798991131001011021161031041181051061071081 unmodified line1101111121261131141151167 unmodified lines1241251261401271281291301311321331471341351361371381391401411421431441451461551471481491501511521611621531541551641651561571581591601611621711721731741751761771781791801631641651661671851681691881701711721921931941951961971981991731741756 unmodified lines18218318421218518621418718821618919021819119222022122219319422419519619719815 unmodified lines2142152162462472172182502192202217 unmodified lines2292302312642322332342353 unmodified lines2392402412742422432762442452782462472802812822832842852482492502512522532542922932942952962972982993002552562574 unmodified lines26226326431126526626716 unmodified lines.card{ background:white; border:1px solid #e5e7eb; border-radius:18px; padding:24px; margin-bottom:22px; border-radius:16px; padding:20px; margin-bottom:20px;}
.btn{ padding:10px 16px; padding:8px 14px; border-radius:999px; font-weight:700; font-weight:600; cursor:pointer; margin-right:8px; font-size:15px; margin-right:6px;}
.accept{ background:#10b981; color:white;}
.reject{ background:#ef4444; color:white;}
.priority-high{ color:#dc2626; font-weight:800;}
.priority-medium{ color:#d97706; font-weight:800;}.accept{background:#10b981;color:white;}.reject{background:#ef4444;color:white;}
.priority-low{ color:#16a34a; font-weight:800;.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-7 text-3xl font-extrabold"><div class="bg-emerald-600 text-white p-6 text-2xl font-bold"> NourishNet AI System</div>
<div class="p-8 space-y-8 max-w-5xl mx-auto"><div class="p-8 space-y-8">
<!-- INPUT --><!-- INPUT SECTION --><div class="card">
<h2 class="text-3xl font-bold mb-6">Food Input</h2><h2 class="text-2xl font-bold mb-4">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"><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 text-lg"><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-5 mt-2"><input type="range" min="1" max="250" value="50" id="portions" class="w-full mb-4">
<label class="font-semibold text-lg">Expiry</label><select id="expiry" class="w-full border p-4 rounded-xl mt-2 text-lg"><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 --><!-- AI RESULTS --><div class="card">
<h2 class="text-3xl font-bold mb-5">AI Recommendations</h2><h2 class="text-2xl font-bold mb-4">AI Recommendations</h2>
<div id="aiBox" class="text-gray-600 text-lg"><div id="aiBox" class="text-gray-600">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"><button onclick="runAI()" class="mt-4 bg-emerald-600 text-white px-6 py-2 rounded-full">Ask AI</button>
</div>
<!-- MATCHED --><!-- MATCHED RECIPIENTS --><div class="card">
<h2 class="text-3xl font-bold mb-5">Matched Recipients</h2><h2 class="text-2xl font-bold mb-4">Matched Recipients</h2>
<div id="matchedBox" class="text-gray-500 text-lg"><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-10 py-4 rounded-full font-bold text-xl"><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://Infinity-1995-NourishAI.hf.space/analyze";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 ---------------- *//* ---------------- 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 food distribution..."; "π§ AI analyzing new input...";
try{
const res = await fetch(API_URL,{ method:"POST", headers:{ "Content-Type":"application/json" }, body: JSON.stringify({ headers:{"Content-Type":"application/json"}, body:JSON.stringify({ meals, expiry, foodType foodType, expiry }) });
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; }); currentMatches = data;
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 lines document.getElementById("aiBox").innerHTML = currentMatches.map((d,i)=>`
<div class="border p-5 rounded-2xl mb-4"> <div class="border p-4 rounded-xl mb-3">
<div class="text-2xl font-bold">${d.recipient}</div> <div class="font-bold text-lg">${d.recipient}</div>
<div class="text-gray-500 text-lg mt-1">π ${d.km} km away</div> <div class="text-gray-500">π ${d.km} km away</div>
<div class="text-lg mt-3">${d.reason}</div> <div class="text-sm mt-1">${d.reason}</div>
<div class="${getPriorityClass(d.priority)} text-xl mt-3"> ${d.priority} Priority </div> <div class="font-semibold mt-1">${d.priority} Priority</div>
<div class="mt-4"> <div class="mt-3">
<button class="btn accept" onclick="acceptItem(${i})">Accept</button>15 unmodified lines
accepted.push(item);
currentMatches.splice(index,1);
alert(`β
${item.recipient} accepted successfully!`);
renderAI(); renderAccepted();
}7 unmodified lines
}
/* ---------------- MATCHED ---------------- *//* ---------------- MATCHED LIST ---------------- */function renderAccepted(){
const box = document.getElementById("matchedBox");3 unmodified lines return; }
box.innerHTML = accepted.map((a,i)=>` box.innerHTML = accepted.map(a=>`
<div class="border p-4 rounded-2xl mb-3"> <div class="border p-3 rounded-xl mb-2">
<div class="text-xl font-bold">${a.recipient}</div> <div class="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>π ${a.km} km away</div>
</div>
`).join("");}
/* ---------------- REMOVE ---------------- */function removeAccepted(i){
accepted.splice(i,1);
renderAccepted();
}
/* ---------------- CONFIRM ---------------- */function confirmDonation(){
4 unmodified lines
localStorage.setItem("donationData", JSON.stringify({ portions: document.getElementById("portions").value, foodType: document.getElementById("foodType").value, accepted: accepted }));
log.html+58-105