Update functions.py
Browse files- functions.py +7 -4
functions.py
CHANGED
@@ -114,12 +114,15 @@ def get_yt_audio(url):
|
|
114 |
}
|
115 |
|
116 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
|
|
|
|
|
117 |
ydl.download([url])
|
118 |
|
119 |
#with open(temp_audio_file+'.mp3', 'rb') as file:
|
120 |
audio_file = os.path.join('output', 'audio.mp3')
|
121 |
|
122 |
-
return audio_file
|
123 |
|
124 |
|
125 |
@st.cache_resource
|
@@ -289,14 +292,14 @@ def get_spacy():
|
|
289 |
return nlp
|
290 |
|
291 |
@st.cache_data
|
292 |
-
def inference(link, upload, _asr_model):
|
293 |
'''Convert Youtube video or Audio upload to text'''
|
294 |
|
295 |
try:
|
296 |
|
297 |
if validators.url(link):
|
298 |
|
299 |
-
audio_file = get_yt_audio(link)
|
300 |
# title = yt.title
|
301 |
|
302 |
if 'audio' not in st.session_state:
|
@@ -330,7 +333,7 @@ def inference(link, upload, _asr_model):
|
|
330 |
|
331 |
results = ','.join(transcriptions)
|
332 |
|
333 |
-
return results,
|
334 |
|
335 |
elif upload:
|
336 |
|
|
|
114 |
}
|
115 |
|
116 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
117 |
+
|
118 |
+
info = ydl.extract_info(url, download=False)
|
119 |
+
title = info.get('title', None)
|
120 |
ydl.download([url])
|
121 |
|
122 |
#with open(temp_audio_file+'.mp3', 'rb') as file:
|
123 |
audio_file = os.path.join('output', 'audio.mp3')
|
124 |
|
125 |
+
return audio_file, title
|
126 |
|
127 |
|
128 |
@st.cache_resource
|
|
|
292 |
return nlp
|
293 |
|
294 |
@st.cache_data
|
295 |
+
def inference(link, title, upload, _asr_model):
|
296 |
'''Convert Youtube video or Audio upload to text'''
|
297 |
|
298 |
try:
|
299 |
|
300 |
if validators.url(link):
|
301 |
|
302 |
+
audio_file, title = get_yt_audio(link)
|
303 |
# title = yt.title
|
304 |
|
305 |
if 'audio' not in st.session_state:
|
|
|
333 |
|
334 |
results = ','.join(transcriptions)
|
335 |
|
336 |
+
return results, title
|
337 |
|
338 |
elif upload:
|
339 |
|