Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ import yaml
|
|
| 7 |
from Gradio_UI import GradioUI
|
| 8 |
|
| 9 |
|
|
|
|
| 10 |
@tool
|
| 11 |
def duckduckgo_search(query: str, max_results: int = 5) -> str:
|
| 12 |
"""
|
|
@@ -19,30 +20,34 @@ def duckduckgo_search(query: str, max_results: int = 5) -> str:
|
|
| 19 |
Returns:
|
| 20 |
str: A formatted string containing search results.
|
| 21 |
"""
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
results = ddgs.text(query, max_results=max_results)
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
|
| 36 |
-
except Exception as e:
|
| 37 |
-
return f"Search failed due to error: {str(e)}"
|
| 38 |
|
| 39 |
@tool
|
| 40 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 41 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
tz = pytz.timezone(timezone)
|
| 43 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 44 |
-
return f"The current time in {timezone} is {local_time}"
|
| 45 |
-
|
| 46 |
|
| 47 |
final_answer = FinalAnswerTool()
|
| 48 |
|
|
|
|
| 7 |
from Gradio_UI import GradioUI
|
| 8 |
|
| 9 |
|
| 10 |
+
|
| 11 |
@tool
|
| 12 |
def duckduckgo_search(query: str, max_results: int = 5) -> str:
|
| 13 |
"""
|
|
|
|
| 20 |
Returns:
|
| 21 |
str: A formatted string containing search results.
|
| 22 |
"""
|
| 23 |
+
with DDGS() as ddgs:
|
| 24 |
+
results = ddgs.text(query, max_results=max_results)
|
|
|
|
| 25 |
|
| 26 |
+
output = []
|
| 27 |
+
for i, r in enumerate(results, 1):
|
| 28 |
+
output.append(
|
| 29 |
+
f"{i}. {r.get('title')}\n"
|
| 30 |
+
f"{r.get('href')}\n"
|
| 31 |
+
f"{r.get('body')}\n"
|
| 32 |
+
)
|
| 33 |
|
| 34 |
+
return "\n".join(output) if output else "No results found."
|
| 35 |
|
|
|
|
|
|
|
| 36 |
|
| 37 |
@tool
|
| 38 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 39 |
+
"""
|
| 40 |
+
Get the current local time in a specified timezone.
|
| 41 |
+
|
| 42 |
+
Args:
|
| 43 |
+
timezone (str): A valid timezone string such as 'America/New_York'.
|
| 44 |
+
|
| 45 |
+
Returns:
|
| 46 |
+
str: The current local time formatted as YYYY-MM-DD HH:MM:SS.
|
| 47 |
+
"""
|
| 48 |
tz = pytz.timezone(timezone)
|
| 49 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 50 |
+
return f"The current local time in {timezone} is {local_time}"
|
|
|
|
| 51 |
|
| 52 |
final_answer = FinalAnswerTool()
|
| 53 |
|