Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,43 +19,38 @@ def my_custom_tool(
|
|
| 19 |
"""
|
| 20 |
return "What magic will you build ?"
|
| 21 |
|
|
|
|
|
|
|
|
|
|
| 22 |
@tool
|
| 23 |
-
def
|
| 24 |
-
"""Calculates the time
|
| 25 |
|
| 26 |
-
This tool
|
| 27 |
-
|
| 28 |
-
Args:
|
| 29 |
-
timezone1 (str): The name of the first timezone (e.g., 'America/New_York').
|
| 30 |
-
timezone2 (str): The name of the second timezone (e.g., 'Europe/Istanbul').
|
| 31 |
|
| 32 |
Returns:
|
| 33 |
-
str: A message displaying the
|
| 34 |
"""
|
| 35 |
try:
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
diff_hours = abs(diff_seconds / 3600)
|
| 48 |
|
| 49 |
return (
|
| 50 |
-
f"
|
| 51 |
-
f"
|
| 52 |
-
f"Time difference: {diff_hours:.1f} hours"
|
| 53 |
)
|
| 54 |
except Exception as e:
|
| 55 |
-
return f"Error
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
| 60 |
@tool
|
| 61 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -96,7 +91,7 @@ agent = CodeAgent(
|
|
| 96 |
model=model,
|
| 97 |
tools=[
|
| 98 |
final_answer,
|
| 99 |
-
|
| 100 |
get_current_time_in_timezone,
|
| 101 |
], ## add your tools here (don't remove final answer)
|
| 102 |
max_steps=6,
|
|
|
|
| 19 |
"""
|
| 20 |
return "What magic will you build ?"
|
| 21 |
|
| 22 |
+
import datetime
|
| 23 |
+
from smolagents import tool
|
| 24 |
+
|
| 25 |
@tool
|
| 26 |
+
def new_year_countdown_tool() -> str:
|
| 27 |
+
"""Calculates the remaining time until the next New Year.
|
| 28 |
|
| 29 |
+
This tool determines how many days, hours, and minutes are left
|
| 30 |
+
until January 1st of the next year.
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
Returns:
|
| 33 |
+
str: A message displaying the remaining time until the New Year.
|
| 34 |
"""
|
| 35 |
try:
|
| 36 |
+
# Get current date and time
|
| 37 |
+
now = datetime.datetime.now()
|
| 38 |
+
|
| 39 |
+
# Calculate next New Year's date (January 1st of the next year)
|
| 40 |
+
next_new_year = datetime.datetime(year=now.year + 1, month=1, day=1, hour=0, minute=0, second=0)
|
| 41 |
+
|
| 42 |
+
# Compute the difference
|
| 43 |
+
diff = next_new_year - now
|
| 44 |
+
days = diff.days
|
| 45 |
+
hours, remainder = divmod(diff.seconds, 3600)
|
| 46 |
+
minutes, _ = divmod(remainder, 60)
|
|
|
|
| 47 |
|
| 48 |
return (
|
| 49 |
+
f"Time remaining until New Year {next_new_year.year}:\n"
|
| 50 |
+
f"{days} days, {hours} hours, {minutes} minutes."
|
|
|
|
| 51 |
)
|
| 52 |
except Exception as e:
|
| 53 |
+
return f"Error calculating New Year countdown: {str(e)}"
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
@tool
|
| 56 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 91 |
model=model,
|
| 92 |
tools=[
|
| 93 |
final_answer,
|
| 94 |
+
new_year_countdown_tool,
|
| 95 |
get_current_time_in_timezone,
|
| 96 |
], ## add your tools here (don't remove final answer)
|
| 97 |
max_steps=6,
|