Jiaaaaaaax commited on
Commit
184c6e4
·
verified ·
1 Parent(s): 82ec579

Update session_analysis.py

Browse files
Files changed (1) hide show
  1. session_analysis.py +101 -31
session_analysis.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  import io
 
3
  import pandas as pd
4
  import plotly.express as px
5
  import plotly.graph_objects as go
@@ -57,6 +58,47 @@ def show_upload_section():
57
  else: # Previous Session Data
58
  show_previous_sessions_selector()
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  def process_media_file(file, type):
61
  st.write(f"Processing {type}...")
62
 
@@ -313,38 +355,54 @@ def process_analysis_results(raw_analysis):
313
  }
314
 
315
  def show_analysis_results():
316
- """Display comprehensive analysis results"""
317
  if not st.session_state.analysis_results:
318
  return
319
-
320
- results = st.session_state.analysis_results
321
-
322
- # Top-level metrics
323
- show_mi_metrics_dashboard(results['metrics'])
324
-
325
- # Detailed analysis sections
326
- tabs = st.tabs([
327
- "MI Adherence",
328
- "Technical Skills",
329
- "Client Language",
330
- "Session Flow",
331
- "Recommendations"
332
- ])
333
 
334
- with tabs[0]:
335
- show_mi_adherence_analysis(results)
336
-
337
- with tabs[1]:
338
- show_technical_skills_analysis(results)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
 
340
- with tabs[2]:
341
- show_client_language_analysis(results)
 
 
 
342
 
343
- with tabs[3]:
344
- show_session_flow_analysis(results)
 
 
 
345
 
346
- with tabs[4]:
347
- show_recommendations(results)
 
 
348
 
349
  def show_mi_metrics_dashboard(metrics):
350
  st.subheader("MI Performance Dashboard")
@@ -513,24 +571,36 @@ def save_analysis_results():
513
  st.error(f"Error saving analysis results: {str(e)}")
514
 
515
  def show_upload_section():
516
- st.header("Session Data Upload")
 
517
 
518
  upload_type = st.radio(
519
- "Select Input Method:",
520
- ["Text Transcript", "Session Notes", "Previous Session Data"] # Removed Audio/Video options
521
  )
522
 
523
  if upload_type == "Text Transcript":
524
- file = st.file_uploader("Upload Transcript", type=["txt", "doc", "docx", "json"])
525
  if file:
526
  process_text_file(file)
527
 
 
 
 
 
 
 
 
 
 
 
528
  elif upload_type == "Session Notes":
529
  show_manual_input_form()
530
 
531
- else: # Previous Session Data
532
  show_previous_sessions_selector()
533
 
 
534
  def process_text_file(file):
535
  try:
536
  if file.name.endswith('.json'):
 
1
  import streamlit as st
2
  import io
3
+ from io import BytesIO
4
  import pandas as pd
5
  import plotly.express as px
6
  import plotly.graph_objects as go
 
58
  else: # Previous Session Data
59
  show_previous_sessions_selector()
60
 
61
+ def process_video_file(video_file):
62
+ """Process uploaded video file"""
63
+ try:
64
+ # Save video temporarily
65
+ temp_path = f"temp_video_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
66
+ with open(temp_path, "wb") as f:
67
+ f.write(video_file.getbuffer())
68
+
69
+ st.video(temp_path)
70
+ st.info("Video uploaded successfully. Please note: automatic transcription is not yet implemented. Please provide transcript manually.")
71
+
72
+ # Add manual transcript input
73
+ transcript = st.text_area("Please enter the session transcript:", height=300)
74
+ if transcript:
75
+ st.session_state.current_transcript = transcript
76
+ analyze_session_content(transcript)
77
+
78
+ except Exception as e:
79
+ st.error(f"Error processing video: {str(e)}")
80
+
81
+ def process_audio_file(audio_file):
82
+ """Process uploaded audio file"""
83
+ try:
84
+ # Save audio temporarily
85
+ temp_path = f"temp_audio_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp3"
86
+ with open(temp_path, "wb") as f:
87
+ f.write(audio_file.getbuffer())
88
+
89
+ st.audio(temp_path)
90
+ st.info("Audio uploaded successfully. Please note: automatic transcription is not yet implemented. Please provide transcript manually.")
91
+
92
+ # Add manual transcript input
93
+ transcript = st.text_area("Please enter the session transcript:", height=300)
94
+ if transcript:
95
+ st.session_state.current_transcript = transcript
96
+ analyze_session_content(transcript)
97
+
98
+ except Exception as e:
99
+ st.error(f"Error processing audio: {str(e)}")
100
+
101
+
102
  def process_media_file(file, type):
