NagarajanB1990 commited on
Commit
cbbfdf7
·
verified ·
1 Parent(s): 7256897

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -16
app.py CHANGED
@@ -1,18 +1,37 @@
1
- from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
 
2
 
3
- def who_is_bot(person_name: str) -> str:
4
- agent = CodeAgent(
5
- tools=[DuckDuckGoSearchTool()],
6
- model=HfApiModel()
7
- )
8
- prompt = (
9
- f"Who is {person_name}? "
10
- "Give a short 1-2 sentence summary."
11
- )
12
- result = agent.run(prompt)
13
- return result.strip()
14
 
15
- if __name__ == "__main__":
16
- person = "Sundar Pichai"
17
- summary = who_is_bot(person)
18
- print(f"About {person}: {summary}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import Tool
2
+ from typing import Optional
3
 
4
+ class SimpleTool(Tool):
5
+ name = "get_travel_duration"
6
+ description = "Gets the travel time between two places."
7
+ inputs = {"start_location":{"type":"string","description":"the place from which you start your ride"},"destination_location":{"type":"string","description":"the place of arrival"},"transportation_mode":{"type":"string","nullable":True,"description":"The transportation mode, in 'driving', 'walking', 'bicycling', or 'transit'. Defaults to 'driving'."}}
8
+ output_type = "string"
 
 
 
 
 
 
9
 
10
+ def forward(self, start_location: str, destination_location: str, transportation_mode: Optional[str] = None) -> str:
11
+ """Gets the travel time between two places.
12
+ Args:
13
+ start_location: the place from which you start your ride
14
+ destination_location: the place of arrival
15
+ transportation_mode: The transportation mode, in 'driving', 'walking', 'bicycling', or 'transit'. Defaults to 'driving'.
16
+ """
17
+ import os # All imports are placed within the function, to allow for sharing to Hub.
18
+ import googlemaps
19
+ from datetime import datetime
20
+
21
+ gmaps = googlemaps.Client(os.getenv("GMAPS_API_KEY"))
22
+
23
+ if transportation_mode is None:
24
+ transportation_mode = "driving"
25
+ try:
26
+ directions_result = gmaps.directions(
27
+ start_location,
28
+ destination_location,
29
+ mode=transportation_mode,
30
+ departure_time=datetime(2025, 12, 6, 11, 0), # At 11, date far in the future
31
+ )
32
+ if len(directions_result) == 0:
33
+ return "No way found between these places with the required transportation mode."
34
+ return directions_result[0]["legs"][0]["duration"]["text"]
35
+ except Exception as e:
36
+ print(e)
37
+ return e