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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -8,12 +8,14 @@ from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
 
10
  from typing import List
11
- from web import search
 
 
12
 
13
  @tool
14
  def get_web_search(query: str, max_results: int = 3) -> str:
15
- """
16
- A tool that searches for relevant information on the internet.
17
 
18
  Args:
19
  query: The search term or topic to look up.
@@ -22,15 +24,20 @@ def get_web_search(query: str, max_results: int = 3) -> str:
22
  Returns:
23
  A string containing summarized relevant information about the topic.
24
  """
25
- search_results = search(query)
 
 
 
 
 
26
 
27
- if not search_results:
28
- return "No relevant information found. Try refining your search query."
29
 
30
- result_summaries = []
31
- for i, result in enumerate(search_results[:max_results]):
32
- result_summaries.append(f"{i+1}. {result['title']}: {result['snippet']}")
33
 
 
34
  return "\n".join(result_summaries)
35
 
36
  @tool
 
8
  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
  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