dygoo commited on
Commit
f2291d0
·
verified ·
1 Parent(s): 0c374bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -2
app.py CHANGED
@@ -11,7 +11,31 @@ from Gradio_UI import GradioUI
11
 
12
  search_tool = DuckDuckGoSearchTool()
13
 
14
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  @tool
17
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -51,7 +75,7 @@ with open("prompts.yaml", 'r') as stream:
51
 
52
  agent = CodeAgent(
53
  model=model,
54
- tools=[final_answer, get_current_time_in_timezone,image_generation_tool, search_tool], ## add your tools here (don't remove final answer)
55
  max_steps=6,
56
  verbosity_level=1,
57
  grammar=None,
 
11
 
12
  search_tool = DuckDuckGoSearchTool()
13
 
14
+ news_sites = ["https://www.cnn.com/"]
15
+
16
+ site_config = {
17
+ "https://www.cnn.com/": {'tag': 'h2', 'class': 'headline'}
18
+ }
19
+ }
20
+
21
+ @tool
22
+ def get_latest_news(news_sites) ->dict:
23
+ """ Tool returns news headlines"""
24
+ headlines = {}
25
+ for site in news_sites:
26
+ try:
27
+ config = site_config.get(site,{'tag': 'h2', 'class:':'headline'})
28
+ response = requests.get(site)
29
+ response.raise_for_status()
30
+ soup = BeautifulSoup(response.content, 'html.parser')
31
+ site_headlines=soup.find_all(config['tag'], class = config['class'])
32
+ headlines[site] = [headline.text for headline in site_headlines]
33
+ except requests.RequestException as e:
34
+ headlines[site] = f"Error fetching news:{e}"
35
+ return headlines
36
+
37
+
38
+
39
 
40
  @tool
41
  def get_current_time_in_timezone(timezone: str) -> str:
 
75
 
76
  agent = CodeAgent(
77
  model=model,
78
+ tools=[final_answer, get_current_time_in_timezone,image_generation_tool, search_tool, get_latest_news], ## add your tools here (don't remove final answer)
79
  max_steps=6,
80
  verbosity_level=1,
81
  grammar=None,