Spaces:
Sleeping
Sleeping
Update app.py
Browse filesimage generation and distance calculations tools from google added
app.py
CHANGED
|
@@ -7,6 +7,39 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
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
|
|
@@ -52,10 +85,11 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
|
|
| 52 |
|
| 53 |
with open("prompts.yaml", 'r') as stream:
|
| 54 |
prompt_templates = yaml.safe_load(stream)
|
| 55 |
-
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
|
|
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
from typing import Optional
|
| 11 |
+
|
| 12 |
+
@tool
|
| 13 |
+
def get_travel_duration(start_location: str, destination_location: str, transportation_mode: Optional[str] = None) -> str:
|
| 14 |
+
"""Gets the travel time between two places.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
start_location: the place from which you start your ride
|
| 18 |
+
destination_location: the place of arrival
|
| 19 |
+
transportation_mode: The transportation mode, in 'driving', 'walking', 'bicycling', or 'transit'. Defaults to 'driving'.
|
| 20 |
+
"""
|
| 21 |
+
import os # All imports are placed within the function, to allow for sharing to Hub.
|
| 22 |
+
import googlemaps
|
| 23 |
+
from datetime import datetime
|
| 24 |
+
|
| 25 |
+
gmaps = googlemaps.Client(os.getenv("GMAPS_API_KEY"))
|
| 26 |
+
|
| 27 |
+
if transportation_mode is None:
|
| 28 |
+
transportation_mode = "driving"
|
| 29 |
+
try:
|
| 30 |
+
directions_result = gmaps.directions(
|
| 31 |
+
start_location,
|
| 32 |
+
destination_location,
|
| 33 |
+
mode=transportation_mode,
|
| 34 |
+
departure_time=datetime(2025, 6, 6, 11, 0), # At 11, date far in the future
|
| 35 |
+
)
|
| 36 |
+
if len(directions_result) == 0:
|
| 37 |
+
return "No way found between these places with the required transportation mode."
|
| 38 |
+
return directions_result[0]["legs"][0]["duration"]["text"]
|
| 39 |
+
except Exception as e:
|
| 40 |
+
print(e)
|
| 41 |
+
return e
|
| 42 |
+
|
| 43 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 44 |
@tool
|
| 45 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 85 |
|
| 86 |
with open("prompts.yaml", 'r') as stream:
|
| 87 |
prompt_templates = yaml.safe_load(stream)
|
| 88 |
+
|
| 89 |
agent = CodeAgent(
|
| 90 |
model=model,
|
| 91 |
+
tools=[final_answer,image_generation_tool,get_travel_duration], ## add your tools here (don't remove final answer)
|
| 92 |
+
additional_authorized_imports=["datetime"]
|
| 93 |
max_steps=6,
|
| 94 |
verbosity_level=1,
|
| 95 |
grammar=None,
|