Spaces:
Running
Running
Update health_logic.py
Browse files- 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
|
| 9 |
-
if
|
| 10 |
-
if "sugar" in ingredients or
|
| 11 |
-
risk_score +=
|
| 12 |
-
flags.append("High
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
risk_score += 20
|
| 17 |
-
flags.append("
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
if food_data["calories"] > 350:
|
| 21 |
risk_score += 15
|
| 22 |
-
flags.append("High
|
| 23 |
-
|
| 24 |
-
if
|
| 25 |
-
if
|
| 26 |
-
risk_score +=
|
| 27 |
-
flags.append("
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
risk_score += 15
|
| 32 |
-
flags.append("Low
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
risk_score += 20
|
| 37 |
-
flags.append("
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
return
|
|
|
|
| 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
|