Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
"""
|
| 13 |
Args:
|
| 14 |
-
channel_name: The name of the YouTube channel to
|
| 15 |
"""
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 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
|
| 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()
|