mmansor commited on
Commit
fd4ddd7
·
verified ·
1 Parent(s): 3c3c81e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +216 -199
app.py CHANGED
@@ -7,7 +7,7 @@ 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
@@ -26,209 +26,226 @@ def get_country_capital(country_name:str)-> str:
26
  country_name: A string representing the country name
27
  """
28
  countries = {
29
- "Afghanistan" : "Kabul",
30
- "Albania" : "Tirana",
31
- "Algeria" : "Algiers",
32
- "Andorra" : "Andorra la Vella",
33
- "Angola" : "Luanda",
34
- "Antigua and Barbuda" : "Saint John’s",
35
- "Argentina" : "Buenos Aires",
36
- "Armenia" : "Yerevan",
37
- "Australia" : "Canberra",
38
- "Austria" : "Vienna",
39
- "Azerbaijan" : "Baku",
40
- "The Bahamas" : "Nassau",
41
- "Bahrain" : "Manama",
42
- "Bangladesh" : "Dhaka",
43
- "Barbados" : "Bridgetown",
44
- "Belarus" : "Minsk",
45
- "Belgium" : "Brussels",
46
- "Belize" : "Belmopan",
47
- "Benin" : "Porto-Novo",
48
- "Bhutan" : "Thimphu",
49
- "Bolivia" : "La Paz, Sucre",
50
- "Bosnia and Herzegovina" : "Sarajevo",
51
- "Botswana" : "Gaborone",
52
- "Brazil" : "Brasilia",
53
- "Brunei" : "Bandar Seri Begawan",
54
- "Bulgaria" : "Sofia",
55
- "Burkina Faso" : "Ouagadougou",
56
- "Burundi" : "Bujumbura",
57
- "Cambodia" : "Phnom Penh",
58
- "Cameroon" : "Yaounde",
59
- "Canada" : "Ottawa",
60
- "Cape Verde" : "Praia",
61
- "Central African Republic" : "Bangui",
62
- "Chad" : "N’Djamena",
63
- "Chile" : "Santiago",
64
- "China" : "Beijing",
65
- "Colombia" : "Bogota",
66
- "Comoros" : "Moroni",
67
- "Republic of the Congo": "Brazzaville",
68
- "Democratic Republic of the Congo" : "Kinshasa",
69
- "Costa Rica" : "San Jose",
70
- "Cote d’Ivoire" : "Yamoussoukro",
71
- "Croatia" : "Zagreb",
72
- "Cuba" : "Havana",
73
- "Cyprus" : "Nicosia",
74
- "Czech Republic" : "Prague",
75
- "Denmark" : "Copenhagen",
76
- "Djibouti" : "Djibouti",
77
- "Dominica" : "Roseau",
78
- "Dominican Republic" : "Santo Domingo",
79
- "East Timor" : "Dili",
80
- "Ecuador" : "Quito",
81
- "Egypt" : "Cairo",
82
- "El Salvador" : "San Salvador",
83
- "Equatorial Guinea" : "Malabo",
84
- "Eritrea" : "Asmara",
85
- "Estonia" : "Tallinn",
86
- "Ethiopia" : "Addis Ababa",
87
- "Fiji" : "Suva",
88
- "Finland" : "Helsinki",
89
- "France" : "Paris",
90
- "Gabon" : "Libreville",
91
- "The Gambia" : "Banjul",
92
- "Georgia" : "Tbilisi",
93
- "Germany" : "Berlin",
94
- "Ghana" : "Accra",
95
- "Greece" : "Athens",
96
- "Grenada" : "Saint George’s",
97
- "Guatemala" : "Guatemala City",
98
- "Guinea" : "Conakry",
99
- "Guinea-Bissau" : "Bissau",
100
- "Guyana" : "Georgetown",
101
- "Haiti" : "Port-au-Prince",
102
- "Honduras" : "Tegucigalpa",
103
- "Hungary" : "Budapest",
104
- "Iceland" : "Reykjavik",
105
- "India" : "New Delhi",
106
- "Indonesia" : "Jakarta",
107
- "Iran" : "Tehran",
108
- "Iraq" : "Baghdad",
109
- "Ireland" : "Dublin",
110
- "Israel" : "Jerusalem",
111
- "Italy" : "Rome",
112
- "Jamaica" : "Kingston",
113
- "Japan" : "Tokyo",
114
- "Jordan" : "Amman",
115
- "Kazakhstan" : "Astana",
116
- "Kenya" : "Nairobi",
117
- "Kiribati" : "Tarawa Atoll",
118
- "North Korea" : "Pyongyang",
119
- "South Korea" : "Seoul",
120
- "Kosovo" : "Pristina",
121
- "Kuwait" : "Kuwait City",
122
- "Kyrgyzstan" : "Bishkek",
123
- "Laos" : "Vientiane",
124
- "Latvia" : "Riga",
125
- "Lebanon" : "Beirut",
126
- "Lesotho" : "Maseru",
127
- "Liberia" : "Monrovia",
128
- "Libya" : "Tripoli",
129
- "Liechtenstein" : "Vaduz",
130
- "Lithuania" : "Vilnius",
131
- "Luxembourg" : "Luxembourg",
132
- "Macedonia" : "Skopje",
133
- "Madagascar" : "Antananarivo",
134
- "Malawi" : "Lilongwe",
135
- "Malaysia" : "Kuala Lumpur",
136
- "Maldives" : "Male",
137
- "Mali" : "Bamako",
138
- "Malta" : "Valletta",
139
- "Marshall Islands" : "Majuro",
140
- "Mauritania" : "Nouakchott",
141
- "Mauritius" : "Port Louis",
142
- "Mexico" : "Mexico City",
143
- "Federated States of Micronesia" : "Palikir",
144
- "Moldova" : "Chisinau",
145
- "Monaco" : "Monaco",
146
- "Mongolia" : "Ulaanbaatar",
147
- "Montenegro" : "Podgorica",
148
- "Morocco" : "Rabat",
149
- "Mozambique" : "Maputo",
150
- "Myanmar" : "Naypyidaw",
151
- "Namibia" : "Windhoek",
152
- "Nauru" : "Yaren District",
153
- "Nepal" : "Kathmandu",
154
- "Netherlands" : "Amsterdam",
155
- "New Zealand" : "Wellington",
156
- "Nicaragua" : "Managua",
157
- "Niger" : "Niamey",
158
- "Nigeria" : "Abuja",
159
- "Norway" : "Oslo",
160
- "Oman" : "Muscat",
161
- "Pakistan" : "Islamabad",
162
- "Palau" : "Melekeok",
163
- "Panama" : "Panama City",
164
- "Papua New Guinea" : "Port Moresby",
165
- "Paraguay" : "Asuncion",
166
- "Peru" : "Lima",
167
- "Philippines" : "Manila",
168
- "Poland" : "Warsaw",
169
- "Portugal" : "Lisbon",
170
- "Qatar" : "Doha",
171
- "Romania" : "Bucharest",
172
- "Russia" : "Moscow",
173
- "Rwanda" : "Kigali",
174
- "Saint Kitts and Nevis" : "Basseterre",
175
- "Saint Lucia" : "Castries",
176
- "Saint Vincent and the Grenadines" : "Kingstown",
177
- "Samoa" : "Apia",
178
- "San Marino" : "San Marino",
179
- "Sao Tome and Principe" : "Sao Tome",
180
- "Saudi Arabia" : "Riyadh",
181
- "Senegal" : "Dakar",
182
- "Serbia" : "Belgrade",
183
- "Seychelles" : "Victoria",
184
- "Sierra Leone" : "Freetown",
185
- "Singapore" : "Singapore",
186
- "Slovakia" : "Bratislava",
187
- "Slovenia" : "Ljubljana",
188
- "Solomon Islands" : "Honiara",
189
- "Somalia" : "Mogadishu",
190
- "South Africa" : "Pretoria, Cape Town, Bloemfontein",
191
- "South Sudan" : "Juba",
192
- "Spain" : "Madrid",
193
- "Sri Lanka" : "Colombo, Sri Jayewardenepura Kotte",
194
- "Sudan" : "Khartoum",
195
- "Suriname" : "Paramaribo",
196
- "Swaziland" : "Mbabane",
197
- "Sweden" : "Stockholm",
198
- "Switzerland" : "Bern",
199
- "Syria" : "Damascus",
200
- "Taiwan" : "Taipei",
201
- "Tajikistan" : "Dushanbe",
202
- "Tanzania" : "Dodoma",
203
- "Thailand" : "Bangkok",
204
- "Togo" : "Lome",
205
- "Tonga" : "Nuku’alofa",
206
- "Trinidad and Tobago" : "Port-of-Spain",
207
- "Tunisia" : "Tunis",
208
- "Turkey" : "Ankara",
209
- "Turkmenistan" : "Ashgabat",
210
- "Tuvalu" : "Funafuti",
211
- "Uganda" : "Kampala",
212
- "Ukraine" : "Kyiv",
213
- "United Arab Emirates" : "Abu Dhabi",
214
- "United Kingdom" : "London",
215
- "United States of America" : "Washington D.C.",
216
- "Uruguay" : "Montevideo",
217
- "Uzbekistan" : "Tashkent",
218
- "Vanuatu" : "Port-Vila",
219
- "Vatican City" : "Vatican City",
220
- "Venezuela" : "Caracas",
221
- "Vietnam" : "Hanoi",
222
- "Yemen" : "Sanaa",
223
- "Zambia" : "Lusaka",
224
- "Zimbabwe" : "Harare"
225
  }
226
 
227
- capital = countries.get(country_name)
 
228
  if not capital:
229
  return f"Cannot find the capital of {country_name} Try to enter the name correct"
230
  return f"The Capital of {country_name} is {capital}"
231
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
 
233
  @tool
234
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -267,7 +284,7 @@ with open("prompts.yaml", 'r') as stream:
267
 
268
  agent = CodeAgent(
269
  model=model,
270
- tools=[final_answer], ## add your tools here (don't remove final answer)
271
  max_steps=6,
272
  verbosity_level=1,
273
  grammar=None,
 
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
 
26
  country_name: A string representing the country name
27
  """
