ddavydov commited on
Commit
28abda2
·
verified ·
1 Parent(s): f73eab4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -4,23 +4,28 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
- from tools.visit_webpage import VisitWebpageTool
8
- from tools.web_search import DuckDuckGoSearchTool
9
 
10
  from Gradio_UI import GradioUI
11
 
12
  @tool
13
- def get_top_keywods_by_city(city: str, time: int) -> list[str]:
14
- """A tool that returns a list with top 5 most popular things to do based on the city
15
  Args:
16
- city: A string representing a city
17
- time: A timestamp representing a current time in a city
18
  """
19
- print(city, time)
20
- if city == "Athens":
21
- return ["Acropolis", "Philosofy", "Sea", "Food", "Drinks"]
22
-
23
- return ["Other"]
 
 
 
 
 
 
 
 
24
 
25
  @tool
26
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -39,8 +44,6 @@ def get_current_time_in_timezone(timezone: str) -> str:
39
 
40
 
41
  final_answer = FinalAnswerTool()
42
- visit_webpage = VisitWebpageTool()
43
- web_search = DuckDuckGoSearchTool()
44
 
45
  # 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:
46
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
@@ -61,7 +64,7 @@ with open("prompts.yaml", 'r') as stream:
61
 
62
  agent = CodeAgent(
63
  model=model,
64
- tools=[get_current_time_in_timezone, get_top_keywods_by_city, web_search, visit_webpage, final_answer], ## add your tools here (don't remove final answer)
65
  max_steps=6,
66
  verbosity_level=1,
67
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
  @tool
11
+ def get_weather(city: str) -> str:
12
+ """Fetches current weather information for a specified city.
13
  Args:
14
+ city: Name of the city (e.g., 'Paris').
 
15
  """
16
+ try:
17
+ api_key = "your_openweathermap_api_key"
18
+ response = requests.get(
19
+ f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
20
+ )
21
+ data = response.json()
22
+ if data.get("cod") != 200:
23
+ return f"Could not fetch weather: {data.get('message', 'Unknown error')}"
24
+ temp = data['main']['temp']
25
+ condition = data['weather'][0]['description']
26
+ return f"Current weather in {city}: {temp}°C, {condition}."
27
+ except Exception as e:
28
+ return f"Error fetching weather: {str(e)}"
29
 
30
  @tool
31
  def get_current_time_in_timezone(timezone: str) -> str:
 
44
 
45
 
46
  final_answer = FinalAnswerTool()
 
 
47
 
48
  # 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:
49
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
64
 
65
  agent = CodeAgent(
66
  model=model,
67
+ tools=[get_current_time_in_timezone, get_weather, final_answer], ## add your tools here (don't remove final answer)
68
  max_steps=6,
69
  verbosity_level=1,
70
  grammar=None,