Spaces:
Sleeping
Sleeping
update test
Browse files
app.py
CHANGED
|
@@ -66,13 +66,29 @@ def _return_yt_html_embed(yt_url):
|
|
| 66 |
|
| 67 |
|
| 68 |
def yt_transcribe(yt_url, return_timestamps=False):
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
html_embed_str = _return_yt_html_embed(yt_url)
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
text = transcribe("audio.mp3", return_timestamps=return_timestamps)
|
| 75 |
-
|
| 76 |
return html_embed_str, text
|
| 77 |
|
| 78 |
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
def yt_transcribe(yt_url, return_timestamps=False):
|
| 69 |
+
try:
|
| 70 |
+
yt = pt.YouTube(yt_url)
|
| 71 |
+
except Exception as e:
|
| 72 |
+
return f"Error fetching YouTube video: {str(e)}"
|
| 73 |
+
|
| 74 |
html_embed_str = _return_yt_html_embed(yt_url)
|
| 75 |
+
|
| 76 |
+
audio_streams = yt.streams.filter(only_audio=True)
|
| 77 |
+
if not audio_streams:
|
| 78 |
+
return "No audio streams available for this video."
|
| 79 |
+
|
| 80 |
+
stream = audio_streams[0]
|
| 81 |
+
|
| 82 |
+
try:
|
| 83 |
+
stream.download(filename="audio.mp3")
|
| 84 |
+
except Exception as e:
|
| 85 |
+
return f"Error downloading audio: {str(e)}"
|
| 86 |
+
|
| 87 |
+
if not os.path.exists("audio.mp3"):
|
| 88 |
+
return "Downloaded audio file not found."
|
| 89 |
|
| 90 |
text = transcribe("audio.mp3", return_timestamps=return_timestamps)
|
| 91 |
+
|
| 92 |
return html_embed_str, text
|
| 93 |
|
| 94 |
|