younus00 commited on
Commit
21a4e15
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files

added get_weather tool

Files changed (1) hide show
  1. app.py +48 -5
app.py CHANGED
@@ -9,14 +9,54 @@ 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:
@@ -35,6 +75,9 @@ def get_current_time_in_timezone(timezone: str) -> str:
35
 
36
 
37
  final_answer = FinalAnswerTool()
 
 
 
38
 
39
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
40
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def get_weather(place:str)-> 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 get weather of a certain location.
15
  Args:
16
+ place: city location
 
17
  """
18
+ code_map = {
19
+ 0: "Clear", 1: "Mostly clear", 2: "Partly cloudy", 3: "Overcast",
20
+ 45: "Fog", 48: "Rime fog",
21
+ 51: "Light drizzle", 53: "Drizzle", 55: "Heavy drizzle",
22
+ 61: "Light rain", 63: "Rain", 65: "Heavy rain",
23
+ 71: "Light snow", 73: "Snow", 75: "Heavy snow",
24
+ 80: "Rain showers", 81: "Showers", 82: "Heavy showers",
25
+ 95: "Thunderstorm", 96: "T-storm (hail)", 99: "Severe t-storm"
26
+ }
27
+
28
+ try:
29
+ g = requests.get(
30
+ "https://geocoding-api.open-meteo.com/v1/search",
31
+ params={"name": place, "count": 1, "language": "en", "format": "json"},
32
+ timeout=10,
33
+ ).json()
34
+ if not g.get("results"):
35
+ return None
36
+ lat = g["results"][0]["latitude"]
37
+ lon = g["results"][0]["longitude"]
38
+ name = g["results"][0]["name"]
39
+
40
+ w = requests.get(
41
+ "https://api.open-meteo.com/v1/forecast",
42
+ params={
43
+ "latitude": lat,
44
+ "longitude": lon,
45
+ "current": "temperature_2m,weather_code"
46
+ },
47
+ timeout=10,
48
+ ).json().get("current")
49
+ if not w:
50
+ return None
51
+
52
+ code = w.get("weather_code")
53
+ return {
54
+ "location": name,
55
+ "temperature_c": w.get("temperature_2m"),
56
+ "condition": code_map.get(code, f"Code {code}")
57
+ }
58
+ except Exception:
59
+ return None
60
 
61
  @tool
62
  def get_current_time_in_timezone(timezone: str) -> str:
 
75
 
76
 
77
  final_answer = FinalAnswerTool()
78
+ ###
79
+ web_search_tool = DuckDuckGoSearchTool(max_results=5, rate_limit=2.0)
80
+ ###
81
 
82
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
83
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'