Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,22 +67,30 @@ def search_duckduckgo(query: str, num_results: int = 3) -> str:
|
|
| 67 |
|
| 68 |
for i in range(len(result_lines)):
|
| 69 |
if result_lines[i].startswith("[") and len(parsed_results) < num_results:
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
summary = result_lines[i+2].strip() if i+2 < len(result_lines) else "No summary available."
|
| 78 |
-
|
| 79 |
-
formatted_result = f"🔎 **[{title}]({link})**\n📌 {summary}"
|
| 80 |
-
parsed_results.append(formatted_result)
|
| 81 |
|
| 82 |
if not parsed_results:
|
| 83 |
return f"No valid results found for '{query}'."
|
| 84 |
|
| 85 |
-
return "\n\n".join(parsed_results)
|
|
|
|
| 86 |
|
| 87 |
|
| 88 |
|
|
|
|
| 67 |
|
| 68 |
for i in range(len(result_lines)):
|
| 69 |
if result_lines[i].startswith("[") and len(parsed_results) < num_results:
|
| 70 |
+
try:
|
| 71 |
+
title_end = result_lines[i].index("]") # Find the end of the title
|
| 72 |
+
title = result_lines[i][1:title_end] # Extract title
|
| 73 |
+
link = result_lines[i][title_end+2:].strip() # Extract link
|
| 74 |
+
|
| 75 |
+
# Ensure the link is valid
|
| 76 |
+
if not link.startswith("http"):
|
| 77 |
+
continue # Skip invalid links
|
| 78 |
+
|
| 79 |
+
summary = result_lines[i+1].strip() if i+1 < len(result_lines) else "No summary available."
|
| 80 |
+
|
| 81 |
+
# Correct Markdown format
|
| 82 |
+
formatted_result = f"🔎 **[{title}]({link})**\n📌 {summary}"
|
| 83 |
+
parsed_results.append(formatted_result)
|
| 84 |
|
| 85 |
+
except Exception as e:
|
| 86 |
+
print(f"Error parsing result: {e}")
|
| 87 |
+
continue # Skip problematic entries
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
if not parsed_results:
|
| 90 |
return f"No valid results found for '{query}'."
|
| 91 |
|
| 92 |
+
return "\n\n".join(parsed_results) # Return formatted results
|
| 93 |
+
|
| 94 |
|
| 95 |
|
| 96 |
|