Spaces:
Sleeping
Sleeping
Update app.py to add a tool called age_in_animal_years where the user enters name , age and pick animal they want to convert their age to
Browse filesadded tool called age_in_animal_years where the user enters:
1. Their name (string)
2. Their age in human years (integer)
3. The animal (string) they want to convert their age to
app.py
CHANGED
@@ -7,16 +7,32 @@ 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:
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
|
|
10 |
@tool
|
11 |
+
def age_in_animal_years(name: str, age: int, animal: str) -> str:
|
12 |
+
"""Converts a human age into equivalent years for a chosen animal.
|
13 |
+
|
14 |
Args:
|
15 |
+
name: The person's name.
|
16 |
+
age: The age in human years.
|
17 |
+
animal: The animal to convert the age into (e.g., 'dog', 'cat', 'rabbit', 'turtle').
|
18 |
"""
|
19 |
+
# Conversion rates — you can expand this!
|
20 |
+
conversion_rates = {
|
21 |
+
"dog": 7,
|
22 |
+
"cat": 6,
|
23 |
+
"rabbit": 12,
|
24 |
+
"turtle": 0.5,
|
25 |
+
"parrot": 5,
|
26 |
+
"elephant": 1,
|
27 |
+
"hamster": 25
|
28 |
+
}
|
29 |
+
|
30 |
+
animal_lower = animal.lower()
|
31 |
+
if animal_lower not in conversion_rates:
|
32 |
+
return f"Sorry, I don't know how to convert to '{animal}'. Try dog, cat, rabbit, turtle, parrot, elephant, or hamster."
|
33 |
+
|
34 |
+
converted_age = age * conversion_rates[animal_lower]
|
35 |
+
return f"{name} is {converted_age} years old in {animal_lower} years!"
|
36 |
|
37 |
@tool
|
38 |
def get_current_time_in_timezone(timezone: str) -> str:
|