103
  st.write(f"Processing {type}...")
104
 
 
355
  }
356
 
357
  def show_analysis_results():
358
+ """Display the analysis results in the dashboard"""
359
  if not st.session_state.analysis_results:
360
  return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361
 
362
+ # Use the analysis results directly (they're already parsed)
363
+ analysis = st.session_state.analysis_results
364
+
365
+ # Display MI Adherence Score
366
+ st.subheader("MI Adherence Score")
367
+ score = analysis.get('mi_adherence_score', 0)
368
+ create_gauge_chart(score)
369
+
370
+ # Display Key Themes
371
+ st.subheader("Key Themes")
372
+ themes = analysis.get('key_themes', [])
373
+ if themes:
374
+ for theme in themes:
375
+ st.markdown(f"• {theme}")
376
+
377
+ # Display Technique Usage
378
+ st.subheader("MI Technique Usage")
379
+ technique_usage = analysis.get('technique_usage', {})
380
+ if technique_usage:
381
+ fig = go.Figure(data=[
382
+ go.Bar(x=list(technique_usage.keys()), y=list(technique_usage.values()))
383
+ ])
384
+ fig.update_layout(title="Technique Usage Frequency")
385
+ st.plotly_chart(fig)
386
+
387
+ # Display Strengths and Areas for Improvement
388
+ col1, col2 = st.columns(2)
389
 
390
+ with col1:
391
+ st.subheader("Strengths")
392
+ strengths = analysis.get('strengths', [])
393
+ for strength in strengths:
394
+ st.markdown(f"✓ {strength}")
395
 
396
+ with col2:
397
+ st.subheader("Areas for Improvement")
398
+ improvements = analysis.get('areas_for_improvement', [])
399
+ for improvement in improvements:
400
+ st.markdown(f"△ {improvement}")
401
 
402
+ # Display Session Summary
403
+ st.subheader("Session Summary")
404
+ st.write(analysis.get('session_summary', ''))
405
+
406
 
407
  def show_mi_metrics_dashboard(metrics):
408
  st.subheader("MI Performance Dashboard")
 
571
  st.error(f"Error saving analysis results: {str(e)}")
572
 
573
  def show_upload_section():
574
+ """Display the upload section of the dashboard"""
575
+ st.subheader("Upload Session")
576
 
577
  upload_type = st.radio(
578
+ "Choose input method:",
579
+ ["Text Transcript", "Video Recording", "Audio Recording", "Session Notes", "Previous Sessions"]
580
  )
581
 
582
  if upload_type == "Text Transcript":
583
+ file = st.file_uploader("Upload transcript file", type=['txt', 'doc', 'docx'])
584
  if file:
585
  process_text_file(file)
586
 
587
+ elif upload_type == "Video Recording":
588
+ video_file = st.file_uploader("Upload video file", type=['mp4', 'mov', 'avi'])
589
+ if video_file:
590
+ process_video_file(video_file)
591
+
592
+ elif upload_type == "Audio Recording":
593
+ audio_file = st.file_uploader("Upload audio file", type=['mp3', 'wav', 'm4a'])
594
+ if audio_file:
595
+ process_audio_file(audio_file)
596
+
597
  elif upload_type == "Session Notes":
598
  show_manual_input_form()
599
 
600
+ else:
601
  show_previous_sessions_selector()
602
 
603
+
604
  def process_text_file(file):
605
  try:
606
  if file.name.endswith('.json'):