Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,53 +4,48 @@ from transformers import pipeline
|
|
4 |
from pydub import AudioSegment
|
5 |
import os
|
6 |
|
7 |
-
#
|
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
|
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 |
-
#
|
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
|
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.
|
33 |
|
34 |
-
#
|
35 |
-
st.info("
|
36 |
-
summarizer = pipeline("summarization", model="
|
37 |
-
summary = summarizer(transcript, max_length=
|
38 |
|
39 |
-
st.subheader("
|
40 |
st.write(summary[0]["summary_text"])
|
41 |
|
42 |
# Emotion tagging
|
43 |
-
st.info("
|
44 |
emotion_model = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True)
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
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)
|
|
|
4 |
from pydub import AudioSegment
|
5 |
import os
|
6 |
|
7 |
+
# Page config
|
8 |
+
st.set_page_config(page_title="Atma.ai - Advanced Session Summarizer", layout="centered")
|
9 |
|
10 |
+
st.title("π§ Atma.ai β Advanced Mental Health Session Summarizer")
|
11 |
+
st.markdown("Upload a recorded therapy session to get a structured summary and emotional tone analysis. Now enhanced with dialogue-aware summarization!")
|
12 |
|
13 |
# Upload audio
|
14 |
+
uploaded_file = st.file_uploader("ποΈ Upload audio file", type=["wav", "mp3", "m4a"])
|
15 |
|
16 |
if uploaded_file:
|
17 |
st.audio(uploaded_file)
|
18 |
|
19 |
+
# Convert audio to required format
|
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 with 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.markdown(transcript)
|
33 |
|
34 |
+
# Dialogue-aware summarization using SAMSum-tuned model
|
35 |
+
st.info("π Summarizing conversation contextually...")
|
36 |
+
summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
|
37 |
+
summary = summarizer(transcript, max_length=256, min_length=60, do_sample=False)
|
38 |
|
39 |
+
st.subheader("π Summary")
|
40 |
st.write(summary[0]["summary_text"])
|
41 |
|
42 |
# Emotion tagging
|
43 |
+
st.info("π Extracting emotional tones...")
|
44 |
emotion_model = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True)
|
45 |
+
emotion_scores = emotion_model(transcript)
|
46 |
|
47 |
+
st.subheader("π¬ Emotional Insights (Overall)")
|
48 |
+
for emo in emotion_scores[0]:
|
49 |
+
st.write(f"{emo['label']}: {round(emo['score']*100, 2)}%")
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
os.remove(audio_path)
|