Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
-
from smolagents import
|
| 2 |
import re
|
| 3 |
from typing import Dict, Any, List
|
| 4 |
import json
|
| 5 |
-
from tools.final_answer import FinalAnswerTool
|
| 6 |
|
| 7 |
@tool
|
| 8 |
def search_youtuber(youtuber_name: str) -> Dict[str, Any]:
|
|
@@ -18,16 +17,16 @@ def search_youtuber(youtuber_name: str) -> Dict[str, Any]:
|
|
| 18 |
search_tool = DuckDuckGoSearchTool()
|
| 19 |
|
| 20 |
# First search for the YouTuber's channel
|
| 21 |
-
channel_results = search_tool
|
| 22 |
|
| 23 |
# Then search for more specific information
|
| 24 |
-
stats_results = search_tool
|
| 25 |
|
| 26 |
# Search for recent content/news
|
| 27 |
-
content_results = search_tool
|
| 28 |
|
| 29 |
# Search for background information
|
| 30 |
-
background_results = search_tool
|
| 31 |
|
| 32 |
return {
|
| 33 |
"channel_results": channel_results,
|
|
@@ -173,29 +172,10 @@ def format_youtuber_profile(youtuber_name: str, info: Dict[str, Any]) -> str:
|
|
| 173 |
|
| 174 |
# Create the specialized YouTuber information agent
|
| 175 |
search_tool = DuckDuckGoSearchTool()
|
| 176 |
-
final_answer = FinalAnswerTool()
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
temperature=0.3,
|
| 182 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 183 |
-
),
|
| 184 |
-
tools=[
|
| 185 |
-
search_tool,
|
| 186 |
-
search_youtuber,
|
| 187 |
-
extract_youtube_info,
|
| 188 |
-
format_youtuber_profile,
|
| 189 |
-
final_answer
|
| 190 |
-
],
|
| 191 |
-
max_steps=8,
|
| 192 |
-
verbosity_level=1,
|
| 193 |
-
name="YouTuberInfoAgent",
|
| 194 |
-
description="A specialized agent that finds and provides information about YouTubers using DuckDuckGo search with proper citations."
|
| 195 |
-
)
|
| 196 |
-
|
| 197 |
-
# Example prompt template
|
| 198 |
-
system_prompt = """You are a specialized YouTuber information agent. Your task is to find and provide detailed information about YouTube creators when given a YouTuber's name.
|
| 199 |
|
| 200 |
ALWAYS include multiple distinct sources in your response, at LEAST 3-4, by $CITE_id at the end of each information part, like , .
|
| 201 |
|
|
@@ -206,24 +186,38 @@ Follow these steps:
|
|
| 206 |
4. Present the information to the user in a well-organized format
|
| 207 |
|
| 208 |
Always verify the information before presenting it and indicate if certain information couldn't be retrieved.
|
| 209 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
-
#
|
| 212 |
-
|
| 213 |
|
| 214 |
def process_request(youtuber_name):
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
user_prompt=f"Please provide information about the YouTuber: {youtuber_name}"
|
| 218 |
-
)
|
| 219 |
return response
|
| 220 |
|
| 221 |
-
|
|
|
|
| 222 |
fn=process_request,
|
| 223 |
-
inputs="
|
| 224 |
-
outputs="
|
| 225 |
title="YouTuber Information Agent",
|
| 226 |
-
description="Enter a YouTuber's name to get information about them with proper citations."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
)
|
| 228 |
|
| 229 |
-
|
|
|
|
|
|
| 1 |
+
from smolagents import Agent, DuckDuckGoSearchTool, tool
|
| 2 |
import re
|
| 3 |
from typing import Dict, Any, List
|
| 4 |
import json
|
|
|
|
| 5 |
|
| 6 |
@tool
|
| 7 |
def search_youtuber(youtuber_name: str) -> Dict[str, Any]:
|
|
|
|
| 17 |
search_tool = DuckDuckGoSearchTool()
|
| 18 |
|
| 19 |
# First search for the YouTuber's channel
|
| 20 |
+
channel_results = search_tool(f"{youtuber_name} youtube channel")
|
| 21 |
|
| 22 |
# Then search for more specific information
|
| 23 |
+
stats_results = search_tool(f"{youtuber_name} youtube stats subscribers")
|
| 24 |
|
| 25 |
# Search for recent content/news
|
| 26 |
+
content_results = search_tool(f"{youtuber_name} recent videos content")
|
| 27 |
|
| 28 |
# Search for background information
|
| 29 |
+
background_results = search_tool(f"{youtuber_name} youtube background history")
|
| 30 |
|
| 31 |
return {
|
| 32 |
"channel_results": channel_results,
|
|
|
|
| 172 |
|
| 173 |
# Create the specialized YouTuber information agent
|
| 174 |
search_tool = DuckDuckGoSearchTool()
|
|
|
|
| 175 |
|
| 176 |
+
# Define the agent with the proper system prompt
|
| 177 |
+
youtuber_info_agent = Agent(
|
| 178 |
+
system_prompt="""You are a specialized YouTuber information agent. Your task is to find and provide detailed information about YouTube creators when given a YouTuber's name.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
ALWAYS include multiple distinct sources in your response, at LEAST 3-4, by $CITE_id at the end of each information part, like , .
|
| 181 |
|
|
|
|
| 186 |
4. Present the information to the user in a well-organized format
|
| 187 |
|
| 188 |
Always verify the information before presenting it and indicate if certain information couldn't be retrieved.
|
| 189 |
+
""",
|
| 190 |
+
tools=[
|
| 191 |
+
search_tool,
|
| 192 |
+
search_youtuber,
|
| 193 |
+
extract_youtube_info,
|
| 194 |
+
format_youtuber_profile
|
| 195 |
+
],
|
| 196 |
+
max_steps=8,
|
| 197 |
+
verbose=True
|
| 198 |
+
)
|
| 199 |
|
| 200 |
+
# Set up the Gradio interface
|
| 201 |
+
import gradio as gr
|
| 202 |
|
| 203 |
def process_request(youtuber_name):
|
| 204 |
+
# Use the agent to process the request
|
| 205 |
+
response = youtuber_info_agent(f"Please provide information about the YouTuber: {youtuber_name}")
|
|
|
|
|
|
|
| 206 |
return response
|
| 207 |
|
| 208 |
+
# Create the Gradio interface
|
| 209 |
+
interface = gr.Interface(
|
| 210 |
fn=process_request,
|
| 211 |
+
inputs=gr.Textbox(label="Enter YouTuber Name"),
|
| 212 |
+
outputs=gr.Markdown(label="YouTuber Information"),
|
| 213 |
title="YouTuber Information Agent",
|
| 214 |
+
description="Enter a YouTuber's name to get information about them with proper citations.",
|
| 215 |
+
examples=[
|
| 216 |
+
["MrBeast"],
|
| 217 |
+
["PewDiePie"],
|
| 218 |
+
["Marques Brownlee"]
|
| 219 |
+
]
|
| 220 |
)
|
| 221 |
|
| 222 |
+
# Launch with sharing enabled
|
| 223 |
+
interface.launch(share=True)
|