alirezamoshfegh commited on
Commit
bf72402
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +126 -0
app.py CHANGED
@@ -32,7 +32,133 @@ def get_current_time_in_timezone(timezone: str) -> str:
32
  return f"The current local time in {timezone} is: {local_time}"
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
 
 
 
36
 
37
  final_answer = FinalAnswerTool()
38
 
 
32
  return f"The current local time in {timezone} is: {local_time}"
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
+ @tool
36
+ def create_healthy_diet_plan(weight: float, height: float, age: int = 30, gender: str = "not specified", activity_level: str = "moderate") -> str:
37
+ """A tool that creates a personalized healthy diet plan based on user metrics.
38
+
39
+ Args:
40
+ weight: Weight in kilograms (kg)
41
+ height: Height in centimeters (cm)
42
+ age: Age in years (default: 30)
43
+ gender: "male", "female", or "not specified" (default: "not specified")
44
+ activity_level: "sedentary", "light", "moderate", "active", or "very active" (default: "moderate")
45
+ """
46
+ # Calculate BMI
47
+ bmi = weight / ((height/100) ** 2)
48
+ bmi_rounded = round(bmi, 1)
49
+
50
+ # Determine BMI category
51
+ if bmi < 18.5:
52
+ bmi_category = "underweight"
53
+ elif bmi < 25:
54
+ bmi_category = "normal weight"
55
+ elif bmi < 30:
56
+ bmi_category = "overweight"
57
+ else:
58
+ bmi_category = "obese"
59
+
60
+ # Calculate Basal Metabolic Rate (BMR) using Mifflin-St Jeor Equation
61
+ if gender.lower() == "male":
62
+ bmr = 10 * weight + 6.25 * height - 5 * age + 5
63
+ elif gender.lower() == "female":
64
+ bmr = 10 * weight + 6.25 * height - 5 * age - 161
65
+ else:
66
+ # Average of male and female calculations for non-specified gender
67
+ bmr = 10 * weight + 6.25 * height - 5 * age - 78
68
+
69
+ # Activity level multiplier for Total Daily Energy Expenditure (TDEE)
70
+ activity_multipliers = {
71
+ "sedentary": 1.2, # Little or no exercise
72
+ "light": 1.375, # Light exercise 1-3 days/week
73
+ "moderate": 1.55, # Moderate exercise 3-5 days/week
74
+ "active": 1.725, # Hard exercise 6-7 days/week
75
+ "very active": 1.9 # Very hard exercise & physical job or training twice a day
76
+ }
77
+
78
+ multiplier = activity_multipliers.get(activity_level.lower(), 1.55)
79
+ tdee = round(bmr * multiplier)
80
+
81
+ # Diet recommendation based on BMI category
82
+ if bmi_category == "underweight":
83
+ calorie_adjustment = 300 # Surplus for weight gain
84
+ protein_ratio = 1.6 # g per kg of body weight
85
+ diet_focus = "nutrient-dense, calorie-rich foods to gain healthy weight"
86
+ elif bmi_category == "normal weight":
87
+ calorie_adjustment = 0 # Maintenance
88
+ protein_ratio = 1.4
89
+ diet_focus = "balanced nutrition to maintain your healthy weight"
90
+ elif bmi_category == "overweight":
91
+ calorie_adjustment = -300 # Deficit for weight loss
92
+ protein_ratio = 1.8
93
+ diet_focus = "portion control and nutrient-dense, lower-calorie foods"
94
+ else: # obese
95
+ calorie_adjustment = -500 # Larger deficit for weight loss
96
+ protein_ratio = 2.0
97
+ diet_focus = "whole foods with high satiety and controlled portions"
98
+
99
+ # Calculate daily calorie target
100
+ daily_calories = tdee + calorie_adjustment
101
+
102
+ # Calculate macronutrient breakdown
103
+ daily_protein = round(weight * protein_ratio) # grams
104
+ daily_protein_calories = daily_protein * 4 # 4 calories per gram of protein
105
+
106
+ # Fat is about 25-30% of calories
107
+ daily_fat_calories = round(daily_calories * 0.28)
108
+ daily_fat = round(daily_fat_calories / 9) # 9 calories per gram of fat
109
+
110
+ # Remaining calories from carbs
111
+ daily_carb_calories = daily_calories - daily_protein_calories - daily_fat_calories
112
+ daily_carb = round(daily_carb_calories / 4) # 4 calories per gram of carb
113
+
114
+ # Generate diet plan response
115
+ response = f"""
116
+ Based on your measurements:
117
+ - Weight: {weight} kg
118
+ - Height: {height} cm
119
+ - BMI: {bmi_rounded} ({bmi_category})
120
+
121
+ Your estimated daily calorie needs are approximately {daily_calories} calories.
122
+
123
+ RECOMMENDED DAILY NUTRITION:
124
+ • Protein: {daily_protein}g ({round(daily_protein_calories)} calories)
125
+ • Carbohydrates: {daily_carb}g ({round(daily_carb_calories)} calories)
126
+ • Fats: {daily_fat}g ({round(daily_fat_calories)} calories)
127
+
128
+ MEAL PLAN FOCUS:
129
+ Your diet should focus on {diet_focus}.
130
+
131
+ SAMPLE DAILY MEAL STRUCTURE:
132
+
133
+ BREAKFAST (25% of daily calories):
134
+ • Protein source (eggs, Greek yogurt, or protein shake)
135
+ • Complex carbohydrates (oatmeal, whole grain toast)
136
+ • Healthy fat (nuts, seeds, or avocado)
137
+ • Fruit for vitamins and fiber
138
+
139
+ LUNCH (30% of daily calories):
140
+ • Lean protein (chicken, fish, tofu, or legumes)
141
+ • Complex carbohydrates (brown rice, quinoa, or sweet potato)
142
+ • Vegetables (at least 2 varieties)
143
+ • Healthy fat source (olive oil dressing or nuts)
144
+
145
+ DINNER (30% of daily calories):
146
+ • Lean protein (fish, turkey, beef, or plant-based alternative)
147
+ • Non-starchy vegetables (half your plate)
148
+ • Small portion of complex carbohydrates
149
+ • Healthy fat source
150
+
151
+ SNACKS (15% of daily calories):
152
+ • Mid-morning: Fruit with nuts or yogurt
153
+ • Mid-afternoon: Vegetable sticks with hummus or a small protein shake
154
+
155
+ HYDRATION:
156
+ • Aim for 8-10 glasses of water daily
157
+ • Limit sugary drinks and alcohol
158
 
159
+ This plan is personalized based on your metrics and designed to support your health goals while providing adequate nutrition.
160
+ """
161
+ return response
162
 
163
  final_answer = FinalAnswerTool()
164