bako96 commited on
Commit
cb33157
·
verified ·
1 Parent(s): 4d55c5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -7,7 +7,6 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- # Tool to fetch basic information about a YouTube channel using DuckDuckGo search
11
  @tool
12
  def get_youtube_channel_info(channel_name: str) -> str:
13
  """Fetch basic information about a YouTube channel using DuckDuckGo search.
@@ -17,19 +16,31 @@ def get_youtube_channel_info(channel_name: str) -> str:
17
  try:
18
  # Initialize DuckDuckGoSearchTool with a maximum of 5 results
19
  search_tool = DuckDuckGoSearchTool(max_results=5)
20
- query = f"{channel_name} YouTube channel Description"
21
  print(f"Searching for: {query}") # Debug print statement
22
 
23
  # Perform the search
24
  search_results = search_tool.forward(query)
25
  print(f"Raw search results:\n{search_results}") # Debug print statement
26
 
27
- # Return the formatted search results
28
- return f"Search results for '{channel_name}':\n\n{search_results[0:3]}"
 
 
 
 
 
 
 
 
 
 
 
29
  except Exception as e:
30
  print(f"Error occurred while searching for '{channel_name}': {str(e)}") # Debug print statement
31
  return f"Error fetching YouTube channel information: {str(e)}"
32
 
 
33
  @tool
34
  def get_current_time_in_timezone(timezone: str) -> str:
35
  """A tool that fetches the current local time in a specified timezone.
 
7
 
8
  from Gradio_UI import GradioUI
9
 
 
10
  @tool
11
  def get_youtube_channel_info(channel_name: str) -> str:
12
  """Fetch basic information about a YouTube channel using DuckDuckGo search.
 
16
  try:
17
  # Initialize DuckDuckGoSearchTool with a maximum of 5 results
18
  search_tool = DuckDuckGoSearchTool(max_results=5)
19
+ query = f"{channel_name} YouTube channel information"
20
  print(f"Searching for: {query}") # Debug print statement
21
 
22
  # Perform the search
23
  search_results = search_tool.forward(query)
24
  print(f"Raw search results:\n{search_results}") # Debug print statement
25
 
26
+ # Split the results into a list of lines
27
+ results_lines = search_results.split("\n\n")[1:] # Skip the "## Search Results" header
28
+ print(f"Parsed results lines:\n{results_lines}") # Debug print statement
29
+
30
+ # Extract the top 3 results
31
+ top_3_results = results_lines[:3]
32
+ print(f"Top 3 results:\n{top_3_results}") # Debug print statement
33
+
34
+ # Concatenate the top 3 results into a single string
35
+ concatenated_results = "\n\n".join(top_3_results)
36
+ print(f"Concatenated top 3 results:\n{concatenated_results}") # Debug print statement
37
+
38
+ return f"Top 3 search results for '{channel_name}':\n\n{concatenated_results}"
39
  except Exception as e:
40
  print(f"Error occurred while searching for '{channel_name}': {str(e)}") # Debug print statement
41
  return f"Error fetching YouTube channel information: {str(e)}"
42
 
43
+
44
  @tool
45
  def get_current_time_in_timezone(timezone: str) -> str:
46
  """A tool that fetches the current local time in a specified timezone.