Spaces:
Sleeping
Sleeping
Upload tool
Browse files- app.py +6 -0
- requirements.txt +2 -0
- tool.py +24 -0
app.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import launch_gradio_demo
|
| 2 |
+
from tool import GetTime
|
| 3 |
+
|
| 4 |
+
tool = GetTime()
|
| 5 |
+
|
| 6 |
+
launch_gradio_demo(tool)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pytz
|
| 2 |
+
smolagents
|
tool.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Optional
|
| 2 |
+
from smolagents.tools import Tool
|
| 3 |
+
import pytz
|
| 4 |
+
import datetime
|
| 5 |
+
|
| 6 |
+
class GetTime(Tool):
|
| 7 |
+
name = "get_time"
|
| 8 |
+
description = "Get the current time in a specific timezone."
|
| 9 |
+
inputs = {'tz': {'type': 'string', 'description': 'the timezone (such as Asia/Shanghai, Europe/Amsterdam, etc.)'}}
|
| 10 |
+
output_type = "string"
|
| 11 |
+
|
| 12 |
+
def forward(self, tz: str) -> str:
|
| 13 |
+
"""Get the current time in a specific timezone.
|
| 14 |
+
|
| 15 |
+
Args:
|
| 16 |
+
tz (str): the timezone (such as Asia/Shanghai, Europe/Amsterdam, etc.)
|
| 17 |
+
"""
|
| 18 |
+
import pytz
|
| 19 |
+
from datetime import datetime
|
| 20 |
+
|
| 21 |
+
return datetime.now(pytz.timezone(tz)).strftime("%Y-%m-%d %H:%M:%S")
|
| 22 |
+
|
| 23 |
+
def __init__(self, *args, **kwargs):
|
| 24 |
+
self.is_initialized = False
|