Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,30 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import whisper
|
|
|
|
| 3 |
from transformers import pipeline
|
| 4 |
import spacy
|
| 5 |
from summa import keywords
|
| 6 |
import datetime
|
| 7 |
import os
|
|
|
|
|
|
|
| 8 |
|
| 9 |
@st.cache_resource
|
| 10 |
def load_models():
|
| 11 |
-
|
|
|
|
| 12 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 13 |
nlp = spacy.load("en_core_web_sm")
|
| 14 |
-
return whisper_model, summarizer, nlp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
def extract_action_items(text, nlp):
|
| 17 |
doc = nlp(text)
|
|
@@ -39,30 +52,33 @@ def extract_action_items(text, nlp):
|
|
| 39 |
def main():
|
| 40 |
st.title("🤖 Smart AI Meeting Assistant")
|
| 41 |
|
| 42 |
-
whisper_model, summarizer, nlp = load_models()
|
| 43 |
|
| 44 |
audio_file = st.file_uploader("Upload meeting audio", type=["wav", "mp3", "m4a", "ogg", "flac"])
|
| 45 |
|
| 46 |
if audio_file is not None:
|
| 47 |
file_path = f"uploaded_audio_{datetime.datetime.now().timestamp()}.wav"
|
| 48 |
|
| 49 |
-
# Save uploaded file
|
| 50 |
with open(file_path, "wb") as f:
|
| 51 |
f.write(audio_file.getbuffer())
|
| 52 |
|
| 53 |
st.subheader("Meeting Transcription")
|
| 54 |
with st.spinner("Transcribing audio..."):
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
|
| 61 |
-
result = whisper_model.transcribe(file_path)
|
| 62 |
-
transcript = result["text"]
|
| 63 |
|
| 64 |
st.write(transcript)
|
| 65 |
-
os.remove(file_path)
|
| 66 |
|
| 67 |
st.subheader("Meeting Summary")
|
| 68 |
with st.spinner("Generating summary..."):
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import whisper
|
| 3 |
+
import torch
|
| 4 |
from transformers import pipeline
|
| 5 |
import spacy
|
| 6 |
from summa import keywords
|
| 7 |
import datetime
|
| 8 |
import os
|
| 9 |
+
from pydub import AudioSegment
|
| 10 |
+
import concurrent.futures
|
| 11 |
|
| 12 |
@st.cache_resource
|
| 13 |
def load_models():
|
| 14 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 15 |
+
whisper_model = whisper.load_model("small").to(device) # Using 'small' for faster speed
|
| 16 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 17 |
nlp = spacy.load("en_core_web_sm")
|
| 18 |
+
return whisper_model, summarizer, nlp, device
|
| 19 |
+
|
| 20 |
+
def split_audio(file_path, chunk_length_ms=60000): # 60 seconds per chunk
|
| 21 |
+
audio = AudioSegment.from_file(file_path)
|
| 22 |
+
chunks = [audio[i : i + chunk_length_ms] for i in range(0, len(audio), chunk_length_ms)]
|
| 23 |
+
return chunks
|
| 24 |
+
|
| 25 |
+
def transcribe_chunk(whisper_model, chunk_path, device):
|
| 26 |
+
options = {"fp16": False} if device == "cpu" else {"fp16": True}
|
| 27 |
+
return whisper_model.transcribe(chunk_path, **options)["text"]
|
| 28 |
|
| 29 |
def extract_action_items(text, nlp):
|
| 30 |
doc = nlp(text)
|
|
|
|
| 52 |
def main():
|
| 53 |
st.title("🤖 Smart AI Meeting Assistant")
|
| 54 |
|
| 55 |
+
whisper_model, summarizer, nlp, device = load_models()
|
| 56 |
|
| 57 |
audio_file = st.file_uploader("Upload meeting audio", type=["wav", "mp3", "m4a", "ogg", "flac"])
|
| 58 |
|
| 59 |
if audio_file is not None:
|
| 60 |
file_path = f"uploaded_audio_{datetime.datetime.now().timestamp()}.wav"
|
| 61 |
|
|
|
|
| 62 |
with open(file_path, "wb") as f:
|
| 63 |
f.write(audio_file.getbuffer())
|
| 64 |
|
| 65 |
st.subheader("Meeting Transcription")
|
| 66 |
with st.spinner("Transcribing audio..."):
|
| 67 |
+
chunks = split_audio(file_path)
|
| 68 |
+
chunk_paths = []
|
| 69 |
+
|
| 70 |
+
for i, chunk in enumerate(chunks):
|
| 71 |
+
chunk_path = f"chunk_{i}.wav"
|
| 72 |
+
chunk.export(chunk_path, format="wav")
|
| 73 |
+
chunk_paths.append(chunk_path)
|
| 74 |
+
|
| 75 |
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
| 76 |
+
transcripts = list(executor.map(lambda cp: transcribe_chunk(whisper_model, cp, device), chunk_paths))
|
| 77 |
|
| 78 |
+
transcript = " ".join(transcripts)
|
|
|
|
|
|
|
| 79 |
|
| 80 |
st.write(transcript)
|
| 81 |
+
os.remove(file_path)
|
| 82 |
|
| 83 |
st.subheader("Meeting Summary")
|
| 84 |
with st.spinner("Generating summary..."):
|