Update functions.py
Browse files- functions.py +10 -14
functions.py
CHANGED
@@ -217,7 +217,7 @@ def gen_embeddings(embedding_model):
|
|
217 |
return embeddings
|
218 |
|
219 |
@st.cache_data
|
220 |
-
def embed_text(query,
|
221 |
|
222 |
'''Embed text and generate semantic search scores'''
|
223 |
|
@@ -230,8 +230,6 @@ def embed_text(query,title,embedding_model,_docsearch):
|
|
230 |
temperature=0
|
231 |
)
|
232 |
|
233 |
-
title = title.split()[0].lower()
|
234 |
-
|
235 |
chain = ConversationalRetrievalChain.from_llm(chat_llm,
|
236 |
retriever= _docsearch.as_retriever(),
|
237 |
qa_prompt = load_prompt(),
|
@@ -304,8 +302,7 @@ def inference(link, upload, _asr_model):
|
|
304 |
|
305 |
audio_file = get_yt_audio(link)
|
306 |
# title = yt.title
|
307 |
-
|
308 |
-
print(len(audio_file))
|
309 |
if 'audio' not in st.session_state:
|
310 |
st.session_state['audio'] = audio_file
|
311 |
|
@@ -317,13 +314,12 @@ def inference(link, upload, _asr_model):
|
|
317 |
|
318 |
#Use whisper API
|
319 |
results = load_whisper_api(audio_file)['text']
|
320 |
-
print(results)
|
321 |
|
322 |
else:
|
323 |
|
324 |
-
st.
|
325 |
|
326 |
-
song = AudioSegment.from_file(audio_file, format='
|
327 |
|
328 |
# PyDub handles time in milliseconds
|
329 |
twenty_minutes = 20 * 60 * 1000
|
@@ -333,8 +329,8 @@ def inference(link, upload, _asr_model):
|
|
333 |
transcriptions = []
|
334 |
|
335 |
for i, chunk in enumerate(chunks):
|
336 |
-
chunk.export(f'output/chunk_{i}.
|
337 |
-
transcriptions.append(load_whisper_api('output/chunk_{i}.
|
338 |
|
339 |
results = ','.join(transcriptions)
|
340 |
|
@@ -365,8 +361,8 @@ def inference(link, upload, _asr_model):
|
|
365 |
transcriptions = []
|
366 |
|
367 |
for i, chunk in enumerate(chunks):
|
368 |
-
chunk.export(f'output/chunk_{i}.
|
369 |
-
transcriptions.append(load_whisper_api('output/chunk_{i}.
|
370 |
|
371 |
results = ','.join(transcriptions)
|
372 |
|
@@ -374,8 +370,8 @@ def inference(link, upload, _asr_model):
|
|
374 |
|
375 |
except Exception as e:
|
376 |
|
377 |
-
st.
|
378 |
-
Using Whisper module from GitHub, might take longer than expected''')
|
379 |
|
380 |
results = _asr_model.transcribe(st.session_state['audio'], task='transcribe', language='en')
|
381 |
|
|
|
217 |
return embeddings
|
218 |
|
219 |
@st.cache_data
|
220 |
+
def embed_text(query,embedding_model,_docsearch):
|
221 |
|
222 |
'''Embed text and generate semantic search scores'''
|
223 |
|
|
|
230 |
temperature=0
|
231 |
)
|
232 |
|
|
|
|
|
233 |
chain = ConversationalRetrievalChain.from_llm(chat_llm,
|
234 |
retriever= _docsearch.as_retriever(),
|
235 |
qa_prompt = load_prompt(),
|
|
|
302 |
|
303 |
audio_file = get_yt_audio(link)
|
304 |
# title = yt.title
|
305 |
+
|
|
|
306 |
if 'audio' not in st.session_state:
|
307 |
st.session_state['audio'] = audio_file
|
308 |
|
|
|
314 |
|
315 |
#Use whisper API
|
316 |
results = load_whisper_api(audio_file)['text']
|
|
|
317 |
|
318 |
else:
|
319 |
|
320 |
+
st.warning('File size larger than 24mb, applying chunking and transcription',icon="⚠️")
|
321 |
|
322 |
+
song = AudioSegment.from_file(audio_file, format='mp3')
|
323 |
|
324 |
# PyDub handles time in milliseconds
|
325 |
twenty_minutes = 20 * 60 * 1000
|
|
|
329 |
transcriptions = []
|
330 |
|
331 |
for i, chunk in enumerate(chunks):
|
332 |
+
chunk.export(f'output/chunk_{i}.mp3', format='mp3')
|
333 |
+
transcriptions.append(load_whisper_api('output/chunk_{i}.mp3')['text'])
|
334 |
|
335 |
results = ','.join(transcriptions)
|
336 |
|
|
|
361 |
transcriptions = []
|
362 |
|
363 |
for i, chunk in enumerate(chunks):
|
364 |
+
chunk.export(f'output/chunk_{i}.mp3', format='mp3')
|
365 |
+
transcriptions.append(load_whisper_api('output/chunk_{i}.mp3')['text'])
|
366 |
|
367 |
results = ','.join(transcriptions)
|
368 |
|
|
|
370 |
|
371 |
except Exception as e:
|
372 |
|
373 |
+
st.warning(f'''Whisper API Error: {e},
|
374 |
+
Using Whisper module from GitHub, might take longer than expected''',icon="⚠️")
|
375 |
|
376 |
results = _asr_model.transcribe(st.session_state['audio'], task='transcribe', language='en')
|
377 |
|