Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 13 |
-
|
| 14 |
-
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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:
|