DenDanDon commited on
Commit
016e6c9
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -6
app.py CHANGED
@@ -9,14 +9,35 @@ 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 my_custom_tool(arg1:str, arg2: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
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def get_travel_duration(start_location: str, destination_location: str, transportation_mode: Optional[str] = None) -> str:
13
+ """Gets the travel time between two places.
14
+
15
  Args:
16
+ start_location: the place from which you start your ride
17
+ destination_location: the place of arrival
18
+ transportation_mode: The transportation mode, in 'driving', 'walking', 'bicycling', or 'transit'. Defaults to 'driving'.
19
  """
20
+ import os # All imports are placed within the function, to allow for sharing to Hub.
21
+ import googlemaps
22
+ from datetime import datetime
23
+
24
+ gmaps = googlemaps.Client(os.getenv("GMAPS_API_KEY"))
25
+
26
+ if transportation_mode is None:
27
+ transportation_mode = "driving"
28
+ try:
29
+ directions_result = gmaps.directions(
30
+ start_location,
31
+ destination_location,
32
+ mode=transportation_mode,
33
+ departure_time=datetime(2025, 6, 6, 11, 0), # At 11, date far in the future
34
+ )
35
+ if len(directions_result) == 0:
36
+ return "No way found between these places with the required transportation mode."
37
+ return directions_result[0]["legs"][0]["duration"]["text"]
38
+ except Exception as e:
39
+ print(e)
40
+ return e
41
 
42
  @tool
43
  def get_current_time_in_timezone(timezone: str) -> str: