Spaces:
Running
Running
peterbonnesoeur
commited on
Commit
·
6d113c1
1
Parent(s):
5911e55
First commit
Browse files- .gitignore +2 -0
- app.py +7 -0
- requirements.txt +2 -0
- tool.py +21 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
|
2 |
+
.codegpt
|
app.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents import launch_gradio_demo
|
2 |
+
from typing import Optional
|
3 |
+
from tool import TimeZoneConversionTool
|
4 |
+
|
5 |
+
tool = TimeZoneConversionTool()
|
6 |
+
|
7 |
+
launch_gradio_demo(tool)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
smolagents
|
2 |
+
pytz
|
tool.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents import Tool
|
2 |
+
from datetime import datetime
|
3 |
+
import pytz
|
4 |
+
|
5 |
+
class TimeZoneConversionTool(Tool):
|
6 |
+
name = "timezone_converter"
|
7 |
+
description = "Converts time between two time zones."
|
8 |
+
inputs = {
|
9 |
+
"time": {"type": "string", "description": "Time in 'YYYY-MM-DD HH:MM' format"},
|
10 |
+
"from_timezone": {"type": "string", "description": "Original time zone"},
|
11 |
+
"to_timezone": {"type": "string", "description": "Target time zone"}
|
12 |
+
}
|
13 |
+
output_type = "string"
|
14 |
+
|
15 |
+
def forward(self, time: str, from_timezone: str, to_timezone: str):
|
16 |
+
from_zone = pytz.timezone(from_timezone)
|
17 |
+
to_zone = pytz.timezone(to_timezone)
|
18 |
+
naive_time = datetime.strptime(time, "%Y-%m-%d %H:%M")
|
19 |
+
local_time = from_zone.localize(naive_time)
|
20 |
+
converted_time = local_time.astimezone(to_zone)
|
21 |
+
return converted_time.strftime("%Y-%m-%d %H:%M")
|