Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,56 @@
|
|
|
|
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 |
-
|
|
|
9 |
|
10 |
if uploaded_file:
|
11 |
st.audio(uploaded_file)
|
12 |
-
|
13 |
-
# Save
|
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 |
-
|
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 |
-
|
|
|
30 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
31 |
-
summary = summarizer(transcript, max_length=
|
|
|
|
|
32 |
st.write(summary[0]["summary_text"])
|
33 |
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
import streamlit as st
|
3 |
from transformers import pipeline
|
4 |
from pydub import AudioSegment
|
5 |
import os
|
6 |
|
7 |
+
# Set Streamlit page config
|
8 |
+
st.set_page_config(page_title="Atma.ai - Session Summarizer", layout="centered")
|
9 |
+
|
10 |
st.title("π§ Atma.ai β Mental Health Session Summarizer")
|
11 |
+
st.markdown("Upload a therapy session audio file to get a transcript, summary, and emotional insights.")
|
12 |
|
13 |
+
# Upload audio
|
14 |
+
uploaded_file = st.file_uploader("ποΈ Upload audio", type=["wav", "mp3", "m4a"])
|
15 |
|
16 |
if uploaded_file:
|
17 |
st.audio(uploaded_file)
|
18 |
+
|
19 |
+
# Save and convert audio
|
20 |
audio_path = "temp_audio.wav"
|
21 |
audio = AudioSegment.from_file(uploaded_file)
|
22 |
audio = audio.set_channels(1).set_frame_rate(16000)
|
23 |
audio.export(audio_path, format="wav")
|
24 |
|
25 |
+
# Transcribe
|
26 |
+
st.info("Transcribing audio using Whisper...")
|
|
|
27 |
asr = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
28 |
+
result = asr(audio_path, return_timestamps=True)
|
29 |
transcript = result["text"]
|
30 |
|
31 |
+
st.subheader("π Transcript")
|
32 |
st.write(transcript)
|
33 |
|
34 |
+
# Summarize
|
35 |
+
st.info("Generating summary...")
|
36 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
37 |
+
summary = summarizer(transcript, max_length=250, min_length=50, do_sample=False)
|
38 |
+
|
39 |
+
st.subheader("π Summary")
|
40 |
st.write(summary[0]["summary_text"])
|
41 |
|
42 |
+
# Emotion tagging
|
43 |
+
st.info("Analyzing emotional tone...")
|
44 |
+
emotion_model = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True)
|
45 |
+
emotion_results = emotion_model(transcript)
|
46 |
+
|
47 |
+
# Aggregate emotions
|
48 |
+
avg_scores = {}
|
49 |
+
for result in emotion_results[0]:
|
50 |
+
avg_scores[result['label']] = round(result['score'] * 100, 2)
|
51 |
+
|
52 |
+
st.subheader("π¬ Emotional Insights")
|
53 |
+
for emotion, score in avg_scores.items():
|
54 |
+
st.write(f"{emotion}: {score}%")
|
55 |
+
|
56 |
+
os.remove(audio_path)
|