jaisun2004 commited on
Commit
29ac338
Β·
verified Β·
1 Parent(s): dd61bc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -44
app.py CHANGED
@@ -60,51 +60,51 @@ if uploaded_file:
60
  prompt_input = f"""Previous session context:\n{rag_context}\n\nCurrent session:\n{raw_transcript}"""
61
  summary = summarizer(prompt_input, max_length=256, min_length=60, do_sample=False)
62
 
63
- # Emotion tagging
64
- st.info("🎭 Extracting emotional tones...")
65
- emotion_model = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True)
66
- emotion_scores = emotion_model(raw_transcript)
67
-
68
- # Layout with Tabs
69
-
70
- with tab1:
71
- st.subheader("πŸ“ Speaker-Simulated Transcript")
72
- st.markdown(diarized_transcript, unsafe_allow_html=True)
73
-
74
- with tab2:
75
- st.subheader("πŸ“‹ Contextual Summary")
76
-
77
- # Insight Tracking based on previous sessions
78
- insights = []
79
- if "music" in raw_transcript.lower():
80
- if any("walking" in s["coping"] for s in past_sessions):
81
- insights.append("Patient previously mentioned walking as a helpful coping mechanism. This time, music is highlighted instead.")
82
- if "sleep" in raw_transcript.lower():
83
- insights.append("Sleep continues to be a recurring theme across sessions.")
84
-
85
- final_output = f"{summary[0]['summary_text']}\n\nContextual Observations:\n" + "\n".join(insights)
86
- st.write(final_output)
87
-
88
- with tab3:
89
- st.subheader("πŸ’¬ Emotional Insights (Overall)")
90
- if 'emotion_scores' in locals():
91
- for emo in emotion_scores[0]:
92
- st.write(f"{emo['label']}: {round(emo['score']*100, 2)}%")
93
- else:
94
- st.write("No emotional data to display.")
95
-
96
- with tab4:
97
- st.subheader("πŸ“ˆ Emotional Trends Over Time")
98
-
99
- session_dates = ["2024-04-01", "2024-04-08", "2024-04-15", "2024-04-22"]
100
- anxiety_scores = [70, 65, 55, 40]
101
- sadness_scores = [30, 20, 25, 15]
102
 
103
- fig = go.Figure()
104
- fig.add_trace(go.Scatter(x=session_dates, y=anxiety_scores, mode='lines+markers', name='Anxiety'))
105
- fig.add_trace(go.Scatter(x=session_dates, y=sadness_scores, mode='lines+markers', name='Sadness'))
106
- fig.update_layout(title='Emotional Trends', xaxis_title='Date', yaxis_title='Score (%)')
107
- st.plotly_chart(fig)
 
 
 
 
 
 
 
108
 
109
  # Export Button
110
  st.subheader("πŸ“₯ Export Session Report")
 
60
  prompt_input = f"""Previous session context:\n{rag_context}\n\nCurrent session:\n{raw_transcript}"""
61
  summary = summarizer(prompt_input, max_length=256, min_length=60, do_sample=False)
62
 
63
+ # Emotion tagging
64
+ st.info("🎭 Extracting emotional tones...")
65
+ emotion_model = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True)
66
+ emotion_scores = emotion_model(raw_transcript)
67
+
68
+ # Layout with Tabs
69
+
70
+ with tab1:
71
+ st.subheader("πŸ“ Speaker-Simulated Transcript")
72
+ st.markdown(diarized_transcript, unsafe_allow_html=True)
73
+
74
+ with tab2:
75
+ st.subheader("πŸ“‹ Contextual Summary")
76
+
77
+ # Insight Tracking based on previous sessions
78
+ insights = []
79
+ if "music" in raw_transcript.lower():
80
+ if any("walking" in s["coping"] for s in past_sessions):
81
+ insights.append("Patient previously mentioned walking as a helpful coping mechanism. This time, music is highlighted instead.")
82
+ if "sleep" in raw_transcript.lower():
83
+ insights.append("Sleep continues to be a recurring theme across sessions.")
84
+
85
+ final_output = f"{summary[0]['summary_text']}\n\nContextual Observations:\n" + "\n".join(insights)
86
+ st.write(final_output)
87
+
88
+ with tab3:
89
+ st.subheader("πŸ’¬ Emotional Insights (Overall)")
90
+ if 'emotion_scores' in locals():
91
+ for emo in emotion_scores[0]:
92
+ st.write(f"{emo['label']}: {round(emo['score']*100, 2)}%")
93
+ else:
94
+ st.write("No emotional data to display.")
 
 
 
 
 
 
 
95
 
96
+ with tab4:
97
+ st.subheader("πŸ“ˆ Emotional Trends Over Time")
98
+
99
+ session_dates = ["2024-04-01", "2024-04-08", "2024-04-15", "2024-04-22"]
100
+ anxiety_scores = [70, 65, 55, 40]
101
+ sadness_scores = [30, 20, 25, 15]
102
+
103
+ fig = go.Figure()
104
+ fig.add_trace(go.Scatter(x=session_dates, y=anxiety_scores, mode='lines+markers', name='Anxiety'))
105
+ fig.add_trace(go.Scatter(x=session_dates, y=sadness_scores, mode='lines+markers', name='Sadness'))
106
+ fig.update_layout(title='Emotional Trends', xaxis_title='Date', yaxis_title='Score (%)')
107
+ st.plotly_chart(fig)
108
 
109
  # Export Button
110
  st.subheader("πŸ“₯ Export Session Report")