jaisun2004 commited on
Commit
abc0e8f
Β·
verified Β·
1 Parent(s): 644d52a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -23
app.py CHANGED
@@ -4,53 +4,48 @@ 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)
 
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)