Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ import requests
|
|
8 |
from typing import List, Dict, Union
|
9 |
import pandas as pd
|
10 |
import wikipediaapi
|
11 |
-
|
12 |
|
13 |
load_dotenv()
|
14 |
|
@@ -29,12 +29,14 @@ class BasicAgent:
|
|
29 |
print(f"Agent returning answer: {fixed_answer}")
|
30 |
return fixed_answer
|
31 |
|
32 |
-
@staticmethod
|
33 |
-
def basic_search(query):
|
34 |
-
url = f"https://www.google.com/search?q={query}"
|
35 |
-
response = requests.get(url)
|
36 |
-
return response.text
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
|
40 |
|
|
|
8 |
from typing import List, Dict, Union
|
9 |
import pandas as pd
|
10 |
import wikipediaapi
|
11 |
+
from googlesearch-python import search # pip install googlesearch-python
|
12 |
|
13 |
load_dotenv()
|
14 |
|
|
|
29 |
print(f"Agent returning answer: {fixed_answer}")
|
30 |
return fixed_answer
|
31 |
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
|
34 |
+
def basic_search(self, query):
|
35 |
+
try:
|
36 |
+
results = list(search(query, num_results=1)) # Get top result
|
37 |
+
return results[0] if results else "No results found"
|
38 |
+
except Exception as e:
|
39 |
+
return f"Search error: {str(e)}"
|
40 |
|
41 |
|
42 |
|