bako96 commited on
Commit
e00059f
·
verified ·
1 Parent(s): c852e5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -23
app.py CHANGED
@@ -7,30 +7,27 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
 
10
  @tool
11
  def get_youtube_channel_info(channel_name: str) -> str:
12
- """A tool that provides basic information about a YouTube channel using DuckDuckGo search.
13
  Args:
14
- channel_name: The name of the YouTube channel to get information about
15
  """
16
- search_tool = DuckDuckGoSearchTool(max_results=5) # Create DuckDuckGo search tool instance [[0]](#__0)
17
-
18
- # Search for the YouTube channel information
19
- query = f"{channel_name} youtube channel information subscribers videos"
20
- search_results = search_tool(query) # Execute the search [[1]](#__1)
21
-
22
- # Format the results in a readable way
23
- formatted_info = f"Information about YouTube channel '{channel_name}':\n\n"
24
-
25
- if search_results and len(search_results) > 0:
26
- for i, result in enumerate(search_results[:3]): # Limit to top 3 results
27
- formatted_info += f"Source {i+1}: {result.get('title', 'No title')}\n"
28
- formatted_info += f"Description: {result.get('snippet', 'No description')}\n"
29
- formatted_info += f"URL: {result.get('link', 'No link')}\n\n"
30
- else:
31
- formatted_info += "No information found for this channel."
32
-
33
- return formatted_info # Return the formatted information [[2]](#__2)
34
 
35
  @tool
36
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -60,7 +57,6 @@ model = HfApiModel(
60
  custom_role_conversions=None,
61
  )
62
 
63
-
64
  # Import tool from Hub
65
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
66
 
@@ -69,7 +65,7 @@ with open("prompts.yaml", 'r') as stream:
69
 
70
  agent = CodeAgent(
71
  model=model,
72
- tools=[final_answer, get_youtube_channel_info, get_current_time_in_timezone, image_generation_tool], # Added our tools here [[3]](#__3)
73
  max_steps=6,
74
  verbosity_level=1,
75
  grammar=None,
@@ -79,5 +75,4 @@ agent = CodeAgent(
79
  prompt_templates=prompt_templates
80
  )
81
 
82
-
83
  GradioUI(agent).launch()
 
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.
14
  Args:
15
+ channel_name: The name of the YouTube channel to search for.
16
  """
17
+ try:
18
+ # Use DuckDuckGoSearchTool to search for the YouTube channel
19
+ search_tool = DuckDuckGoSearchTool()
20
+ query = f"{channel_name} YouTube channel information"
21
+ search_results = search_tool.search(query)
22
+
23
+ # Extract and return the top result
24
+ if search_results and len(search_results) > 0:
25
+ top_result = search_results[0] # Get the first result
26
+ return f"Top search result for '{channel_name}': {top_result}"
27
+ else:
28
+ return f"No information found for YouTube channel '{channel_name}'."
29
+ except Exception as e:
30
+ return f"Error fetching YouTube channel information: {str(e)}"
 
 
 
 
31
 
32
  @tool
33
  def get_current_time_in_timezone(timezone: str) -> str:
 
57
  custom_role_conversions=None,
58
  )
59
 
 
60
  # Import tool from Hub
61
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
62
 
 
65
 
66
  agent = CodeAgent(
67
  model=model,
68
+ tools=[final_answer, get_youtube_channel_info, get_current_time_in_timezone], # Add tools here
69
  max_steps=6,
70
  verbosity_level=1,
71
  grammar=None,
 
75
  prompt_templates=prompt_templates
76
  )
77
 
 
78
  GradioUI(agent).launch()