ninooo96 commited on
Commit
8f8f56f
·
1 Parent(s): 11eb781

code refactor

Browse files
Files changed (2) hide show
  1. app.py +5 -37
  2. utils.py +32 -0
app.py CHANGED
@@ -4,6 +4,8 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
 
7
 
8
  from Gradio_UI import GradioUI
9
 
@@ -50,39 +52,6 @@ def get_geo_coordinates(city):
50
  else:
51
  print("Error on fetching geo coordinates.")
52
 
53
- def get_weather_description(code):
54
- weather_codes = {
55
- 0: "Clear sky",
56
- 1: "Mainly clear",
57
- 2: "Partly cloudy",
58
- 3: "Overcast",
59
- 45: "Fog and depositing rime fog",
60
- 48: "Fog and depositing rime fog",
61
- 51: "Drizzle: Light intensity",
62
- 53: "Drizzle: Moderate intensity",
63
- 55: "Drizzle: Dense intensity",
64
- 56: "Freezing Drizzle: Light intensity",
65
- 57: "Freezing Drizzle: Dense intensity",
66
- 61: "Rain: Slight intensity",
67
- 63: "Rain: Moderate intensity",
68
- 65: "Rain: Heavy intensity",
69
- 66: "Freezing Rain: Light intensity",
70
- 67: "Freezing Rain: Heavy intensity",
71
- 71: "Snow fall: Slight intensity",
72
- 73: "Snow fall: Moderate intensity",
73
- 75: "Snow fall: Heavy intensity",
74
- 77: "Snow grains",
75
- 80: "Rain showers: Slight intensity",
76
- 81: "Rain showers: Moderate intensity",
77
- 82: "Rain showers: Violent intensity",
78
- 85: "Snow showers: Slight intensity",
79
- 86: "Snow showers: Heavy intensity",
80
- 95: "Thunderstorm: Slight or moderate",
81
- 96: "Thunderstorm with slight hail",
82
- 99: "Thunderstorm with heavy hail"
83
- }
84
- return weather_codes.get(code, "Code not found")
85
-
86
  @tool
87
  def get_weather(city: str) -> str:
88
  """A tool that fetches the current weather information of a specified city.
@@ -98,7 +67,7 @@ def get_weather(city: str) -> str:
98
  temperature = weather_data['current_weather']['temperature']
99
  windspeed = weather_data['current_weather']['windspeed']
100
  wind_unit = weather_data['current_weather_units']['windspeed']
101
- weather_description = get_weather_description(weather_data['current_weather']['weathercode'])
102
  return f"This is the weather on {city}. Temperature on {city} is {temperature}{unit}, the windspeed is {windspeed}{wind_unit} and the condition is {weather_description}"
103
  else:
104
  return "Error on fetching weather data."
@@ -106,7 +75,7 @@ def get_weather(city: str) -> str:
106
 
107
 
108
  final_answer = FinalAnswerTool()
109
-
110
  # 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:
111
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
112
 
@@ -126,7 +95,7 @@ with open("prompts.yaml", 'r') as stream:
126
 
127
  agent = CodeAgent(
128
  model=model,
129
- tools=[final_answer, get_current_time_in_timezone, get_weather], ## add your tools here (don't remove final answer)
130
  max_steps=6,
131
  verbosity_level=1,
132
  grammar=None,
@@ -136,5 +105,4 @@ agent = CodeAgent(
136
  prompt_templates=prompt_templates
137
  )
138
 
139
-
140
  GradioUI(agent).launch()
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ from tools.web_search import WebSearchTool
8
+ import utils
9
 
10
  from Gradio_UI import GradioUI
11
 
 
52
  else:
53
  print("Error on fetching geo coordinates.")
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  @tool
56
  def get_weather(city: str) -> str:
57
  """A tool that fetches the current weather information of a specified city.
 
67
  temperature = weather_data['current_weather']['temperature']
68
  windspeed = weather_data['current_weather']['windspeed']
69
  wind_unit = weather_data['current_weather_units']['windspeed']
70
+ weather_description = utils.get_weather_description(weather_data['current_weather']['weathercode'])
71
  return f"This is the weather on {city}. Temperature on {city} is {temperature}{unit}, the windspeed is {windspeed}{wind_unit} and the condition is {weather_description}"
72
  else:
73
  return "Error on fetching weather data."
 
75
 
76
 
77
  final_answer = FinalAnswerTool()
78
+ web_search = WebSearchTool()
79
  # 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:
80
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
81
 
 
95
 
96
  agent = CodeAgent(
97
  model=model,
98
+ tools=[final_answer, web_search, get_current_time_in_timezone, get_weather], ## add your tools here (don't remove final answer)
99
  max_steps=6,
100
  verbosity_level=1,
101
  grammar=None,
 
105
  prompt_templates=prompt_templates
106
  )
107
 
 
108
  GradioUI(agent).launch()
utils.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def get_weather_description(code):
2
+ weather_codes = {
3
+ 0: "Clear sky",
4
+ 1: "Mainly clear",
5
+ 2: "Partly cloudy",
6
+ 3: "Overcast",
7
+ 45: "Fog and depositing rime fog",
8
+ 48: "Fog and depositing rime fog",
9
+ 51: "Drizzle: Light intensity",
10
+ 53: "Drizzle: Moderate intensity",
11
+ 55: "Drizzle: Dense intensity",
12
+ 56: "Freezing Drizzle: Light intensity",
13
+ 57: "Freezing Drizzle: Dense intensity",
14
+ 61: "Rain: Slight intensity",
15
+ 63: "Rain: Moderate intensity",
16
+ 65: "Rain: Heavy intensity",
17
+ 66: "Freezing Rain: Light intensity",
18
+ 67: "Freezing Rain: Heavy intensity",
19
+ 71: "Snow fall: Slight intensity",
20
+ 73: "Snow fall: Moderate intensity",
21
+ 75: "Snow fall: Heavy intensity",
22
+ 77: "Snow grains",
23
+ 80: "Rain showers: Slight intensity",
24
+ 81: "Rain showers: Moderate intensity",
25
+ 82: "Rain showers: Violent intensity",
26
+ 85: "Snow showers: Slight intensity",
27
+ 86: "Snow showers: Heavy intensity",
28
+ 95: "Thunderstorm: Slight or moderate",
29
+ 96: "Thunderstorm with slight hail",
30
+ 99: "Thunderstorm with heavy hail"
31
+ }
32
+ return weather_codes.get(code, "Code not found")