Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -1,16 +1,34 @@
|
|
1 |
-
|
2 |
-
import whisper
|
3 |
import tempfile
|
|
|
|
|
4 |
from transformers import pipeline
|
5 |
|
6 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
7 |
whisper_model = whisper.load_model("base")
|
8 |
|
9 |
def download_audio(youtube_url):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
def transcribe_audio(audio_path):
|
16 |
result = whisper_model.transcribe(audio_path)
|
|
|
1 |
+
import os
|
|
|
2 |
import tempfile
|
3 |
+
import whisper
|
4 |
+
import subprocess
|
5 |
from transformers import pipeline
|
6 |
|
7 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
8 |
whisper_model = whisper.load_model("base")
|
9 |
|
10 |
def download_audio(youtube_url):
|
11 |
+
try:
|
12 |
+
temp_dir = tempfile.mkdtemp()
|
13 |
+
audio_path = os.path.join(temp_dir, "audio.mp3")
|
14 |
+
|
15 |
+
command = [
|
16 |
+
"yt-dlp",
|
17 |
+
"-x", "--audio-format", "mp3",
|
18 |
+
"-o", audio_path,
|
19 |
+
youtube_url
|
20 |
+
]
|
21 |
+
subprocess.run(command, check=True)
|
22 |
+
|
23 |
+
# yt-dlp renames with extensions, so fix actual filename
|
24 |
+
files = os.listdir(temp_dir)
|
25 |
+
if files:
|
26 |
+
return os.path.join(temp_dir, files[0])
|
27 |
+
else:
|
28 |
+
raise Exception("No audio file downloaded.")
|
29 |
+
except Exception as e:
|
30 |
+
print("Error downloading audio:", str(e))
|
31 |
+
raise e
|
32 |
|
33 |
def transcribe_audio(audio_path):
|
34 |
result = whisper_model.transcribe(audio_path)
|