File size: 2,323 Bytes
ab58fb5 9d727e3 7117743 f3e24b8 b74cc3f ab58fb5 253b4e4 866ffb3 b74cc3f 36688d2 bf628b5 3e7fc84 bf628b5 c274bf0 bf628b5 e3d61f6 bf628b5 3e7fc84 2ea7ea8 3e7fc84 2ea7ea8 3e7fc84 2ea7ea8 253b4e4 c274bf0 e3d61f6 c274bf0 b03d0c5 4ebf6a9 b03d0c5 97c3b7e 3277eaa 2040736 4ebf6a9 2040736 34b0634 2040736 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
import streamlit as st
import whisper
import os
import torch
from transformers import pipeline
from pydub import AudioSegment
def transcribe_audio(audiofile):
st.session_state['audio'] = audiofile
print(f"audio_file_session_state:{st.session_state['audio'] }")
#get size of audio file
audio_size = round(os.path.getsize(st.session_state['audio'])/(1024*1024),1)
print(f"audio file size:{audio_size}")
#determine audio duration
podcast = AudioSegment.from_mp3(st.session_state['audio'])
st.session_state['audio_segment'] = podcast
podcast_duration = podcast.duration_seconds
print(f"Audio Duration: {podcast_duration}")
st.info('Transcribing...')
device = "cuda:0" if torch.cuda.is_available() else "cpu"
pipe = pipeline(
"automatic-speech-recognition",
model="openai/whisper-medium",
chunk_length_s=30,
device=device,
max_new_tokens=60,
)
transcription = pipe(audiofile, batch_size=8)["text"]
st.session_state['transcription'] = transcription
print(f"transcription: {transcription}")
st.info('Done Transcription')
return transcription
def summarize_podcast(audiotranscription):
sum_pipe = pipeline("summarization",model="google/flan-t5-base",clean_up_tokenization_spaces=True)
summarized_text = sum_pipe(audiotranscription,
max_length=1000,
min_length=100,
do_sample=False,
early_stopping=True,
num_beams=4)
summarized_text = ' '.join([summ['summary_text'] for summ in summarized_text])
return summarized_text
st.markdown("# Podcast Q&A")
st.markdown(
"""
This helps understand information-dense podcast episodes by doing the following:
- Speech to Text transcription - using OpenSource Whisper Model
- Summarizes the episode
- Allows you to ask questions and returns direct quotes from the episode.
"""
)
st.audio("marketplace-2023-06-14.mp3")
if st.button("Process Audio File"):
transcribe_audio("marketplace-2023-06-14.mp3")
#audio_file = st.file_uploader("Upload audio copy of file", key="upload", type=['.mp3'])
# if audio_file:
# transcribe_audio(audio_file)
|