wt002 commited on
Commit
d0476d0
·
verified ·
1 Parent(s): 7148ce0

UPdate app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -14
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 google.search import search # pip install googlesearch-python
12
 
13
  load_dotenv()
14
 
@@ -19,26 +19,23 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
19
 
20
  # --- Basic Agent Definition ---
21
 
 
 
22
  class BasicAgent:
23
  def __init__(self):
24
  print("BasicAgent initialized.")
25
 
26
  def __call__(self, question: str) -> str:
27
- print(f"Agent received question (first 50 chars): {question[:50]}...")
28
- fixed_answer = self.basic_search(question) # Now works correctly
29
- print(f"Agent returning answer: {fixed_answer}")
30
- return fixed_answer
31
-
32
 
33
-
34
  def basic_search(self, query):
35
- try:
36
- results = list(search(query, num_results=1)) # Get top result
37
- return results[0] if results else "No results found"
38
- except Exception as e:
39
- return f"Search error: {str(e)}"
40
-
41
-
42
 
43
  def run_and_submit_all( profile: gr.OAuthProfile | None):
44
  """
 
8
  from typing import List, Dict, Union
9
  import pandas as pd
10
  import wikipediaapi
11
+ from googlesearch import search
12
 
13
  load_dotenv()
14
 
 
19
 
20
  # --- Basic Agent Definition ---
21
 
22
+
23
+
24
  class BasicAgent:
25
  def __init__(self):
26
  print("BasicAgent initialized.")
27
 
28
  def __call__(self, question: str) -> str:
29
+ print(f"Agent received question: {question[:50]}...")
30
+ answer = self.basic_search(question)
31
+ print(f"Answer: {answer}")
32
+ return answer
 
33
 
 
34
  def basic_search(self, query):
35
+ from duckduckgo_search import ddg
36
+ results = ddg(query, max_results=3)
37
+
38
+
 
 
 
39
 
40
  def run_and_submit_all( profile: gr.OAuthProfile | None):
41
  """