Spaces:
Sleeping
Sleeping
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -12,15 +12,16 @@ class MediaTool(Tool):
|
|
| 12 |
name = "media_tool"
|
| 13 |
description = "Used for deciphering video and audio files."
|
| 14 |
inputs = {
|
| 15 |
-
"
|
| 16 |
"type": "string",
|
| 17 |
"description": "The name of the media file to transcribe."
|
| 18 |
}
|
| 19 |
}
|
| 20 |
output_type = "string"
|
| 21 |
|
| 22 |
-
def forward(self,
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
class WikipediaTool(Tool):
|
| 26 |
name = "wikipedia_api"
|
|
@@ -34,8 +35,13 @@ class WikipediaTool(Tool):
|
|
| 34 |
output_type = "string"
|
| 35 |
|
| 36 |
def forward(self, title: str):
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
class ExcelTool(Tool):
|
| 41 |
name = "read_excel"
|
|
@@ -48,9 +54,13 @@ class ExcelTool(Tool):
|
|
| 48 |
}
|
| 49 |
output_type = "string"
|
| 50 |
|
| 51 |
-
def forward(self,
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
class WebscraperTool(Tool):
|
| 56 |
name = "webscraper"
|
|
@@ -64,13 +74,17 @@ class WebscraperTool(Tool):
|
|
| 64 |
output_type = "string"
|
| 65 |
|
| 66 |
def forward(self, url: str):
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
# Initialize the DuckDuckGo search tool
|
| 76 |
class InternetSearchTool(Tool):
|
|
@@ -85,32 +99,13 @@ class InternetSearchTool(Tool):
|
|
| 85 |
output_type = "string"
|
| 86 |
|
| 87 |
def forward(self, question: str):
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
description = "Fetches dummy weather information for a given location."
|
| 96 |
-
inputs = {
|
| 97 |
-
"location": {
|
| 98 |
-
"type": "string",
|
| 99 |
-
"description": "The location to get weather information for."
|
| 100 |
-
}
|
| 101 |
-
}
|
| 102 |
-
output_type = "string"
|
| 103 |
-
|
| 104 |
-
def forward(self, location: str):
|
| 105 |
-
# Dummy weather data
|
| 106 |
-
weather_conditions = [
|
| 107 |
-
{"condition": "Rainy", "temp_c": 15},
|
| 108 |
-
{"condition": "Clear", "temp_c": 25},
|
| 109 |
-
{"condition": "Windy", "temp_c": 20}
|
| 110 |
-
]
|
| 111 |
-
# Randomly select a weather condition
|
| 112 |
-
data = random.choice(weather_conditions)
|
| 113 |
-
return f"Weather in {location}: {data['condition']}, {data['temp_c']}°C"
|
| 114 |
|
| 115 |
class HubStatsTool(Tool):
|
| 116 |
name = "hub_stats"
|
|
|
|
| 12 |
name = "media_tool"
|
| 13 |
description = "Used for deciphering video and audio files."
|
| 14 |
inputs = {
|
| 15 |
+
"filename": {
|
| 16 |
"type": "string",
|
| 17 |
"description": "The name of the media file to transcribe."
|
| 18 |
}
|
| 19 |
}
|
| 20 |
output_type = "string"
|
| 21 |
|
| 22 |
+
def forward(self, filename: str):
|
| 23 |
+
print(f"called MediaTool with {filename}")
|
| 24 |
+
return "This tool hasn't been implemented yet. Please return 0 if the task cannot be solved without knowing the contents of this file."
|
| 25 |
|
| 26 |
class WikipediaTool(Tool):
|
| 27 |
name = "wikipedia_api"
|
|
|
|
| 35 |
output_type = "string"
|
| 36 |
|
| 37 |
def forward(self, title: str):
|
| 38 |
+
print(f"called WikipediaTool with {title}")
|
| 39 |
+
try:
|
| 40 |
+
page = wikipedia.page(title)
|
| 41 |
+
content = page.content[:3000]
|
| 42 |
+
return content
|
| 43 |
+
except Exception as e:
|
| 44 |
+
return f"ERROR: {e}"
|
| 45 |
|
| 46 |
class ExcelTool(Tool):
|
| 47 |
name = "read_excel"
|
|
|
|
| 54 |
}
|
| 55 |
output_type = "string"
|
| 56 |
|
| 57 |
+
def forward(self, filename: str):
|
| 58 |
+
print(f"called ExcelTool with {filename}")
|
| 59 |
+
try:
|
| 60 |
+
df = pd.read_excel(filename, engine = "openpyxl")
|
| 61 |
+
return df
|
| 62 |
+
except Exception as e:
|
| 63 |
+
return f"ERROR: {e}"
|
| 64 |
|
| 65 |
class WebscraperTool(Tool):
|
| 66 |
name = "webscraper"
|
|
|
|
| 74 |
output_type = "string"
|
| 75 |
|
| 76 |
def forward(self, url: str):
|
| 77 |
+
print(f"called WebscraperTool with {url}")
|
| 78 |
+
try:
|
| 79 |
+
response = requests.get(url, stream=True)
|
| 80 |
+
if response.status_code == 200:
|
| 81 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
| 82 |
+
html_text = soup.get_text()
|
| 83 |
+
return html_text
|
| 84 |
+
else:
|
| 85 |
+
return "Website cannot be reached."
|
| 86 |
+
except Exception as e:
|
| 87 |
+
return f"ERROR: {e}"
|
| 88 |
|
| 89 |
# Initialize the DuckDuckGo search tool
|
| 90 |
class InternetSearchTool(Tool):
|
|
|
|
| 99 |
output_type = "string"
|
| 100 |
|
| 101 |
def forward(self, question: str):
|
| 102 |
+
print(f"called InternetSearchTool with {question}")
|
| 103 |
+
try:
|
| 104 |
+
search_tool = DuckDuckGoSearchTool()
|
| 105 |
+
result = search_tool(question)
|
| 106 |
+
return result
|
| 107 |
+
except Exception as e:
|
| 108 |
+
return f"ERROR: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
class HubStatsTool(Tool):
|
| 111 |
name = "hub_stats"
|