Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ import requests
|
|
8 |
from typing import List, Dict, Union
|
9 |
import pandas as pd
|
10 |
import wikipediaapi
|
11 |
-
from
|
12 |
|
13 |
load_dotenv()
|
14 |
|
@@ -19,8 +19,6 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
19 |
|
20 |
# --- Basic Agent Definition ---
|
21 |
|
22 |
-
|
23 |
-
|
24 |
class BasicAgent:
|
25 |
def __init__(self):
|
26 |
print("BasicAgent initialized.")
|
@@ -32,10 +30,27 @@ class BasicAgent:
|
|
32 |
return answer
|
33 |
|
34 |
def basic_search(self, query):
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
|
39 |
|
40 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
41 |
"""
|
|
|
8 |
from typing import List, Dict, Union
|
9 |
import pandas as pd
|
10 |
import wikipediaapi
|
11 |
+
from duckduckgo_search import ddg
|
12 |
|
13 |
load_dotenv()
|
14 |
|
|
|
19 |
|
20 |
# --- Basic Agent Definition ---
|
21 |
|
|
|
|
|
22 |
class BasicAgent:
|
23 |
def __init__(self):
|
24 |
print("BasicAgent initialized.")
|
|
|
30 |
return answer
|
31 |
|
32 |
def basic_search(self, query):
|
33 |
+
try:
|
34 |
+
# Get search results from DuckDuckGo
|
35 |
+
results = ddg(query, max_results=3)
|
36 |
+
|
37 |
+
# Format the results
|
38 |
+
if not results:
|
39 |
+
return "No results found"
|
40 |
+
|
41 |
+
formatted_results = []
|
42 |
+
for i, result in enumerate(results, 1):
|
43 |
+
formatted_results.append(
|
44 |
+
f"{i}. {result['title']}\n"
|
45 |
+
f" {result['link']}\n"
|
46 |
+
f" {result['body']}"
|
47 |
+
)
|
48 |
+
|
49 |
+
return "\n\n".join(formatted_results)
|
50 |
+
|
51 |
+
except Exception as e:
|
52 |
+
return f"Search error: {str(e)}"
|
53 |
|
|
|
54 |
|
55 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
56 |
"""
|