jaisun2004 commited on
Commit
21c5c47
Β·
verified Β·
1 Parent(s): abc0e8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -30
app.py CHANGED
@@ -5,10 +5,10 @@ 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"])
@@ -22,30 +22,41 @@ if 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)
 
 
 
 
 
 
 
 
 
 
 
 
5
  import os
6
 
7
  # Page config
8
+ st.set_page_config(page_title="Atma.ai - Mixed Language Session Summarizer", layout="centered")
9
 
10
+ st.title("🧠 Atma.ai – Mixed Language Session Summarizer")
11
+ st.markdown("Upload a therapy session audio file in Tamil-English mix to get a clean transcript, contextual summary, and emotional analysis.")
12
 
13
  # Upload audio
14
  uploaded_file = st.file_uploader("πŸŽ™οΈ Upload audio file", type=["wav", "mp3", "m4a"])
 
22
  audio = audio.set_channels(1).set_frame_rate(16000)
23
  audio.export(audio_path, format="wav")
24
 
25
+ # Transcribe with explicit language forcing
26
+ st.info("πŸ”„ Transcribing with Whisper (mixed-language support)...")
27
+ try:
28
+ asr = pipeline("automatic-speech-recognition", model="openai/whisper-large")
29
+ result = asr(audio_path, return_timestamps=True, generate_kwargs={"language": "<|en|>"})
30
+ transcript = result.get("text", "")
31
+
32
+ if not transcript:
33
+ st.error("❌ Could not generate a transcript. Please try a different audio.")
34
+ else:
35
+ st.subheader("πŸ“ Transcript")
36
+ st.markdown(transcript)
37
+
38
+ # Summarize
39
+ st.info("πŸ“‹ Summarizing conversation...")
40
+ summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
41
+ try:
42
+ summary = summarizer(transcript, max_length=256, min_length=60, do_sample=False)
43
+ st.subheader("πŸ“Œ Summary")
44
+ st.write(summary[0]["summary_text"])
45
+ except Exception as e:
46
+ st.error(f"⚠️ Could not summarize: {e}")
47
+
48
+ # Emotion tagging
49
+ st.info("🎭 Extracting emotional tones...")
50
+ try:
51
+ emotion_model = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True)
52
+ emotion_scores = emotion_model(transcript)
53
+ st.subheader("πŸ’¬ Emotional Insights (Overall)")
54
+ for emo in emotion_scores[0]:
55
+ st.write(f"{emo['label']}: {round(emo['score']*100, 2)}%")
56
+ except Exception as e:
57
+ st.warning(f"⚠️ Emotion detection skipped due to error: {e}")
58
+ except Exception as err:
59
+ st.error(f"❌ Transcription failed: {err}")
60
+ finally:
61
+ if os.path.exists(audio_path):
62
+ os.remove(audio_path)