saretta00 commited on
Commit
71be2e7
·
verified ·
1 Parent(s): a0134b8

add get_trending_searches

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -2,11 +2,27 @@ from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
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 add_numbers(a:int, b:int)-> int:
12
  """A tool that adds two integers.
@@ -33,7 +49,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
33
 
34
  @tool
35
  def duckduckgo_search(query: str) -> str:
36
- """Searches DuckDuckGo for a given query and returns the top result.
37
  Args:
38
  query: The search query string.
39
  Returns:
@@ -82,7 +98,7 @@ with open("prompts.yaml", 'r') as stream:
82
 
83
  agent = CodeAgent(
84
  model=model,
85
- tools=[image_generation_tool, add_numbers, duckduckgo_search, get_current_time_in_timezone,final_answer], ## add your tools here (don't remove final answer)
86
  max_steps=6,
87
  verbosity_level=1,
88
  grammar=None,
 
2
  import datetime
3
  import requests
4
  import pytz
5
+ import
6
  from tools.final_answer import FinalAnswerTool
7
+ from pytrends.requests import TrendReq
8
 
9
  from Gradio_UI import GradioUI
10
 
11
+ @tool
12
+ def get_trending_searches(region:str="united states") -> list:
13
+ """
14
+ A tool to fetch the current top trending searches from Google Trends.
15
+ Args:
16
+ region: Country code (e.g., 'united states')
17
+ """
18
+ try:
19
+ pytrends = TrendReq()
20
+ trending = pytrends.trending_searches(pn=region)
21
+ return trending[0].tolist()
22
+ except Exception as e:
23
+ return f"Error fetching trends:{str(e)}"
24
+
25
+
26
  @tool
27
  def add_numbers(a:int, b:int)-> int:
28
  """A tool that adds two integers.
 
49
 
50
  @tool
51
  def duckduckgo_search(query: str) -> str:
52
+ """Searches DuckDuckGo for a given query and returns the top result.
53
  Args:
54
  query: The search query string.
55
  Returns:
 
98
 
99
  agent = CodeAgent(
100
  model=model,
101
+ tools=[get_trending_searches, image_generation_tool, add_numbers, duckduckgo_search, get_current_time_in_timezone,final_answer], ## add your tools here (don't remove final answer)
102
  max_steps=6,
103
  verbosity_level=1,
104
  grammar=None,