Update app.py
#241
by
lization - opened
app.py
CHANGED
|
@@ -1,37 +1,42 @@
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
-
import
|
| 3 |
import requests
|
| 4 |
-
import pytz
|
| 5 |
import yaml
|
|
|
|
| 6 |
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
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
Args:
|
| 16 |
-
arg1: the first argument
|
| 17 |
-
arg2: the second argument
|
| 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.
|
| 24 |
Args:
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
"""
|
| 27 |
try:
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
-
return f"Error fetching
|
| 35 |
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
|
@@ -55,7 +60,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,
|
|
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
+
from meteostat import Stations, Daily
|
| 3 |
import requests
|
|
|
|
| 4 |
import yaml
|
| 5 |
+
import datetime
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
|
| 8 |
+
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 12 |
@tool
|
| 13 |
+
def World_temperature(lat: float, lon: float) -> str:
|
| 14 |
+
"""Fetches the current temperature in a specified location using latitude & longitude.
|
| 15 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
Args:
|
| 17 |
+
lat: Latitude of the location (e.g., 51.51 for London).
|
| 18 |
+
lon: Longitude of the location (e.g., -0.13 for London).
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
A string with the current temperature.
|
| 22 |
"""
|
| 23 |
try:
|
| 24 |
+
# Get nearest weather station
|
| 25 |
+
stations = Stations().nearby(lat, lon).fetch(1)
|
| 26 |
+
station_id = stations.index[0]
|
| 27 |
+
|
| 28 |
+
# Get today's weather data
|
| 29 |
+
today = datetime.datetime.today()
|
| 30 |
+
data = Daily(station_id, today, today).fetch()
|
| 31 |
+
|
| 32 |
+
if not data.empty:
|
| 33 |
+
temp = data["tavg"].iloc[0] # Get average temperature
|
| 34 |
+
return f"The current temperature at ({lat}, {lon}) is {temp}°C."
|
| 35 |
+
else:
|
| 36 |
+
return "No temperature data available for this location."
|
| 37 |
+
|
| 38 |
except Exception as e:
|
| 39 |
+
return f"Error fetching temperature: {str(e)}"
|
| 40 |
|
| 41 |
|
| 42 |
final_answer = FinalAnswerTool()
|
|
|
|
| 60 |
|
| 61 |
agent = CodeAgent(
|
| 62 |
model=model,
|
| 63 |
+
tools=[final_answer], [World_temperature] ## add your tools here (don't remove final answer)
|
| 64 |
max_steps=6,
|
| 65 |
verbosity_level=1,
|
| 66 |
grammar=None,
|