Spaces:
Build error
Build error
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -5,6 +5,7 @@ from huggingface_hub import list_models
|
|
| 5 |
import requests
|
| 6 |
from bs4 import BeautifulSoup
|
| 7 |
import openpyxl
|
|
|
|
| 8 |
|
| 9 |
class WikipediaTool(Tool):
|
| 10 |
name = "wikipedia_api"
|
|
@@ -17,10 +18,9 @@ class WikipediaTool(Tool):
|
|
| 17 |
}
|
| 18 |
output_type = "string"
|
| 19 |
|
| 20 |
-
def forward(self,
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
return result
|
| 24 |
|
| 25 |
class ExcelTool(Tool):
|
| 26 |
name = "read_excel"
|
|
@@ -49,10 +49,14 @@ class WebscraperTool(Tool):
|
|
| 49 |
}
|
| 50 |
output_type = "string"
|
| 51 |
|
| 52 |
-
def forward(self,
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
# Initialize the DuckDuckGo search tool
|
| 58 |
class InternetSearchTool(Tool):
|
|
|
|
| 5 |
import requests
|
| 6 |
from bs4 import BeautifulSoup
|
| 7 |
import openpyxl
|
| 8 |
+
import wikipedia
|
| 9 |
|
| 10 |
class WikipediaTool(Tool):
|
| 11 |
name = "wikipedia_api"
|
|
|
|
| 18 |
}
|
| 19 |
output_type = "string"
|
| 20 |
|
| 21 |
+
def forward(self, title: str):
|
| 22 |
+
page = wikipedia.page(title)
|
| 23 |
+
return page.content
|
|
|
|
| 24 |
|
| 25 |
class ExcelTool(Tool):
|
| 26 |
name = "read_excel"
|
|
|
|
| 49 |
}
|
| 50 |
output_type = "string"
|
| 51 |
|
| 52 |
+
def forward(self, url: str):
|
| 53 |
+
response = requests.get(url, stream=True)
|
| 54 |
+
if response.status_code == 200:
|
| 55 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
| 56 |
+
html_text = soup.get_text()
|
| 57 |
+
return html_text
|
| 58 |
+
else:
|
| 59 |
+
raise Exception(f"Failed to retrieve the webpage. Status code: {response.status_code}")
|
| 60 |
|
| 61 |
# Initialize the DuckDuckGo search tool
|
| 62 |
class InternetSearchTool(Tool):
|