Spaces:
Sleeping
Sleeping
Added BMI calculator Tool
Browse files
app.py
CHANGED
@@ -33,6 +33,53 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
final_answer = FinalAnswerTool()
|
38 |
|
@@ -55,7 +102,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
36 |
+
@tool
|
37 |
+
def calculate_bmi(weight: float, height: float) -> str:
|
38 |
+
"""A tool that calculates the Body Mass Index (BMI) given weight and height,
|
39 |
+
and provides health recommendations based on the BMI value.
|
40 |
+
|
41 |
+
Args:
|
42 |
+
weight: Your weight in kilograms.
|
43 |
+
height: Your height in meters or centimeters.
|
44 |
+
If the value is greater than 3, it is assumed to be in centimeters.
|
45 |
+
"""
|
46 |
+
try:
|
47 |
+
# If height is provided in centimeters (i.e., greater than 3), convert to meters.
|
48 |
+
if height > 3:
|
49 |
+
height = height / 100.0
|
50 |
+
|
51 |
+
bmi = weight / (height ** 2)
|
52 |
+
bmi = round(bmi, 2)
|
53 |
+
|
54 |
+
if bmi < 18.5:
|
55 |
+
category = "Underweight"
|
56 |
+
recommendation = (
|
57 |
+
"Consider increasing your calorie intake with nutrient-dense foods, "
|
58 |
+
"and possibly consult a healthcare provider for a tailored plan."
|
59 |
+
)
|
60 |
+
elif bmi < 25:
|
61 |
+
category = "Normal weight"
|
62 |
+
recommendation = (
|
63 |
+
"Great job maintaining a healthy weight! Keep up with your balanced diet "
|
64 |
+
"and regular physical activity."
|
65 |
+
)
|
66 |
+
elif bmi < 30:
|
67 |
+
category = "Overweight"
|
68 |
+
recommendation = (
|
69 |
+
"A balanced diet and regular exercise might help in managing your weight. "
|
70 |
+
"It could be helpful to consult with a nutritionist for personalized advice."
|
71 |
+
)
|
72 |
+
else:
|
73 |
+
category = "Obese"
|
74 |
+
recommendation = (
|
75 |
+
"It's advisable to consult a healthcare professional for personalized recommendations "
|
76 |
+
"regarding nutrition and exercise."
|
77 |
+
)
|
78 |
+
|
79 |
+
return f"Your BMI is {bmi} ({category}). {recommendation}"
|
80 |
+
except Exception as e:
|
81 |
+
return f"Error calculating BMI: {str(e)}"
|
82 |
+
|
83 |
|
84 |
final_answer = FinalAnswerTool()
|
85 |
|
|
|
102 |
|
103 |
agent = CodeAgent(
|
104 |
model=model,
|
105 |
+
tools=[final_answer, calculate_bmi, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
106 |
max_steps=6,
|
107 |
verbosity_level=1,
|
108 |
grammar=None,
|