Spaces:
Sleeping
Sleeping
Create app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import gradio as grfrom groq import Groqimport os
# Load API key from Hugging Face Secretsclient = Groq(api_key=os.environ.get("GROQ_API_KEY"))
def get_recommendation(quantity, food_type, expiry_hours): # Basic logic (fast + reliable) if quantity < 20: base = "Elderly Individuals" elif quantity < 100: base = "Care Homes" else: base = "NGOs / Refugee Centers"
# AI explanation prompt = f""" A restaurant has: - {quantity} meals - Food type: {food_type} - Expiry in {expiry_hours} hours
The system selected: {base}
Explain why this is the best recipient in 2-3 lines. """
response = client.chat.completions.create( model="llama3-70b-8192", messages=[{"role": "user", "content": prompt}] )
explanation = response.choices[0].message.content
return f"✅ Recommended: {base}\n\n🤖 AI Reasoning:\n{explanation}"
# Gradio UIdemo = gr.Interface( fn=get_recommendation, inputs=[ gr.Number(label="Number of Meals"), gr.Dropdown(["halal", "soft", "packaged"], label="Food Type"), gr.Number(label="Hours Until Expiry") ], outputs="text", title="🍽️ NourishNet AI", description="AI-powered food surplus redistribution system")
if __name__ == "__main__": demo.launch()app.pyAdded+53