Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 -
|
9 |
|
10 |
-
st.title("π§ Atma.ai β
|
11 |
-
st.markdown("Upload a
|
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 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|