28
  countries = {
29
+ "afghanistan": "Kabul",
30
+ "albania": "Tirana",
31
+ "algeria": "Algiers",
32
+ "andorra": "Andorra la Vella",
33
+ "angola": "Luanda",
34
+ "antigua and barbuda": "Saint John’s",
35
+ "argentina": "Buenos Aires",
36
+ "armenia": "Yerevan",
37
+ "australia": "Canberra",
38
+ "austria": "Vienna",
39
+ "azerbaijan": "Baku",
40
+ "the bahamas": "Nassau",
41
+ "bahrain": "Manama",
42
+ "bangladesh": "Dhaka",
43
+ "barbados": "Bridgetown",
44
+ "belarus": "Minsk",
45
+ "belgium": "Brussels",
46
+ "belize": "Belmopan",
47
+ "benin": "Porto-Novo",
48
+ "bhutan": "Thimphu",
49
+ "bolivia": "La Paz, Sucre",
50
+ "bosnia and herzegovina": "Sarajevo",
51
+ "botswana": "Gaborone",
52
+ "brazil": "Brasilia",
53
+ "brunei": "Bandar Seri Begawan",
54
+ "bulgaria": "Sofia",
55
+ "burkina faso": "Ouagadougou",
56
+ "burundi": "Bujumbura",
57
+ "cambodia": "Phnom Penh",
58
+ "cameroon": "Yaounde",
59
+ "canada": "Ottawa",
60
+ "cape verde": "Praia",
61
+ "central african republic": "Bangui",
62
+ "chad": "N’Djamena",
63
+ "chile": "Santiago",
64
+ "china": "Beijing",
65
+ "colombia": "Bogota",
66
+ "comoros": "Moroni",
67
+ "republic of the congo": "Brazzaville",
68
+ "democratic republic of the congo": "Kinshasa",
69
+ "costa rica": "San Jose",
70
+ "cote d’ivoire": "Yamoussoukro",
71
+ "croatia": "Zagreb",
72
+ "cuba": "Havana",
73
+ "cyprus": "Nicosia",
74
+ "czech republic": "Prague",
75
+ "denmark": "Copenhagen",
76
+ "djibouti": "Djibouti",
77
+ "dominica": "Roseau",
78
+ "dominican republic": "Santo Domingo",
79
+ "east timor": "Dili",
80
+ "ecuador": "Quito",
81
+ "egypt": "Cairo",
82
+ "el salvador": "San Salvador",
83
+ "equatorial guinea": "Malabo",
84
+ "eritrea": "Asmara",
85
+ "estonia": "Tallinn",
86
+ "ethiopia": "Addis Ababa",
87
+ "fiji": "Suva",
88
+ "finland": "Helsinki",
89
+ "france": "Paris",
90
+ "gabon": "Libreville",
91
+ "the gambia": "Banjul",
92
+ "georgia": "Tbilisi",
93
+ "germany": "Berlin",
94
+ "ghana": "Accra",
95
+ "greece": "Athens",
96
+ "grenada": "Saint George’s",
97
+ "guatemala": "Guatemala City",
98
+ "guinea": "Conakry",
99
+ "guinea-bissau": "Bissau",
100
+ "guyana": "Georgetown",
101
+ "haiti": "Port-au-Prince",
102
+ "honduras": "Tegucigalpa",
103
+ "hungary": "Budapest",
104
+ "iceland": "Reykjavik",
105
+ "india": "New Delhi",
106
+ "indonesia": "Jakarta",
107
+ "iran": "Tehran",
108
+ "iraq": "Baghdad",
109
+ "ireland": "Dublin",
110
+ "israel": "Jerusalem",
111
+ "italy": "Rome",
112
+ "jamaica": "Kingston",
113
+ "japan": "Tokyo",
114
+ "jordan": "Amman",
115
+ "kazakhstan": "Astana",
116
+ "kenya": "Nairobi",
117
+ "kiribati": "Tarawa Atoll",
118
+ "north korea": "Pyongyang",
119
+ "south korea": "Seoul",
120
+ "kosovo": "Pristina",
121
+ "kuwait": "Kuwait City",
122
+ "kyrgyzstan": "Bishkek",
123
+ "laos": "Vientiane",
124
+ "latvia": "Riga",
125
+ "lebanon": "Beirut",
126
+ "lesotho": "Maseru",
127
+ "liberia": "Monrovia",
128
+ "libya": "Tripoli",
129
+ "liechtenstein": "Vaduz",
130
+ "lithuania": "Vilnius",
131
+ "luxembourg": "Luxembourg",
132
+ "macedonia": "Skopje",
133
+ "madagascar": "Antananarivo",
134
+ "malawi": "Lilongwe",
135
+ "malaysia": "Kuala Lumpur",
136
+ "maldives": "Male",
137
+ "mali": "Bamako",
138
+ "malta": "Valletta",
139
+ "marshall islands": "Majuro",
140
+ "mauritania": "Nouakchott",
141
+ "mauritius": "Port Louis",
142
+ "mexico": "Mexico City",
143
+ "federated states of micronesia": "Palikir",
144
+ "moldova": "Chisinau",
145
+ "monaco": "Monaco",
146
+ "mongolia": "Ulaanbaatar",
147
+ "montenegro": "Podgorica",
148
+ "morocco": "Rabat",
149
+ "mozambique": "Maputo",
150
+ "myanmar": "Naypyidaw",
151
+ "namibia": "Windhoek",
152
+ "nauru": "Yaren District",
153
+ "nepal": "Kathmandu",
154
+ "netherlands": "Amsterdam",
155
+ "new zealand": "Wellington",
156
+ "nicaragua": "Managua",
157
+ "niger": "Niamey",
158
+ "nigeria": "Abuja",
159
+ "norway": "Oslo",
160
+ "oman": "Muscat",
161
+ "pakistan": "Islamabad",
162
+ "palau": "Melekeok",
163
+ "panama": "Panama City",
164
+ "papua new guinea": "Port Moresby",
165
+ "paraguay": "Asuncion",
166
+ "peru": "Lima",
167
+ "philippines": "Manila",
168
+ "poland": "Warsaw",
169
+ "portugal": "Lisbon",
170
+ "qatar": "Doha",
171
+ "romania": "Bucharest",
172
+ "russia": "Moscow",
173
+ "rwanda": "Kigali",
174
+ "saint kitts and nevis": "Basseterre",
175
+ "saint lucia": "Castries",
176
+ "saint vincent and the grenadines": "Kingstown",
177
+ "samoa": "Apia",
178
+ "san marino": "San Marino",
179
+ "sao tome and principe": "Sao Tome",
180
+ "saudi arabia": "Riyadh",
181
+ "senegal": "Dakar",
182
+ "serbia": "Belgrade",
183
+ "seychelles": "Victoria",
184
+ "sierra leone": "Freetown",
185
+ "singapore": "Singapore",
186
+ "slovakia": "Bratislava",
187
+ "slovenia": "Ljubljana",
188
+ "solomon islands": "Honiara",
189
+ "somalia": "Mogadishu",
190
+ "south africa": "Pretoria, Cape Town, Bloemfontein",
191
+ "south sudan": "Juba",
192
+ "spain": "Madrid",
193
+ "sri lanka": "Colombo, Sri Jayewardenepura Kotte",
194
+ "sudan": "Khartoum",
195
+ "suriname": "Paramaribo",
196
+ "swaziland": "Mbabane",
197
+ "sweden": "Stockholm",
198
+ "switzerland": "Bern",
199
+ "syria": "Damascus",
200
+ "taiwan": "Taipei",
201
+ "tajikistan": "Dushanbe",
202
+ "tanzania": "Dodoma",
203
+ "thailand": "Bangkok",
204
+ "togo": "Lome",
205
+ "tonga": "Nuku’alofa",
206
+ "trinidad and tobago": "Port-of-Spain",
207
+ "tunisia": "Tunis",
208
+ "turkey": "Ankara",
209
+ "turkmenistan": "Ashgabat",
210
+ "tuvalu": "Funafuti",
211
+ "uganda": "Kampala",
212
+ "ukraine": "Kyiv",
213
+ "united arab emirates": "Abu Dhabi",
214
+ "united kingdom": "London",
215
+ "united states of america": "Washington D.C.",
216
+ "uruguay": "Montevideo",
217
+ "uzbekistan": "Tashkent",
218
+ "vanuatu": "Port-Vila",
219
+ "vatican city": "Vatican City",
220
+ "venezuela": "Caracas",
221
+ "vietnam": "Hanoi",
222
+ "yemen": "Sanaa",
223
+ "zambia": "Lusaka",
224
+ "zimbabwe": "Harare",
225
  }
226
 
227
+
228
+ capital = countries.get(country_name.lower())
229
  if not capital:
230
  return f"Cannot find the capital of {country_name} Try to enter the name correct"
231
  return f"The Capital of {country_name} is {capital}"
232
 
233
+ @tool
234
+ def search(text: str) -> str:
235
+ """A tool that uses DuckDuckGoSearchTool to search.
236
+ Args:
237
+ text:
238
+ """
239
+ try:
240
+ # Create timezone object
241
+ tz = pytz.timezone(timezone)
242
+ # Get current time in that timezone
243
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
244
+ return f"The current local time in {timezone} is: {local_time}"
245
+ except Exception as e:
246
+ return f"Error fetching time for timezone '{timezone}': {str(e)}"
247
+
248
+
249
 
250
  @tool
251
  def get_current_time_in_timezone(timezone: str) -> str:
 
284
 
285
  agent = CodeAgent(
286
  model=model,
287
+ tools=[final_answer, DuckDuckGoSearchTool(), get_country_capital], ## add your tools here (don't remove final answer)
288
  max_steps=6,
289
  verbosity_level=1,
290
  grammar=None,