lization commited on
Commit
7d059b1
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -22
app.py CHANGED
@@ -1,37 +1,42 @@
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
- import datetime
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 my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
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
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
 
 
 
26
  """
27
  try:
28
- # Create timezone object
29
- tz = pytz.timezone(timezone)
30
- # Get current time in that timezone
31
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
32
- return f"The current local time in {timezone} is: {local_time}"
 
 
 
 
 
 
 
 
 
33
  except Exception as e:
34
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
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,