WeByT3 commited on
Commit
b13cbd1
·
verified ·
1 Parent(s): b7807d8

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +26 -0
tools.py CHANGED
@@ -3,6 +3,11 @@ from langchain_community.tools.tavily_search import TavilySearchResults
3
  from youtube_transcript_api import YouTubeTranscriptApi
4
  from langchain_community.document_loaders import WikipediaLoader
5
  import pandas as pd
 
 
 
 
 
6
 
7
  @tool
8
  def add(a: int, b: int) -> int:
@@ -54,6 +59,9 @@ def divide(a: int, b: int) -> int:
54
  def read_excel_summary(file_path: str) -> str:
55
  """
56
  Reads an Excel file and returns basic summary statistics, column names, and row count.
 
 
 
57
  """
58
  try:
59
  df = pd.read_excel(file_path, engine="openpyxl")
@@ -94,6 +102,21 @@ def wiki_search(query: str) -> str:
94
  ])
95
  return {"wiki_results": formatted_search_docs}
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  @tool
98
  def arvix_search(query: str) -> str:
99
  """Search Arxiv for a query and return maximum 3 result.
@@ -113,6 +136,9 @@ def fetch_youtube_transcript(video_url: str) -> str:
113
  """
114
  Fetch transcript of a YouTube video by URL.
115
  Returns plain text if transcript is available.
 
 
 
116
  """
117
  import re
118
  video_id_match = re.search(r"(?:v=|youtu\.be/)([\w-]+)", video_url)
 
3
  from youtube_transcript_api import YouTubeTranscriptApi
4
  from langchain_community.document_loaders import WikipediaLoader
5
  import pandas as pd
6
+ import whisper
7
+ import os
8
+ import tempfile
9
+
10
+ whisper_model = whisper.load_model("base")
11
 
12
  @tool
13
  def add(a: int, b: int) -> int:
 
59
  def read_excel_summary(file_path: str) -> str:
60
  """
61
  Reads an Excel file and returns basic summary statistics, column names, and row count.
62
+
63
+ Args:
64
+ file_path: The path to the Excel file
65
  """
66
  try:
67
  df = pd.read_excel(file_path, engine="openpyxl")
 
102
  ])
103
  return {"wiki_results": formatted_search_docs}
104
 
105
+ @tool
106
+ def transcribe_audio(file_path: str) -> str:
107
+ """
108
+ Transcribes an audio file (MP3, WAV, etc.) to text using Whisper.
109
+ Returns the transcribed text.
110
+
111
+ Args:
112
+ file_path: the path to the audio file
113
+ """
114
+ try:
115
+ result = whisper_model.transcribe(file_path)
116
+ return result["text"]
117
+ except Exception as e:
118
+ return f"Error during transcription: {str(e)}"
119
+
120
  @tool
121
  def arvix_search(query: str) -> str:
122
  """Search Arxiv for a query and return maximum 3 result.
 
136
  """
137
  Fetch transcript of a YouTube video by URL.
138
  Returns plain text if transcript is available.
139
+
140
+ Args:
141
+ video_url: The YouTube url link to the video
142
  """
143
  import re
144
  video_id_match = re.search(r"(?:v=|youtu\.be/)([\w-]+)", video_url)