Spaces:
Sleeping
Sleeping
Commit ·
3fd4883
1
Parent(s): ae7a494
added bmr calculator tool
Browse files- .gitignore +3 -0
- app.py +5 -4
- tools/bmr_calculator.py +27 -0
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.gradio/
|
| 2 |
+
__pycache__/
|
| 3 |
+
tools/__pycache__/
|
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
@@ -33,16 +34,16 @@ 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 |
|
| 39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 40 |
-
|
| 41 |
|
| 42 |
model = HfApiModel(
|
| 43 |
max_tokens=2096,
|
| 44 |
temperature=0.5,
|
| 45 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 46 |
custom_role_conversions=None,
|
| 47 |
)
|
| 48 |
|
|
@@ -55,7 +56,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,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from tools.bmr_calculator import BMRCalculatorTool
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
|
|
| 34 |
except Exception as e:
|
| 35 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 36 |
|
| 37 |
+
bmr_calculator_tool = BMRCalculatorTool()
|
| 38 |
final_answer = FinalAnswerTool()
|
| 39 |
|
| 40 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 41 |
+
model_id= 'https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 42 |
|
| 43 |
model = HfApiModel(
|
| 44 |
max_tokens=2096,
|
| 45 |
temperature=0.5,
|
| 46 |
+
model_id=model_id, # 'Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 47 |
custom_role_conversions=None,
|
| 48 |
)
|
| 49 |
|
|
|
|
| 56 |
|
| 57 |
agent = CodeAgent(
|
| 58 |
model=model,
|
| 59 |
+
tools=[final_answer, get_current_time_in_timezone, bmr_calculator_tool], ## add your tools here (don't remove final answer)
|
| 60 |
max_steps=6,
|
| 61 |
verbosity_level=1,
|
| 62 |
grammar=None,
|
tools/bmr_calculator.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Optional
|
| 2 |
+
from smolagents.tools import Tool
|
| 3 |
+
import requests
|
| 4 |
+
import markdownify
|
| 5 |
+
import smolagents
|
| 6 |
+
|
| 7 |
+
class BMRCalculatorTool(Tool):
|
| 8 |
+
name = "bmr_calculator"
|
| 9 |
+
description = "Calcuates the basal metabolism rate (BMR) of a male/female given weight (in kgs), height (in cms), age (in yrs), and gender."
|
| 10 |
+
inputs = {
|
| 11 |
+
'gender': {'type': 'string', 'description': 'Gender of the person.'},
|
| 12 |
+
'weight': {'type': 'number', 'description': 'Weight of the person.'},
|
| 13 |
+
'height': {'type': 'number', 'description': 'Height of the person.'},
|
| 14 |
+
'age': {'type': 'number', 'description': 'Age of the person.'}
|
| 15 |
+
}
|
| 16 |
+
output_type = 'string'
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def calculate_bmr(self, gender, weight, height, age):
|
| 20 |
+
if gender.lower() == "male":
|
| 21 |
+
bmr = 88.36 + (13.4 * weight) + (4.8 * height) - (5.7 * age)
|
| 22 |
+
else: # gender == "female":
|
| 23 |
+
bmr = 447.6 + (9.2 * weight) + (3.1 * height) - (4.3 * age)
|
| 24 |
+
return f"Your BMR is {bmr:.2f} calories/day."
|
| 25 |
+
|
| 26 |
+
def forward(self, gender: str, weight: float, height: int, age: int):
|
| 27 |
+
return self.calculate_bmr(gender, weight, height, age)
|