Spaces:
Running
Running
Daniel Amendoeira
commited on
Update tools.py
Browse files
tools.py
CHANGED
@@ -6,6 +6,8 @@ import os
|
|
6 |
import tempfile
|
7 |
from urllib.parse import urlparse
|
8 |
from openai import OpenAI
|
|
|
|
|
9 |
|
10 |
@tool
|
11 |
def current_date(_) -> str :
|
@@ -65,4 +67,25 @@ def transcribe_audio(audio_file: str, file_extension: str) -> str:
|
|
65 |
return transcription.text
|
66 |
|
67 |
except Exception as e:
|
68 |
-
return f"transcribe_audio failed: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
import tempfile
|
7 |
from urllib.parse import urlparse
|
8 |
from openai import OpenAI
|
9 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
10 |
+
from pytube import extract
|
11 |
|
12 |
@tool
|
13 |
def current_date(_) -> str :
|
|
|
67 |
return transcription.text
|
68 |
|
69 |
except Exception as e:
|
70 |
+
return f"transcribe_audio failed: {e}"
|
71 |
+
|
72 |
+
# TESTTTTT
|
73 |
+
@tool
|
74 |
+
def get_youtube_transcript(page_url: str) -> str:
|
75 |
+
"""Get the transcript of a YouTube video
|
76 |
+
Args:
|
77 |
+
page_url (str): YouTube URL of the video
|
78 |
+
"""
|
79 |
+
try:
|
80 |
+
# get video ID from URL
|
81 |
+
video_id = extract.video_id(page_url)
|
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"get_youtube_transcript failed: {e}"
|