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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -34
app.py CHANGED
@@ -1,37 +1,21 @@
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
 
1
+ import os
2
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
3
 
4
+ hf_token = os.getenv("HF_TOKEN")
 
 
 
 
5
 
6
+ def who_is_bot(person_name: str) -> str:
7
+ agent = CodeAgent(
8
+ tools=[DuckDuckGoSearchTool()],
9
+ model=HfApiModel(hf_token=hf_token)
10
+ )
11
+ prompt = (
12
+ f"Who is {person_name}? "
13
+ "Give a short 1-2 sentence summary."
14
+ )
15
+ result = agent.run(prompt)
16
+ return result.strip()
17
 
18
+ if __name__ == "__main__":
19
+ person = "Sundar Pichai"
20
+ summary = who_is_bot(person)
21
+ print(f"About {person}: {summary}")