jtarletta commited on
Commit
a89822b
·
verified ·
1 Parent(s): d8ac937

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -14
app.py CHANGED
@@ -9,13 +9,12 @@ from Gradio_UI import GradioUI
9
 
10
  from typing import List
11
  import requests
12
- from bs4 import BeautifulSoup
13
 
14
 
15
  @tool
16
  def get_web_search(query: str, max_results: int = 3) -> str:
17
- """
18
- A tool that searches for relevant information on the internet without using an API.
19
 
20
  Args:
21
  query: The search term or topic to look up.
@@ -24,20 +23,13 @@ def get_web_search(query: str, max_results: int = 3) -> str:
24
  Returns:
25
  A string containing summarized relevant information about the topic.
26
  """
27
- search_url = f"https://www.google.com/search?q={query}"
28
- headers = {"User-Agent": "Mozilla/5.0"}
29
- response = requests.get(search_url, headers=headers)
30
-
31
- if response.status_code != 200:
32
- return "Failed to retrieve search results."
33
-
34
- soup = BeautifulSoup(response.text, "html.parser")
35
- result_elements = soup.find_all("h3")[:max_results]
36
 
37
- if not result_elements:
38
  return "No relevant information found."
39
 
40
- result_summaries = [f"{i+1}. {elem.get_text()}" for i, elem in enumerate(result_elements)]
41
  return "\n".join(result_summaries)
42
 
43
  @tool
 
9
 
10
  from typing import List
11
  import requests
 
12
 
13
 
14
  @tool
15
  def get_web_search(query: str, max_results: int = 3) -> str:
16
+ """
17
+ A tool that searches for relevant information on the internet using DuckDuckGoSearchTool.
18
 
19
  Args:
20
  query: The search term or topic to look up.
 
23
  Returns:
24
  A string containing summarized relevant information about the topic.
25
  """
26
+ search_tool = DuckDuckGoSearchTool()
27
+ results = search_tool.run(query)
 
 
 
 
 
 
 
28
 
29
+ if not results:
30
  return "No relevant information found."
31
 
32
+ result_summaries = [f"{i+1}. {res['title']}: {res['link']}" for i, res in enumerate(results[:max_results])]
33
  return "\n".join(result_summaries)
34
 
35
  @tool