Spaces:
Runtime error
Runtime error
Update app.py
Browse filesAdded a Zodiac function!
app.py
CHANGED
|
@@ -9,14 +9,88 @@ 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 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""
|
|
|
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +129,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,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_zodiac_info(birth_month:str, birth_year:int)-> str: #it's import to specify the return type
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
+
"""
|
| 15 |
+
A tool that returns your Zodiac sign and Chinese zodiac animal based on birth month and year.
|
| 16 |
+
|
| 17 |
Args:
|
| 18 |
+
birth_month (str): Month of birth (e.g., "February")
|
| 19 |
+
birth_year (int): Year of birth (e.g., 1988)
|
| 20 |
+
|
| 21 |
+
Returns:
|
| 22 |
+
str: Information about zodiac sign and Chinese zodiac animal, or error message
|
| 23 |
"""
|
| 24 |
+
try:
|
| 25 |
+
# Validate month input
|
| 26 |
+
if not isinstance(birth_month, str):
|
| 27 |
+
return "Error: Birth month must be a string (e.g., 'February')."
|
| 28 |
+
|
| 29 |
+
# Convert month to lowercase for case-insensitive comparison
|
| 30 |
+
birth_month = birth_month.lower()
|
| 31 |
+
|
| 32 |
+
# Define months and their numerical values for easier date comparison
|
| 33 |
+
month_to_num = {
|
| 34 |
+
"january": 1, "february": 2, "march": 3, "april": 4,
|
| 35 |
+
"may": 5, "june": 6, "july": 7, "august": 8,
|
| 36 |
+
"september": 9, "october": 10, "november": 11, "december": 12
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
# Get month number
|
| 40 |
+
month_num = month_to_num.get(birth_month)
|
| 41 |
+
if month_num is None:
|
| 42 |
+
return "Error: Invalid month name provided. Please use full month names (e.g., 'February')."
|
| 43 |
+
|
| 44 |
+
# Validate year input
|
| 45 |
+
if not isinstance(birth_year, int):
|
| 46 |
+
try:
|
| 47 |
+
birth_year = int(birth_year)
|
| 48 |
+
except (ValueError, TypeError):
|
| 49 |
+
return "Error: Birth year must be a valid integer."
|
| 50 |
+
|
| 51 |
+
if birth_year < 1900 or birth_year > 2100:
|
| 52 |
+
return "Error: Birth year should be between 1900 and 2100."
|
| 53 |
+
|
| 54 |
+
# Determine Western zodiac sign
|
| 55 |
+
if (month_num == 1 and 20 <= 31) or (month_num == 2 and 1 <= 18):
|
| 56 |
+
zodiac_sign = "Aquarius"
|
| 57 |
+
elif (month_num == 2 and 19 <= 29) or (month_num == 3 and 1 <= 20):
|
| 58 |
+
zodiac_sign = "Pisces"
|
| 59 |
+
elif (month_num == 3 and 21 <= 31) or (month_num == 4 and 1 <= 19):
|
| 60 |
+
zodiac_sign = "Aries"
|
| 61 |
+
elif (month_num == 4 and 20 <= 30) or (month_num == 5 and 1 <= 20):
|
| 62 |
+
zodiac_sign = "Taurus"
|
| 63 |
+
elif (month_num == 5 and 21 <= 31) or (month_num == 6 and 1 <= 20):
|
| 64 |
+
zodiac_sign = "Gemini"
|
| 65 |
+
elif (month_num == 6 and 21 <= 30) or (month_num == 7 and 1 <= 22):
|
| 66 |
+
zodiac_sign = "Cancer"
|
| 67 |
+
elif (month_num == 7 and 23 <= 31) or (month_num == 8 and 1 <= 22):
|
| 68 |
+
zodiac_sign = "Leo"
|
| 69 |
+
elif (month_num == 8 and 23 <= 31) or (month_num == 9 and 1 <= 22):
|
| 70 |
+
zodiac_sign = "Virgo"
|
| 71 |
+
elif (month_num == 9 and 23 <= 30) or (month_num == 10 and 1 <= 22):
|
| 72 |
+
zodiac_sign = "Libra"
|
| 73 |
+
elif (month_num == 10 and 23 <= 31) or (month_num == 11 and 1 <= 21):
|
| 74 |
+
zodiac_sign = "Scorpio"
|
| 75 |
+
elif (month_num == 11 and 22 <= 30) or (month_num == 12 and 1 <= 21):
|
| 76 |
+
zodiac_sign = "Sagittarius"
|
| 77 |
+
else:
|
| 78 |
+
zodiac_sign = "Capricorn"
|
| 79 |
+
|
| 80 |
+
# Determine Chinese zodiac animal
|
| 81 |
+
# Chinese zodiac repeats every 12 years
|
| 82 |
+
# Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, Rooster, Dog, Pig
|
| 83 |
+
chinese_zodiac = ["Monkey", "Rooster", "Dog", "Pig", "Rat", "Ox",
|
| 84 |
+
"Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat"]
|
| 85 |
+
|
| 86 |
+
# Calculate Chinese zodiac animal
|
| 87 |
+
zodiac_animal = chinese_zodiac[birth_year % 12]
|
| 88 |
+
|
| 89 |
+
# Return formatted string
|
| 90 |
+
return f"You're a {zodiac_sign} and you were born in the year of the {zodiac_animal}."
|
| 91 |
+
|
| 92 |
+
except Exception as e:
|
| 93 |
+
return f"Error: An unexpected error occurred: {str(e)}"
|
| 94 |
|
| 95 |
@tool
|
| 96 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 129 |
|
| 130 |
agent = CodeAgent(
|
| 131 |
model=model,
|
| 132 |
+
tools=[get_zodiac_info, final_answer], ## add your tools here (don't remove final answer)
|
| 133 |
max_steps=6,
|
| 134 |
verbosity_level=1,
|
| 135 |
grammar=None,
|