Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,32 +9,35 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
"""A tool that searches for
|
| 14 |
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
# If results is a list of links, you might parse them. For simplicity, we'll cast it to string and return.
|
| 33 |
-
if not results:
|
| 34 |
-
return "No PDF files found."
|
| 35 |
-
|
| 36 |
-
# Convert the results to a string for returning; you can format or parse further if desired.
|
| 37 |
-
return f"Top {num_results} PDF results for '{arg1}':\n\n{str(results)}"
|
| 38 |
|
| 39 |
@tool
|
| 40 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def search_image_urls(query: str, num_images: int) -> str:
|
| 13 |
+
"""A tool that searches for image URLs using DuckDuckGo.
|
| 14 |
|
| 15 |
Args:
|
| 16 |
+
query: The user-provided search keyword(s), e.g. 'cat'
|
| 17 |
+
num_images: The number of image URLs to return
|
| 18 |
"""
|
| 19 |
+
from duckduckgo_search import ddg_images
|
| 20 |
+
|
| 21 |
+
# Validate number of images
|
| 22 |
+
if num_images < 1:
|
| 23 |
+
num_images = 1
|
| 24 |
+
if num_images > 5:
|
| 25 |
+
# Let's limit to 5 for demonstration
|
| 26 |
+
num_images = 5
|
| 27 |
+
|
| 28 |
+
# Perform the image search
|
| 29 |
+
results = ddg_images(query, max_results=num_images)
|
| 30 |
+
if not results:
|
| 31 |
+
return f"No images found for '{query}'."
|
| 32 |
|
| 33 |
+
# Format results in a neat way
|
| 34 |
+
output_lines = []
|
| 35 |
+
for index, result in enumerate(results, start=1):
|
| 36 |
+
thumbnail = result.get("image", "No image URL found")
|
| 37 |
+
title = result.get("title", "No title")
|
| 38 |
+
output_lines.append(f"{index}. {title}\n {thumbnail}")
|
| 39 |
|
| 40 |
+
return "\n\n".join(output_lines)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
@tool
|
| 43 |
def get_current_time_in_timezone(timezone: str) -> str:
|