Spaces:
Sleeping
Sleeping
Luigi D'Addona
commited on
Commit
·
7d4acc0
1
Parent(s):
27b0cdd
aggiunto tool get_youtube_transcript
Browse files
agent.py
CHANGED
|
@@ -15,7 +15,7 @@ from langchain_google_genai import ChatGoogleGenerativeAI
|
|
| 15 |
# Local imports
|
| 16 |
from tools import get_search_tool, get_tavily_search_tool, get_wikipedia_tool, wikipedia_search, wikipedia_search_3,\
|
| 17 |
execute_python_code_from_file, download_taskid_file, analyze_excel_file, get_analyze_mp3_tool,\
|
| 18 |
-
get_analyze_image_tool, arxiv_search
|
| 19 |
|
| 20 |
# Nota: per i test in locale si usa il .env
|
| 21 |
# su HuggingFace invece si usano le variabili definite in Settings/"Variables and secrets"
|
|
@@ -106,7 +106,15 @@ search_tool = get_tavily_search_tool()
|
|
| 106 |
analyze_mp3_tool = get_analyze_mp3_tool(chat)
|
| 107 |
analyze_png_tool = get_analyze_image_tool(chat)
|
| 108 |
|
| 109 |
-
tools = [search_tool,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
# Bind tools to the model
|
| 112 |
chat_with_tools = chat.bind_tools(tools)
|
|
|
|
| 15 |
# Local imports
|
| 16 |
from tools import get_search_tool, get_tavily_search_tool, get_wikipedia_tool, wikipedia_search, wikipedia_search_3,\
|
| 17 |
execute_python_code_from_file, download_taskid_file, analyze_excel_file, get_analyze_mp3_tool,\
|
| 18 |
+
get_analyze_image_tool, arxiv_search, get_youtube_transcript
|
| 19 |
|
| 20 |
# Nota: per i test in locale si usa il .env
|
| 21 |
# su HuggingFace invece si usano le variabili definite in Settings/"Variables and secrets"
|
|
|
|
| 106 |
analyze_mp3_tool = get_analyze_mp3_tool(chat)
|
| 107 |
analyze_png_tool = get_analyze_image_tool(chat)
|
| 108 |
|
| 109 |
+
tools = [search_tool,
|
| 110 |
+
wikipedia_search_3,
|
| 111 |
+
execute_python_code_from_file,
|
| 112 |
+
download_taskid_file,
|
| 113 |
+
analyze_excel_file,
|
| 114 |
+
analyze_mp3_tool,
|
| 115 |
+
analyze_png_tool,
|
| 116 |
+
arxiv_search,
|
| 117 |
+
get_youtube_transcript]
|
| 118 |
|
| 119 |
# Bind tools to the model
|
| 120 |
chat_with_tools = chat.bind_tools(tools)
|
tools.py
CHANGED
|
@@ -11,6 +11,7 @@ from langchain_community.document_loaders import WikipediaLoader
|
|
| 11 |
import wikipedia
|
| 12 |
from langchain_tavily import TavilySearch
|
| 13 |
from langchain_community.document_loaders import ArxivLoader
|
|
|
|
| 14 |
from langchain_core.tools import tool
|
| 15 |
from langchain.tools import Tool
|
| 16 |
from langchain_core.messages import HumanMessage
|
|
@@ -313,4 +314,17 @@ def arxiv_search(query: str) -> str:
|
|
| 313 |
for doc in search_docs
|
| 314 |
]
|
| 315 |
)
|
| 316 |
-
return {"arxiv_results": formatted_search_docs}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
import wikipedia
|
| 12 |
from langchain_tavily import TavilySearch
|
| 13 |
from langchain_community.document_loaders import ArxivLoader
|
| 14 |
+
from langchain.document_loaders import YouTubeLoader
|
| 15 |
from langchain_core.tools import tool
|
| 16 |
from langchain.tools import Tool
|
| 17 |
from langchain_core.messages import HumanMessage
|
|
|
|
| 314 |
for doc in search_docs
|
| 315 |
]
|
| 316 |
)
|
| 317 |
+
return {"arxiv_results": formatted_search_docs}
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
@tool
|
| 321 |
+
def get_youtube_transcript(url: str) -> str:
|
| 322 |
+
"""
|
| 323 |
+
Fetches the transcript from a YouTube video URL and returns it as plain text.
|
| 324 |
+
"""
|
| 325 |
+
loader = YouTubeLoader.from_youtube_url(url, add_video_info=True)
|
| 326 |
+
docs = loader.load()
|
| 327 |
+
|
| 328 |
+
# Combine all transcript chunks into a single string
|
| 329 |
+
transcript = "\n".join(doc.page_content for doc in docs)
|
| 330 |
+
return transcript
|