Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
-
from duckduckgo_search import
|
| 3 |
from typing import List
|
| 4 |
import time
|
| 5 |
import requests
|
|
@@ -13,6 +13,7 @@ from Gradio_UI import GradioUI
|
|
| 13 |
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
|
|
|
|
| 16 |
@tool
|
| 17 |
def search_internet(query: str, max_results: int = 3) -> str:
|
| 18 |
"""A tool that searches the internet for information about a given query.
|
|
@@ -22,24 +23,28 @@ def search_internet(query: str, max_results: int = 3) -> str:
|
|
| 22 |
max_results: Maximum number of results to return (default: 3)
|
| 23 |
"""
|
| 24 |
try:
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
formatted_results += f"{i}. {result['title']}\n"
|
| 36 |
-
formatted_results += f" {result['link']}\n"
|
| 37 |
-
formatted_results += f" {result['body']}\n\n"
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
return f"Error performing search: {str(e)}"
|
|
|
|
|
|
|
| 43 |
@tool
|
| 44 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 45 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
+
from duckduckgo_search import DDGS
|
| 3 |
from typing import List
|
| 4 |
import time
|
| 5 |
import requests
|
|
|
|
| 13 |
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
|
| 16 |
+
|
| 17 |
@tool
|
| 18 |
def search_internet(query: str, max_results: int = 3) -> str:
|
| 19 |
"""A tool that searches the internet for information about a given query.
|
|
|
|
| 23 |
max_results: Maximum number of results to return (default: 3)
|
| 24 |
"""
|
| 25 |
try:
|
| 26 |
+
# Initialize the DuckDuckGo search
|
| 27 |
+
with DDGS() as ddgs:
|
| 28 |
+
# Perform the search
|
| 29 |
+
results = list(ddgs.text(query, max_results=max_results))
|
| 30 |
+
|
| 31 |
+
if not results:
|
| 32 |
+
return f"No results found for '{query}'"
|
| 33 |
+
|
| 34 |
+
# Format the results
|
| 35 |
+
formatted_results = f"Search results for '{query}':\n\n"
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
for i, result in enumerate(results, 1):
|
| 38 |
+
formatted_results += f"{i}. {result['title']}\n"
|
| 39 |
+
formatted_results += f" {result['link']}\n"
|
| 40 |
+
formatted_results += f" {result['body']}\n\n"
|
| 41 |
+
|
| 42 |
+
return formatted_results
|
| 43 |
|
| 44 |
except Exception as e:
|
| 45 |
return f"Error performing search: {str(e)}"
|
| 46 |
+
|
| 47 |
+
|
| 48 |
@tool
|
| 49 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 50 |
"""A tool that fetches the current local time in a specified timezone.
|