Infinity-1995 commited on
Commit
051cc9c
·
verified ·
1 Parent(s): 10dfbfe

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from groq import Groq
3
+ import os
4
+
5
+ # Load API key from Hugging Face Secrets
6
+ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
7
+
8
+ def get_recommendation(quantity, food_type, expiry_hours):
9
+ # Basic logic (fast + reliable)
10
+ if quantity < 20:
11
+ base = "Elderly Individuals"
12
+ elif quantity < 100:
13
+ base = "Care Homes"
14
+ else:
15
+ base = "NGOs / Refugee Centers"
16
+
17
+ # AI explanation
18
+ prompt = f"""
19
+ A restaurant has:
20
+ - {quantity} meals
21
+ - Food type: {food_type}
22
+ - Expiry in {expiry_hours} hours
23
+
24
+ The system selected: {base}
25
+
26
+ Explain why this is the best recipient in 2-3 lines.
27
+ """
28
+
29
+ response = client.chat.completions.create(
30
+ model="llama3-70b-8192",
31
+ messages=[{"role": "user", "content": prompt}]
32
+ )
33
+
34
+ explanation = response.choices[0].message.content
35
+
36
+ return f"✅ Recommended: {base}\n\n🤖 AI Reasoning:\n{explanation}"
37
+
38
+
39
+ # Gradio UI
40
+ demo = gr.Interface(
41
+ fn=get_recommendation,
42
+ inputs=[
43
+ gr.Number(label="Number of Meals"),
44
+ gr.Dropdown(["halal", "soft", "packaged"], label="Food Type"),
45
+ gr.Number(label="Hours Until Expiry")
46
+ ],
47
+ outputs="text",
48
+ title="🍽️ NourishNet AI",
49
+ description="AI-powered food surplus redistribution system"
50
+ )
51
+
52
+ if __name__ == "__main__":
53
+ demo.launch()