Spaces:
Sleeping
Sleeping
import streamlit as st | |
import whisper | |
from transformers import pipeline | |
import spacy | |
from summa import keywords | |
import datetime | |
import os | |
def load_models(): | |
whisper_model = whisper.load_model("base") # You can use 'small' or 'medium' for better results | |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
nlp = spacy.load("en_core_web_sm") | |
return whisper_model, summarizer, nlp | |
def extract_action_items(text, nlp): | |
doc = nlp(text) | |
actions = [] | |
for sent in doc.sents: | |
for token in sent: | |
if token.dep_ == "ROOT" and token.pos_ == "VERB": | |
action = { | |
"text": sent.text, | |
"responsible": [], | |
"deadline": [] | |
} | |
for ent in sent.ents: | |
if ent.label_ == "PERSON": | |
action["responsible"].append(ent.text) | |
elif ent.label_ == "DATE": | |
action["deadline"].append(ent.text) | |
actions.append(action) | |
break | |
return actions | |
def main(): | |
st.title("π€ Smart AI Meeting Assistant") | |
whisper_model, summarizer, nlp = load_models() | |
audio_file = st.file_uploader("Upload meeting audio", type=["wav", "mp3", "m4a", "ogg", "flac"]) | |
if audio_file is not None: | |
file_path = f"uploaded_audio_{datetime.datetime.now().timestamp()}.wav" | |
# Save uploaded file | |
with open(file_path, "wb") as f: | |
f.write(audio_file.getbuffer()) | |
st.subheader("Meeting Transcription") | |
with st.spinner("Transcribing audio..."): | |
# Load and process audio | |
audio = whisper.load_audio(file_path) # Converts to 16kHz mono | |
audio = whisper.pad_or_trim(audio) # Ensures proper input size | |
mel = whisper.log_mel_spectrogram(audio).to(whisper_model.device) | |
# Transcribe | |
result = whisper_model.transcribe(file_path) | |
transcript = result["text"] | |
st.write(transcript) | |
os.remove(file_path) # Cleanup | |
st.subheader("Meeting Summary") | |
with st.spinner("Generating summary..."): | |
truncated_text = transcript[:1024] | |
summary = summarizer(truncated_text, max_length=150, min_length=50)[0]['summary_text'] | |
st.write(summary) | |
st.subheader("π Action Items") | |
actions = extract_action_items(transcript, nlp) | |
if not actions: | |
st.write("No action items detected") | |
else: | |
for i, action in enumerate(actions, 1): | |
responsible = ", ".join(action["responsible"]) or "Unassigned" | |
deadline = ", ".join(action["deadline"]) or "No deadline" | |
st.markdown(f""" | |
**Action {i}** | |
- Task: {action["text"]} | |
- Responsible: {responsible} | |
- Deadline: {deadline} | |
""") | |
st.subheader("π Key Terms") | |
key_phrases_result = keywords.keywords(transcript) or "" | |
key_phrases = [kp.strip() for kp in key_phrases_result.split("\n") if kp.strip()] | |
st.write(", ".join(key_phrases) if key_phrases else "No key terms extracted") | |
if __name__ == "__main__": | |
main() | |