tu101 commited on
Commit
8ca872b
·
verified ·
1 Parent(s): 0dfdfe7
Files changed (1) hide show
  1. tools.py +27 -0
tools.py CHANGED
@@ -21,6 +21,33 @@ from langchain_tavily import TavilySearch
21
  from langchain.schema import Document
22
  from langchain_community.document_loaders import YoutubeLoader
23
  from langchain_community.document_loaders import AssemblyAIAudioTranscriptLoader
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
 
26
  def excel_search(excel_path: str ) -> str:
 
21
  from langchain.schema import Document
22
  from langchain_community.document_loaders import YoutubeLoader
23
  from langchain_community.document_loaders import AssemblyAIAudioTranscriptLoader
24
+ from langchain_community.document_loaders.assemblyai import TranscriptFormat
25
+
26
+
27
+ def audio_search(path: str) -> str:
28
+ """Read an audio mp3 file and extract the text to understand it.
29
+
30
+ Args:
31
+ path: The path to the file. If the file is just {name}.mp3, then it is local, and just use {name}.mp3. """
32
+ aai.settings.api_key = "945f7d6c00f142158322cd0c13901024"
33
+ audio_file = "./"+path
34
+ loader = AssemblyAIAudioTranscriptLoader(file_path=audio_file, transcript_format=TranscriptFormat.PARAGRAPHS)
35
+
36
+ raw_docs = loader.load()
37
+ # convert each Document into a serializable dict
38
+ serialized_docs = [
39
+ {"text": doc.page_content, "metadata": doc.metadata}
40
+ for doc in raw_docs
41
+ ]
42
+ return {"audio_docs": serialized_docs}
43
+
44
+ audio_search_tool = Tool(
45
+ name="audio_search",
46
+ func=audio_search,
47
+ description="Uses an mp3 audio file path and extract it into paragraphs of text that are searchable."
48
+ )
49
+
50
+
51
 
52
 
53
  def excel_search(excel_path: str ) -> str: