LamiaYT commited on
Commit
af10fd8
·
1 Parent(s): 46e21d3
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -17,17 +17,19 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
17
  # --- Tools ---
18
 
19
  @tool
20
- def extract_youtube_details(url: str) -> str:
21
  """
22
- Extract details from a YouTube video URL.
 
 
 
23
 
24
  Args:
25
- url (str): A valid YouTube video URL.
26
 
27
  Returns:
28
- str: Extracted metadata such as title, author, bird species count, and views.
29
  """
30
-
31
  try:
32
  time.sleep(random.uniform(1, 3))
33
  serper_key = os.getenv("SERPER_API_KEY")
@@ -51,13 +53,13 @@ def extract_youtube_details(url: str) -> str:
51
  for item in data['organic'][:3]:
52
  results.append(f"RESULT: {item.get('title', '')} - {item.get('snippet', '')}")
53
  return "\n".join(results) if results else "No Serper results"
54
- # If serper_key is not set or no results, fallback to Wikipedia
55
  return get_detailed_wikipedia(query)
56
  except Exception as e:
57
  return f"Search error: {str(e)}"
58
 
59
 
60
 
 
61
  @tool
62
  def extract_youtube_details(url: str) -> str:
63
  """
 
17
  # --- Tools ---
18
 
19
  @tool
20
+ def smart_web_search(query: str) -> str:
21
  """
22
+ Perform a smart web search using Serper API with Wikipedia fallback.
23
+
24
+ This tool queries the Serper API (if the key is set), formats the top results, and falls back to
25
+ Wikipedia if no data is returned or if the key is missing.
26
 
27
  Args:
28
+ query (str): The search query to execute.
29
 
30
  Returns:
31
+ str: Concatenated search results or Wikipedia summary.
32
  """
 
33
  try:
34
  time.sleep(random.uniform(1, 3))
35
  serper_key = os.getenv("SERPER_API_KEY")
 
53
  for item in data['organic'][:3]:
54
  results.append(f"RESULT: {item.get('title', '')} - {item.get('snippet', '')}")
55
  return "\n".join(results) if results else "No Serper results"
 
56
  return get_detailed_wikipedia(query)
57
  except Exception as e:
58
  return f"Search error: {str(e)}"
59
 
60
 
61
 
62
+
63
  @tool
64
  def extract_youtube_details(url: str) -> str:
65
  """