Update functions.py
Browse files- functions.py +8 -4
functions.py
CHANGED
@@ -225,7 +225,7 @@ def get_spacy():
|
|
225 |
@st.experimental_memo(suppress_st_warning=True)
|
226 |
def inference(link, upload, _asr_model):
|
227 |
'''Convert Youtube video or Audio upload to text'''
|
228 |
-
|
229 |
try:
|
230 |
|
231 |
if validators.url(link):
|
@@ -235,6 +235,9 @@ def inference(link, upload, _asr_model):
|
|
235 |
|
236 |
#Get audio file from YT
|
237 |
audio_file = yt.streams.filter(only_audio=True)[0].download(filename="audio.mp4")
|
|
|
|
|
|
|
238 |
|
239 |
#Get size of audio file
|
240 |
audio_size = round(os.path.getsize(audio_file)/(1024*1024),1)
|
@@ -299,11 +302,12 @@ def inference(link, upload, _asr_model):
|
|
299 |
|
300 |
return results, "Transcribed Earnings Audio"
|
301 |
|
302 |
-
except:
|
303 |
|
304 |
-
st.write('Whisper API Error
|
|
|
305 |
|
306 |
-
results = _asr_model.transcribe(
|
307 |
|
308 |
return results['text'], yt.title
|
309 |
|
|
|
225 |
@st.experimental_memo(suppress_st_warning=True)
|
226 |
def inference(link, upload, _asr_model):
|
227 |
'''Convert Youtube video or Audio upload to text'''
|
228 |
+
|
229 |
try:
|
230 |
|
231 |
if validators.url(link):
|
|
|
235 |
|
236 |
#Get audio file from YT
|
237 |
audio_file = yt.streams.filter(only_audio=True)[0].download(filename="audio.mp4")
|
238 |
+
|
239 |
+
if 'audio' not in st.session_state:
|
240 |
+
st.session_state['audio'] = audio_file
|
241 |
|
242 |
#Get size of audio file
|
243 |
audio_size = round(os.path.getsize(audio_file)/(1024*1024),1)
|
|
|
302 |
|
303 |
return results, "Transcribed Earnings Audio"
|
304 |
|
305 |
+
except Exception as e:
|
306 |
|
307 |
+
st.write(f'''Whisper API Error: {e},
|
308 |
+
Using Whisper module from GitHub, might take longer than expected''')
|
309 |
|
310 |
+
results = _asr_model.transcribe(st.session_state['audio'], task='transcribe', language='en')
|
311 |
|
312 |
return results['text'], yt.title
|
313 |
|