AADalhat commited on
Commit
4d4d642
·
verified ·
1 Parent(s): 0dca722

Update health_logic.py

Browse files
Files changed (1) hide show
  1. health_logic.py +48 -36
health_logic.py CHANGED
@@ -1,44 +1,56 @@
 
 
 
 
 
 
1
 
2
- def generate_advice(food_data, conditions):
3
- ingredients = [i.lower() for i in food_data.get("ingredients", [])]
4
  risk_score = 0
5
- advice_list = []
6
  flags = []
 
7
 
8
- for condition in conditions:
9
- if condition == "Diabetic":
10
- if "sugar" in ingredients or food_data["carbs"] > 40:
11
- risk_score += 25
12
- flags.append("High carbs/sugar")
13
- advice_list.append("Reduce starchy content, avoid sugary drinks.")
14
- if condition == "Hypertensive":
15
- if "salt" in ingredients or food_data["fat"] > 25:
 
16
  risk_score += 20
17
- flags.append("High salt/fat")
18
- advice_list.append("Use less salt and oil, consider boiling or steaming.")
19
- if condition == "Weight Loss":
20
- if food_data["calories"] > 350:
21
  risk_score += 15
22
- flags.append("High calories")
23
- advice_list.append("Reduce portion size, avoid fried foods.")
24
- if condition == "Malnourished":
25
- if food_data["protein"] < 10:
26
- risk_score += 10
27
- flags.append("Low protein")
28
- advice_list.append("Add beans, eggs, or fish to meals for better nutrition.")
29
- if condition == "Pregnant/Nursing":
30
- if food_data["iron"] < 10:
 
31
  risk_score += 15
32
- flags.append("Low iron")
33
- advice_list.append("Add leafy greens, beans, or iron supplements.")
34
- if condition == "Cholesterol Watch":
35
- if "palm oil" in ingredients or food_data["fat"] > 25:
 
 
 
 
 
 
 
36
  risk_score += 20
37
- flags.append("Saturated fat")
38
- advice_list.append("Reduce palm oil and fried food intake.")
39
- if condition == "Normal":
40
- advice_list.append("Maintain a balanced diet with local ingredients.")
41
-
42
- risk_score = min(risk_score, 100)
43
- final_advice = " ".join(set(advice_list))
44
- return final_advice, risk_score, flags
 
1
+ def generate_advice(food_info, conditions):
2
+ ingredients = [i.lower() for i in food_info["ingredients"]]
3
+ fat = food_info["fat"]
4
+ calories = food_info["calories"]
5
+ carbs = food_info["carbs"]
6
+ protein = food_info["protein"]
7
 
 
 
8
  risk_score = 0
 
9
  flags = []
10
+ advice_parts = []
11
 
12
+ for cond in conditions:
13
+ if cond == "Diabetic":
14
+ if "sugar" in ingredients or carbs > 40:
15
+ risk_score += 30
16
+ flags.append("High carb")
17
+ advice_parts.append("Reduce starchy ingredients or use low-GI substitutes.")
18
+
19
+ if cond == "Hypertensive":
20
+ if "salt" in ingredients:
21
  risk_score += 20
22
+ flags.append("Salt content")
23
+ advice_parts.append("Avoid adding salt; use natural spices.")
24
+ if fat > 25:
 
25
  risk_score += 15
26
+ flags.append("High fat")
27
+
28
+ if cond == "Weight Loss":
29
+ if calories > 400:
30
+ risk_score += 25
31
+ flags.append("High calorie")
32
+ advice_parts.append("Consider smaller portions or reduce oil usage.")
33
+
34
+ if cond == "Malnourished":
35
+ if protein < 10:
36
  risk_score += 15
37
+ flags.append("Low protein")
38
+ advice_parts.append("Add protein-rich sides like beans or eggs.")
39
+
40
+ if cond == "Pregnant/Nursing":
41
+ if protein < 10:
42
+ risk_score += 10
43
+ flags.append("Low protein for pregnancy")
44
+ advice_parts.append("Increase protein with fish, legumes, or eggs.")
45
+
46
+ if cond == "Cholesterol Watch":
47
+ if "palm oil" in ingredients or fat > 25:
48
  risk_score += 20
49
+ flags.append("Cholesterol risk")
50
+ advice_parts.append("Avoid palm oil and fried foods.")
51
+
52
+ if not advice_parts:
53
+ advice_parts.append("No major risks detected. Enjoy in moderation.")
54
+
55
+ advice = " ".join(set(advice_parts))
56
+ return advice, min(risk_score, 100), flags