jaisun2004 commited on
Commit
101c614
Β·
verified Β·
1 Parent(s): 07d82a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -40
app.py CHANGED
@@ -46,21 +46,10 @@ if uploaded_file:
46
  speaker = "Speaker 1" if idx % 2 == 0 else "Speaker 2"
47
  diarized_transcript += f"{speaker}: {sentence}\n\n"
48
 
49
-
50
- # Static Session Context Recall
51
- st.info("πŸ” Loading previous session context...")
52
- past_sessions = [
53
- {"date": "2024-04-15", "coping": "walking", "emotion": "anxiety", "notes": "high workload"},
54
- {"date": "2024-04-22", "coping": "journaling", "emotion": "stress", "notes": "difficulty sleeping"}
55
- ]
56
- rag_context = "\n".join([f"Session {i+1}: {s['coping']}, {s['emotion']}, {s['notes']}" for i, s in enumerate(past_sessions)])
57
-
58
- prompt_input = f"""Previous session context:\n{rag_context}\n\nCurrent session:\n{raw_transcript}"""
59
-
60
  # Summarization
61
  st.info("πŸ“‹ Summarizing conversation...")
62
  summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
63
- summary = summarizer(prompt_input, max_length=256, min_length=60, do_sample=False)
64
 
65
  # Emotion tagging
66
  st.info("🎭 Extracting emotional tones...")
@@ -68,7 +57,7 @@ if uploaded_file:
68
  emotion_scores = emotion_model(raw_transcript)
69
 
70
  # Layout with Tabs
71
- tab1, tab2, tab3, tab4 = st.tabs(["πŸ“ Transcript", "πŸ“‹ Summary", "πŸ’¬ Emotions", "πŸ“ˆ Trends"])
72
 
73
  with tab1:
74
  st.subheader("πŸ“ Speaker-Simulated Transcript")
@@ -76,35 +65,9 @@ tab1, tab2, tab3, tab4 = st.tabs(["πŸ“ Transcript", "πŸ“‹ Summary", "πŸ’¬ Emoti
76
 
77
  with tab2:
78
  st.subheader("πŸ“‹ Contextual Summary")
79
-
80
- # Insight Tracking based on previous sessions
81
- insights = []
82
- if "music" in raw_transcript.lower():
83
- if any("walking" in s["coping"] for s in past_sessions):
84
- insights.append("Patient previously mentioned walking as a helpful coping mechanism. This time, music is highlighted instead.")
85
- if "sleep" in raw_transcript.lower():
86
- insights.append("Sleep continues to be a recurring theme across sessions.")
87
- final_output = f"{summary[0]['summary_text']}\n\nContextual Observations:\n" + "\n".join(insights)
88
- st.write(final_output)
89
-
90
 
91
  with tab3:
92
-
93
- with tab4:
94
- st.subheader("πŸ“ˆ Emotional Trends Over Time")
95
-
96
- session_dates = ["2024-04-01", "2024-04-08", "2024-04-15", "2024-04-22"]
97
- anxiety_scores = [70, 65, 55, 40]
98
- sadness_scores = [30, 20, 25, 15]
99
-
100
- fig, ax = plt.subplots()
101
- ax.plot(session_dates, anxiety_scores, label='Anxiety', marker='o')
102
- ax.plot(session_dates, sadness_scores, label='Sadness', marker='o')
103
- ax.set_title("Emotional Trends Over Time")
104
- ax.set_ylabel("Score (%)")
105
- ax.set_xlabel("Session Date")
106
- ax.legend()
107
- st.pyplot(fig)
108
  st.subheader("πŸ’¬ Emotional Insights (Overall)")
109
  for emo in emotion_scores[0]:
110
  st.write(f"{emo['label']}: {round(emo['score']*100, 2)}%")
@@ -162,3 +125,35 @@ with tab4:
162
  finally:
163
  if os.path.exists(audio_path):
164
  os.remove(audio_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  speaker = "Speaker 1" if idx % 2 == 0 else "Speaker 2"
47
  diarized_transcript += f"{speaker}: {sentence}\n\n"
48
 
 
 
 
 
 
 
 
 
 
 
 
49
  # Summarization
50
  st.info("πŸ“‹ Summarizing conversation...")
51
  summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
52
+ summary = summarizer(raw_transcript, max_length=256, min_length=60, do_sample=False)
53
 
54
  # Emotion tagging
55
  st.info("🎭 Extracting emotional tones...")
 
57
  emotion_scores = emotion_model(raw_transcript)
58
 
59
  # Layout with Tabs
60
+ tab1, tab2, tab3 = st.tabs(["πŸ“ Transcript", "πŸ“‹ Summary", "πŸ’¬ Emotions"])
61
 
62
  with tab1:
63
  st.subheader("πŸ“ Speaker-Simulated Transcript")
 
65
 
66
  with tab2:
67
  st.subheader("πŸ“‹ Contextual Summary")
68
+ st.write(summary[0]["summary_text"])
 
 
 
 
 
 
 
 
 
 
69
 
70
  with tab3:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  st.subheader("πŸ’¬ Emotional Insights (Overall)")
72
  for emo in emotion_scores[0]:
73
  st.write(f"{emo['label']}: {round(emo['score']*100, 2)}%")
 
125
  finally:
126
  if os.path.exists(audio_path):
127
  os.remove(audio_path)
128
+
129
+ # --- Post-processing UI Layout ---
130
+ tab1, tab2, tab3, tab4 = st.tabs(["πŸ“ Transcript", "πŸ“‹ Summary", "πŸ’¬ Emotions", "πŸ“ˆ Trends"])
131
+
132
+ with tab1:
133
+ st.subheader("πŸ“ Transcript")
134
+ st.markdown(diarized_transcript, unsafe_allow_html=True)
135
+
136
+ with tab2:
137
+ st.subheader("πŸ“‹ Contextual Summary")
138
+ st.write(final_output)
139
+
140
+ with tab3:
141
+ st.subheader("πŸ’¬ Emotional Insights (Overall)")
142
+ for emo in emotion_scores[0]:
143
+ st.write(f"{emo['label']}: {round(emo['score']*100, 2)}%")
144
+
145
+ with tab4:
146
+ st.subheader("πŸ“ˆ Emotional Trends Over Time")
147
+
148
+ session_dates = ["2024-04-01", "2024-04-08", "2024-04-15", "2024-04-22"]
149
+ anxiety_scores = [70, 65, 55, 40]
150
+ sadness_scores = [30, 20, 25, 15]
151
+
152
+ fig, ax = plt.subplots()
153
+ ax.plot(session_dates, anxiety_scores, label='Anxiety', marker='o')
154
+ ax.plot(session_dates, sadness_scores, label='Sadness', marker='o')
155
+ ax.set_title("Emotional Trends Over Time")
156
+ ax.set_ylabel("Score (%)")
157
+ ax.set_xlabel("Session Date")
158
+ ax.legend()
159
+ st.pyplot(fig)