Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
|
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
@@ -18,6 +19,29 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
18 |
"""
|
19 |
return "What magic will you build ?"
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
23 |
"""A tool that fetches the current local time in a specified timezone.
|
@@ -55,7 +79,7 @@ with open("prompts.yaml", 'r') as 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,
|
@@ -66,4 +90,4 @@ agent = CodeAgent(
|
|
66 |
)
|
67 |
|
68 |
|
69 |
-
GradioUI(agent).launch()
|
|
|
1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
+
from geopy.geocoders import Nominatim # Used for converting city names into coordinates
|
3 |
import datetime
|
4 |
import requests
|
5 |
import pytz
|
|
|
19 |
"""
|
20 |
return "What magic will you build ?"
|
21 |
|
22 |
+
@tool
|
23 |
+
def get_city_coordinates(city: str) -> str:
|
24 |
+
"""A tool that finds the Latitude and Longitude coordinates of a given city.
|
25 |
+
Args:
|
26 |
+
city: The name of the city to locate.
|
27 |
+
Returns:
|
28 |
+
A string with the coordinates of the city, or an error message if not found.
|
29 |
+
"""
|
30 |
+
try:
|
31 |
+
# initialize a geolocator with a unique user_agent identifier (required by geopy library)
|
32 |
+
geolocator = Nominatim(user_agent="city_coords_app")
|
33 |
+
# Attempt to geocode the city name
|
34 |
+
location = geolocator.geocode(city)
|
35 |
+
if location:
|
36 |
+
return (
|
37 |
+
f"The coordinates of {city} are: "
|
38 |
+
f"Latitude = {location.latitude}, Longitude = {location.longitude}"
|
39 |
+
)
|
40 |
+
else:
|
41 |
+
return f"Could not find coordinates for city: {city}"
|
42 |
+
except Exception as e:
|
43 |
+
return f"Error finding coordinates for city '{city}': {str(e)}"
|
44 |
+
|
45 |
@tool
|
46 |
def get_current_time_in_timezone(timezone: str) -> str:
|
47 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
79 |
|
80 |
agent = CodeAgent(
|
81 |
model=model,
|
82 |
+
tools=[final_answer,image_generation_tool,get_city_coordinates,DuckDuckGoSearchTool], ## add your tools here (don't remove final answer)
|
83 |
max_steps=6,
|
84 |
verbosity_level=1,
|
85 |
grammar=None,
|
|
|
90 |
)
|
91 |
|
92 |
|
93 |
+
GradioUI(agent).launch()
|