m-ric HF staff commited on
Commit
6e4eef0
·
verified ·
1 Parent(s): b993bc2

Upload tool

Browse files
Files changed (3) hide show
  1. app.py +6 -0
  2. requirements.txt +5 -0
  3. tool.py +32 -0
app.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from smolagents import launch_gradio_demo
2
+ from tool import SimpleTool
3
+
4
+ tool = SimpleTool()
5
+
6
+ launch_gradio_demo(tool)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ agents_package
2
+ os
3
+ googlemaps
4
+ smolagents
5
+ datetime
tool.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import Tool
2
+
3
+ class SimpleTool(Tool):
4
+ name = "get_travel_duration"
5
+ description = "Gets the travel time in car between two places."
6
+ inputs = {"start_location":{"type":"string","description":"the place from which you start your ride"},"destination_location":{"type":"string","description":"the place of arrival"},"departure_time":{"type":"integer","nullable":true,"description":"the departure time, provide only a `datetime.datetime` if you want to specify this"}}
7
+ output_type = "string"
8
+
9
+ def forward(self, start_location: str, destination_location: str, departure_time: Optional[int] = None) -> str:
10
+ """Gets the travel time in car between two places.
11
+
12
+ Args:
13
+ start_location: the place from which you start your ride
14
+ destination_location: the place of arrival
15
+ departure_time: the departure time, provide only a `datetime.datetime` if you want to specify this
16
+ """
17
+ import googlemaps
18
+ import os
19
+
20
+ gmaps = googlemaps.Client(os.getenv("GMAPS_API_KEY"))
21
+
22
+ if departure_time is None:
23
+ from datetime import datetime
24
+ monday = datetime(2025, 1, 6, 11, 0)
25
+
26
+ directions_result = gmaps.directions(
27
+ start_location,
28
+ destination_location,
29
+ mode="transit",
30
+ departure_time=departure_time
31
+ )
32
+ return directions_result[0]["legs"][0]["duration"]["text"]