Spaces:
Sleeping
Sleeping
Daniel Amendoeira
commited on
Update tools.py
Browse files
tools.py
CHANGED
@@ -36,11 +36,10 @@ datetime_tools = [current_date, day_of_week, days_until]
|
|
36 |
@tool
|
37 |
def transcribe_audio(audio_file: str, file_extension: str) -> str:
|
38 |
""" Transcribes an audio file to text
|
39 |
-
|
40 |
Args:
|
41 |
audio_file (str): local file path to the audio file (.mp3, .m4a, etc.)
|
42 |
file_extension (str): file extension of the audio, e.g. mp3
|
43 |
-
|
44 |
Returns:
|
45 |
str: The transcribed text from the audio.
|
46 |
"""
|
@@ -71,21 +70,18 @@ def transcribe_audio(audio_file: str, file_extension: str) -> str:
|
|
71 |
|
72 |
# TESTTTTT
|
73 |
@tool
|
74 |
-
def transcribe_youtube(
|
75 |
-
"""
|
76 |
Args:
|
77 |
-
|
78 |
"""
|
79 |
try:
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
# get transcript
|
84 |
-
ytt_api = YouTubeTranscriptApi()
|
85 |
-
transcript = ytt_api.fetch(video_id)
|
86 |
|
87 |
# keep only text
|
88 |
txt = '\n'.join([s.text for s in transcript.snippets])
|
89 |
return txt
|
90 |
except Exception as e:
|
91 |
-
return f"
|
|
|
36 |
@tool
|
37 |
def transcribe_audio(audio_file: str, file_extension: str) -> str:
|
38 |
""" Transcribes an audio file to text
|
|
|
39 |
Args:
|
40 |
audio_file (str): local file path to the audio file (.mp3, .m4a, etc.)
|
41 |
file_extension (str): file extension of the audio, e.g. mp3
|
42 |
+
|
43 |
Returns:
|
44 |
str: The transcribed text from the audio.
|
45 |
"""
|
|
|
70 |
|
71 |
# TESTTTTT
|
72 |
@tool
|
73 |
+
def transcribe_youtube(youtube_url: str) -> str:
|
74 |
+
""" Transcribes a YouTube video
|
75 |
Args:
|
76 |
+
youtube_url (str): youtube video's url
|
77 |
"""
|
78 |
try:
|
79 |
+
video_id = extract.video_id(youtube_url)
|
80 |
+
youtube_api = YouTubeTranscriptApi()
|
81 |
+
transcript = youtube_api.fetch(video_id)
|
|
|
|
|
|
|
82 |
|
83 |
# keep only text
|
84 |
txt = '\n'.join([s.text for s in transcript.snippets])
|
85 |
return txt
|
86 |
except Exception as e:
|
87 |
+
return f"transcribe_youtube failed: {e}"
|