norhan12 commited on
Commit
2c08586
·
verified ·
1 Parent(s): bbfad32

Update process_interview.py

Browse files
Files changed (1) hide show
  1. process_interview.py +11 -13
process_interview.py CHANGED
@@ -25,7 +25,7 @@ from reportlab.lib.units import inch
25
  from reportlab.lib import colors
26
  import matplotlib.pyplot as plt
27
  import matplotlib
28
- matplotlib.use('Agg') # --- FIX: تحديد backend لـ matplotlib ---
29
  from reportlab.platypus import Image
30
  import io # --- FIX: إضافة import io لـ BytesIO ---
31
  # --- End Imports for enhanced PDF ---
@@ -273,7 +273,7 @@ def identify_speakers(transcript: Dict, wav_file: str) -> List[Dict]:
273
 
274
  def train_role_classifier(utterances: List[Dict]):
275
  try:
276
- texts = [u['text'] for u in utterances]
277
  vectorizer = TfidfVectorizer(max_features=500, ngram_range=(1, 2))
278
  X_text = vectorizer.fit_transform(texts)
279
 
@@ -779,18 +779,16 @@ def create_pdf_report(analysis_data: Dict, output_path: str, gemini_report_text:
779
 
780
  # --- Charts ---
781
  story.append(Paragraph("Score Visualization:", h3))
782
- chart_path = os.path.join(OUTPUT_DIR, f"anxiety_confidence_{uuid.uuid4().hex[:8]}.png")
783
- # --- FIX: Call generate_anxiety_confidence_chart if it is defined and imports are correct ---
 
784
  try:
785
- # The generate_anxiety_confidence_chart function is now expected to be defined.
786
- # It relies on matplotlib and Image (from reportlab.platypus)
787
- generate_anxiety_confidence_chart(voice_analysis['composite_scores'], chart_path)
788
- if os.path.exists(chart_path):
789
- img = Image(chart_path, width=3.5*inch, height=2.0*inch)
790
- story.append(img)
791
- story.append(Spacer(1, 0.1 * inch))
792
- os.remove(chart_path)
793
- except NameError: # Catch NameError if function is truly not defined
794
  logger.warning("Chart generation function 'generate_anxiety_confidence_chart' is not defined. Skipping chart.")
795
  except Exception as chart_e:
796
  logger.warning(f"Could not add chart image to PDF: {chart_e}. Please check matplotlib installation.")
 
25
  from reportlab.lib import colors
26
  import matplotlib.pyplot as plt
27
  import matplotlib
28
+ matplotlib.use('Agg')
29
  from reportlab.platypus import Image
30
  import io # --- FIX: إضافة import io لـ BytesIO ---
31
  # --- End Imports for enhanced PDF ---
 
273
 
274
  def train_role_classifier(utterances: List[Dict]):
275
  try:
276
+ texts = [u['text'] for u u in utterances]
277
  vectorizer = TfidfVectorizer(max_features=500, ngram_range=(1, 2))
278
  X_text = vectorizer.fit_transform(texts)
279
 
 
779
 
780
  # --- Charts ---
781
  story.append(Paragraph("Score Visualization:", h3))
782
+ # chart_path = os.path.join(OUTPUT_DIR, f"anxiety_confidence_{uuid.uuid4().hex[:8]}.png") # Removed from here
783
+ # --- FIX: Generate chart in memory (BytesIO) ---
784
+ chart_buffer = io.BytesIO() # Create in-memory buffer
785
  try:
786
+ generate_anxiety_confidence_chart(voice_analysis['composite_scores'], chart_buffer) # Pass buffer instead of path
787
+ chart_buffer.seek(0) # Rewind the buffer to the beginning
788
+ img = Image(chart_buffer, width=3.5*inch, height=2.0*inch) # Load image from buffer
789
+ story.append(img)
790
+ story.append(Spacer(1, 0.1 * inch))
791
+ except NameError:
 
 
 
792
  logger.warning("Chart generation function 'generate_anxiety_confidence_chart' is not defined. Skipping chart.")
793
  except Exception as chart_e:
794
  logger.warning(f"Could not add chart image to PDF: {chart_e}. Please check matplotlib installation.")