Spaces:
Sleeping
Sleeping
Update app.py
Browse files1 unmodified line23456789101111 unmodified lines23242526272829303132333435361 unmodified linefrom groq import Groqimport os# Groq clientapi_key = os.environ.get("GROQ_API_KEY")def get_recommendation(quantity, food_type, expiry_hours):if quantity < 20:base = "Elderly Individuals"elif quantity < 100:11 unmodified linesExplain why this is the best recipient in 2-3 lines."""response = client.chat.completions.create(model="llama-2-7b-chat",messages=[{"role": "user", "content": prompt}])explanation = response.choices[0].message.contentreturn f"✅ Recommended: {base}\n\n🤖 AI Reasoning:\n{explanation}"# Gradio Blocks UIwith gr.Blocks(title="🍽️ NourishNet AI") as demo:gr.Markdown(1 unmodified line2345678910111213141516171811 unmodified lines30313233343536373839404142434445464748491 unmodified linefrom groq import Groqimport os# Get Groq API key from environmentapi_key = os.environ.get("GROQ_API_KEY")# Initialize Groq client only if key existsclient = Groq(api_key=api_key) if api_key else Nonedef get_recommendation(quantity, food_type, expiry_hours):if not client:return "❌ GROQ_API_KEY not found. Please set your API key in environment variables or Secrets."# Basic routing logicif quantity < 20:base = "Elderly Individuals"elif quantity < 100:11 unmodified linesExplain why this is the best recipient in 2-3 lines."""# AI calltry:response = client.chat.completions.create(model="llama-2-7b-chat",messages=[{"role": "user", "content": prompt}])explanation = response.choices[0].message.contentexcept Exception as e:explanation = f"❌ AI explanation not available:\n{e}"return f"✅ Recommended: {base}\n\n🤖 AI Reasoning:\n{explanation}"# Gradio Blocks UIwith gr.Blocks(title="🍽️ NourishNet AI") as demo:gr.Markdown(
app.py+14-1