Spaces:
Sleeping
Sleeping
| from typing import Any, Optional | |
| from smolagents.tools import Tool | |
| import requests | |
| import markdownify | |
| import smolagents | |
| class BMRCalculatorTool(Tool): | |
| name = "bmr_calculator" | |
| description = "Calcuates the basal metabolism rate (BMR) of a male/female given weight (in kgs), height (in cms), age (in yrs), and gender." | |
| inputs = { | |
| 'gender': {'type': 'string', 'description': 'Gender of the person.'}, | |
| 'weight': {'type': 'number', 'description': 'Weight of the person.'}, | |
| 'height': {'type': 'number', 'description': 'Height of the person.'}, | |
| 'age': {'type': 'number', 'description': 'Age of the person.'} | |
| } | |
| output_type = 'string' | |
| def calculate_bmr(self, gender, weight, height, age): | |
| if gender.lower() == "male": | |
| bmr = 88.36 + (13.4 * weight) + (4.8 * height) - (5.7 * age) | |
| else: # gender == "female": | |
| bmr = 447.6 + (9.2 * weight) + (3.1 * height) - (4.3 * age) | |
| return f"Your BMR is {bmr:.2f} calories/day." | |
| def forward(self, gender: str, weight: float, height: int, age: int): | |
| return self.calculate_bmr(gender, weight, height, age) |