Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from pydub import AudioSegment
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
st.title("🧠 Atma.ai – Mental Health Session Summarizer")
|
| 7 |
+
|
| 8 |
+
uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "m4a"])
|
| 9 |
+
|
| 10 |
+
if uploaded_file:
|
| 11 |
+
st.audio(uploaded_file)
|
| 12 |
+
|
| 13 |
+
# Save the uploaded file
|
| 14 |
+
audio_path = "temp_audio.wav"
|
| 15 |
+
audio = AudioSegment.from_file(uploaded_file)
|
| 16 |
+
audio = audio.set_channels(1).set_frame_rate(16000)
|
| 17 |
+
audio.export(audio_path, format="wav")
|
| 18 |
+
|
| 19 |
+
st.write("✅ Audio converted. Starting transcription...")
|
| 20 |
+
|
| 21 |
+
st.spinner("Transcribing with Whisper...")
|
| 22 |
+
asr = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
| 23 |
+
result = asr(audio_path)
|
| 24 |
+
transcript = result["text"]
|
| 25 |
+
|
| 26 |
+
st.subheader("Transcript")
|
| 27 |
+
st.write(transcript)
|
| 28 |
+
|
| 29 |
+
st.subheader("Summary")
|
| 30 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 31 |
+
summary = summarizer(transcript, max_length=200, min_length=40, do_sample=False)
|
| 32 |
+
st.write(summary[0]["summary_text"])
|
| 33 |
+
|
| 34 |
+
os.remove(audio_path) # clean up temp file
|