Spaces:
Sleeping
Sleeping
Added new tools for health
Browse files
app.py
CHANGED
|
@@ -4,19 +4,74 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +110,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer, image_generation_tool, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from typing import Tuple
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
|
|
| 11 |
@tool
|
| 12 |
+
def calculate_bmi(weight: float, height: float) -> str:
|
| 13 |
+
"""A tool that calculates the Body Mass Index (BMI).
|
| 14 |
+
|
| 15 |
Args:
|
| 16 |
+
weight: The weight of the person in kilograms.
|
| 17 |
+
height: The height of the person in meters.
|
| 18 |
+
|
| 19 |
+
Returns:
|
| 20 |
+
A string displaying the BMI and its classification.
|
| 21 |
"""
|
| 22 |
+
try:
|
| 23 |
+
bmi = weight / (height ** 2)
|
| 24 |
+
classification = (
|
| 25 |
+
"Underweight" if bmi < 18.5 else
|
| 26 |
+
"Normal weight" if bmi < 24.9 else
|
| 27 |
+
"Overweight" if bmi < 29.9 else
|
| 28 |
+
"Obese"
|
| 29 |
+
)
|
| 30 |
+
return f"BMI: {bmi:.2f} ({classification})"
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return f"Error calculating BMI: {str(e)}"
|
| 33 |
+
|
| 34 |
+
@tool
|
| 35 |
+
def calculate_bmr(weight: float, height: float, age: int, sex: str) -> str:
|
| 36 |
+
"""A tool that calculates the Basal Metabolic Rate (BMR) using the Mifflin-St Jeor Equation.
|
| 37 |
+
|
| 38 |
+
Args:
|
| 39 |
+
weight: The weight of the person in kilograms.
|
| 40 |
+
height: The height of the person in centimeters.
|
| 41 |
+
age: The age of the person in years.
|
| 42 |
+
sex: The biological sex of the person ('male' or 'female').
|
| 43 |
+
|
| 44 |
+
Returns:
|
| 45 |
+
A string displaying the calculated BMR.
|
| 46 |
+
"""
|
| 47 |
+
try:
|
| 48 |
+
if sex.lower() == "male":
|
| 49 |
+
bmr = 88.36 + (13.4 * weight) + (4.8 * height) - (5.7 * age)
|
| 50 |
+
elif sex.lower() == "female":
|
| 51 |
+
bmr = 447.6 + (9.2 * weight) + (3.1 * height) - (4.3 * age)
|
| 52 |
+
else:
|
| 53 |
+
return "Error: Invalid sex input. Use 'male' or 'female'."
|
| 54 |
+
|
| 55 |
+
return f"BMR: {bmr:.2f} kcal/day"
|
| 56 |
+
except Exception as e:
|
| 57 |
+
return f"Error calculating BMR: {str(e)}"
|
| 58 |
+
|
| 59 |
+
@tool
|
| 60 |
+
def calculate_water_requirement(weight: float) -> str:
|
| 61 |
+
"""A tool that calculates the daily water intake requirement.
|
| 62 |
+
|
| 63 |
+
Args:
|
| 64 |
+
weight: The weight of the person in kilograms.
|
| 65 |
+
|
| 66 |
+
Returns:
|
| 67 |
+
A string displaying the recommended daily water intake in liters.
|
| 68 |
+
"""
|
| 69 |
+
try:
|
| 70 |
+
water_intake = 0.033 * weight
|
| 71 |
+
return f"Recommended daily water intake: {water_intake:.2f} liters"
|
| 72 |
+
except Exception as e:
|
| 73 |
+
return f"Error calculating water requirement: {str(e)}"
|
| 74 |
+
|
| 75 |
|
| 76 |
@tool
|
| 77 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 110 |
|
| 111 |
agent = CodeAgent(
|
| 112 |
model=model,
|
| 113 |
+
tools=[final_answer, image_generation_tool, get_current_time_in_timezone, DuckDuckGoSearchTool(), calculate_water_requirement, calculate_bmi, calculate_bmr], ## add your tools here (don't remove final answer)
|
| 114 |
max_steps=6,
|
| 115 |
verbosity_level=1,
|
| 116 |
grammar=None,
|