jaisun2004 commited on
Commit
a7c706c
Β·
verified Β·
1 Parent(s): 8a2791f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -5
app.py CHANGED
@@ -4,12 +4,16 @@ from transformers import pipeline
4
  from pydub import AudioSegment
5
  import os
6
  import re
 
 
 
 
7
 
8
  # Page config
9
- st.set_page_config(page_title="Atma.ai - Advanced Session Summarizer", layout="wide")
10
 
11
  st.title("🧠 Atma.ai – Advanced Mental Health Session Summarizer")
12
- st.markdown("Upload a therapy session audio file (Tamil-English mix). The app provides a clean transcript with simulated speaker turns, a contextual summary, and emotional analysis.")
13
 
14
  # Upload audio
15
  uploaded_file = st.file_uploader("πŸŽ™οΈ Upload audio file", type=["wav", "mp3", "m4a"])
@@ -24,7 +28,7 @@ if uploaded_file:
24
  audio.export(audio_path, format="wav")
25
 
26
  try:
27
- # Transcribe with explicit language forcing
28
  st.info("πŸ”„ Transcribing with Whisper (mixed-language support)...")
29
  asr = pipeline("automatic-speech-recognition", model="openai/whisper-large")
30
  result = asr(audio_path, return_timestamps=True, generate_kwargs={"language": "<|en|>"})
@@ -33,13 +37,13 @@ if uploaded_file:
33
  if not raw_transcript:
34
  st.error("❌ Could not generate a transcript. Please try a different audio.")
35
  else:
36
- # Simulated Speaker Diarization by sentence splitting
37
  st.info("πŸ—£οΈ Simulating speaker separation...")
38
  sentences = re.split(r'(?<=[.?!])\s+', raw_transcript)
39
  diarized_transcript = ""
40
  for idx, sentence in enumerate(sentences):
41
  speaker = "Speaker 1" if idx % 2 == 0 else "Speaker 2"
42
- diarized_transcript += f"**{speaker}:** {sentence}\n\n"
43
 
44
  # Summarization
45
  st.info("πŸ“‹ Summarizing conversation...")
@@ -66,6 +70,55 @@ if uploaded_file:
66
  st.subheader("πŸ’¬ Emotional Insights (Overall)")
67
  for emo in emotion_scores[0]:
68
  st.write(f"{emo['label']}: {round(emo['score']*100, 2)}%")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  except Exception as err:
70
  st.error(f"❌ Processing failed: {err}")
71
  finally:
 
4
  from pydub import AudioSegment
5
  import os
6
  import re
7
+ from docx import Document
8
+ from docx.shared import Pt
9
+ from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
10
+ from datetime import datetime
11
 
12
  # Page config
13
+ st.set_page_config(page_title="Atma.ai - Session Summarizer + Export", layout="wide")
14
 
15
  st.title("🧠 Atma.ai – Advanced Mental Health Session Summarizer")
16
+ st.markdown("Upload a therapy session audio (Tamil-English mix) to view the transcript, summary, emotional analysis, and export everything to Word!")
17
 
18
  # Upload audio
19
  uploaded_file = st.file_uploader("πŸŽ™οΈ Upload audio file", type=["wav", "mp3", "m4a"])
 
28
  audio.export(audio_path, format="wav")
29
 
30
  try:
31
+ # Transcribe
32
  st.info("πŸ”„ Transcribing with Whisper (mixed-language support)...")
33
  asr = pipeline("automatic-speech-recognition", model="openai/whisper-large")
34
  result = asr(audio_path, return_timestamps=True, generate_kwargs={"language": "<|en|>"})
 
37
  if not raw_transcript:
38
  st.error("❌ Could not generate a transcript. Please try a different audio.")
39
  else:
40
+ # Simulated Speaker Diarization
41
  st.info("πŸ—£οΈ Simulating speaker separation...")
42
  sentences = re.split(r'(?<=[.?!])\s+', raw_transcript)
43
  diarized_transcript = ""
44
  for idx, sentence in enumerate(sentences):
45
  speaker = "Speaker 1" if idx % 2 == 0 else "Speaker 2"
46
+ diarized_transcript += f"{speaker}: {sentence}\n\n"
47
 
48
  # Summarization
49
  st.info("πŸ“‹ Summarizing conversation...")
 
70
  st.subheader("πŸ’¬ Emotional Insights (Overall)")
71
  for emo in emotion_scores[0]:
72
  st.write(f"{emo['label']}: {round(emo['score']*100, 2)}%")
73
+
74
+ # Export Button
75
+ st.subheader("πŸ“₯ Export Session Report")
76
+
77
+ def generate_docx(transcript, summary_text, emotions):
78
+ doc = Document()
79
+
80
+ # Title
81
+ title = doc.add_heading('Session Summary - Atma.ai', 0)
82
+ title.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
83
+
84
+ # Date
85
+ date_paragraph = doc.add_paragraph(f"Date: {datetime.now().strftime('%Y-%m-%d')}")
86
+ date_paragraph.runs[0].italic = True
87
+
88
+ doc.add_paragraph("\n")
89
+
90
+ # Transcript
91
+ doc.add_heading('πŸ“ Transcript', level=1)
92
+ transcript_para = doc.add_paragraph(transcript)
93
+ transcript_para.runs[0].font.size = Pt(12)
94
+
95
+ doc.add_paragraph("\n")
96
+
97
+ # Summary
98
+ doc.add_heading('πŸ“‹ Summary', level=1)
99
+ summary_para = doc.add_paragraph(summary_text)
100
+ summary_para.runs[0].font.size = Pt(12)
101
+
102
+ doc.add_paragraph("\n")
103
+
104
+ # Emotional Insights
105
+ doc.add_heading('πŸ’¬ Emotional Insights', level=1)
106
+ for emo in emotions[0]:
107
+ emotion_para = doc.add_paragraph(f"{emo['label']}: {round(emo['score']*100, 2)}%")
108
+ emotion_para.runs[0].font.size = Pt(12)
109
+
110
+ # Footer
111
+ doc.add_paragraph("\n\n---\nGenerated by Atma.ai – Confidential", style="Intense Quote")
112
+
113
+ output_path = "session_summary.docx"
114
+ doc.save(output_path)
115
+ return output_path
116
+
117
+ if st.button("Generate and Download Report (.docx)"):
118
+ output_file = generate_docx(diarized_transcript, summary[0]["summary_text"], emotion_scores)
119
+ with open(output_file, "rb") as f:
120
+ st.download_button(label="πŸ“₯ Download Report", data=f, file_name="session_summary.docx", mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document")
121
+
122
  except Exception as err:
123
  st.error(f"❌ Processing failed: {err}")
124
  finally: