norhan12 commited on
Commit
4260dbb
·
verified ·
1 Parent(s): 07683d7

Update process_interview.py

Browse files
Files changed (1) hide show
  1. process_interview.py +9 -6
process_interview.py CHANGED
@@ -116,6 +116,8 @@ def load_speaker_model():
116
  logger.error(f"Model loading failed: {str(e)}")
117
  raise RuntimeError("Could not load speaker verification model")
118
 
 
 
119
  def load_models():
120
  speaker_model = load_speaker_model()
121
  nlp = spacy.load("en_core_web_sm")
@@ -198,9 +200,9 @@ def transcribe(audio_path: str) -> Dict:
198
  elif result['status'] == 'error':
199
  raise Exception(result['error'])
200
  time.sleep(5)
201
- except Exception as e:
202
- logger.error(f"Transcription failed: {str(e)}")
203
- raise
204
 
205
  def process_utterance(utterance: Dict, full_audio: AudioSegment, wav_file: str) -> Dict:
206
  try:
@@ -279,7 +281,7 @@ def train_role_classifier(utterances: List[Dict]):
279
  sum(1 for token in doc if token.pos_ == 'NOUN')
280
  ])
281
  features.append(feat)
282
- labels.append(0 if i % 2 == 0 else 1)
283
  scaler = StandardScaler()
284
  X = scaler.fit_transform(features)
285
  clf = RandomForestClassifier(
@@ -322,7 +324,6 @@ def classify_roles(utterances: List[Dict], clf, vectorizer, scaler):
322
  except Exception as e:
323
  logger.error(f"Role classification failed: {str(e)}")
324
  raise
325
-
326
  def analyze_interviewee_voice(audio_path: str, utterances: List[Dict]) -> Dict:
327
  try:
328
  y, sr = librosa.load(audio_path, sr=16000)
@@ -386,6 +387,8 @@ def analyze_interviewee_voice(audio_path: str, utterances: List[Dict]) -> Dict:
386
  logger.error(f"Voice analysis failed: {str(e)}", exc_info=True)
387
  return {'error': f'Voice analysis incomplete due to audio processing issues: {str(e)}'}
388
 
 
 
389
  def generate_voice_interpretation(analysis: Dict) -> str:
390
  try:
391
  if 'error' in analysis:
@@ -844,7 +847,7 @@ def create_company_pdf_report(analysis_data: Dict, output_path: str, gemini_repo
844
  ['Filler Words', f"{voice_analysis.get('filler_ratio', 0) * 100:.1f}%", 'High usage reduces credibility'],
845
  ['Anxiety', voice_analysis.get('interpretation', {}).get('anxiety_level', 'N/A'), f"Score: {voice_analysis.get('composite_scores'), {}).get('anxiety', 0):.3f}"],
846
  ['Confidence', voice_analysis.get('('interpretation', {}).get('confidence_level'), 'N/A'), f"Score: {voice_analysis.get('('composite_scores', {}).get('confidence', 0):.3f}"],
847
- ['Fluency', voice_analysis.get('interpretation', {}).get('fluency_level', 'N/A'), 'Drives engagement'],
848
  ]
849
  table = Table(table_data, colWidths=[1.5*inch, 1.3*inch, 3.2*inch])
850
  table.setStyle(TableStyle([
 
116
  logger.error(f"Model loading failed: {str(e)}")
117
  raise RuntimeError("Could not load speaker verification model")
118
 
119
+
120
+
121
  def load_models():
122
  speaker_model = load_speaker_model()
123
  nlp = spacy.load("en_core_web_sm")
 
200
  elif result['status'] == 'error':
201
  raise Exception(result['error'])
202
  time.sleep(5)
203
+ except Exception as e:
204
+ logger.error(f"Transcription failed: {str(e)}")
205
+ raise
206
 
207
  def process_utterance(utterance: Dict, full_audio: AudioSegment, wav_file: str) -> Dict:
208
  try:
 
281
  sum(1 for token in doc if token.pos_ == 'NOUN')
282
  ])
283
  features.append(feat)
284
+ labels.append(0 if i % 2 == 0 else 1) # Simplified for demo
285
  scaler = StandardScaler()
286
  X = scaler.fit_transform(features)
287
  clf = RandomForestClassifier(
 
324
  except Exception as e:
325
  logger.error(f"Role classification failed: {str(e)}")
326
  raise
 
327
  def analyze_interviewee_voice(audio_path: str, utterances: List[Dict]) -> Dict:
328
  try:
329
  y, sr = librosa.load(audio_path, sr=16000)
 
387
  logger.error(f"Voice analysis failed: {str(e)}", exc_info=True)
388
  return {'error': f'Voice analysis incomplete due to audio processing issues: {str(e)}'}
389
 
390
+
391
+
392
  def generate_voice_interpretation(analysis: Dict) -> str:
393
  try:
394
  if 'error' in analysis:
 
847
  ['Filler Words', f"{voice_analysis.get('filler_ratio', 0) * 100:.1f}%", 'High usage reduces credibility'],
848
  ['Anxiety', voice_analysis.get('interpretation', {}).get('anxiety_level', 'N/A'), f"Score: {voice_analysis.get('composite_scores'), {}).get('anxiety', 0):.3f}"],
849
  ['Confidence', voice_analysis.get('('interpretation', {}).get('confidence_level'), 'N/A'), f"Score: {voice_analysis.get('('composite_scores', {}).get('confidence', 0):.3f}"],
850
+ ['Fluency', voice_analysis.get('interpretation', {}).get('fluency_level', 'N/A'), 'Drives engagement'),
851
  ]
852
  table = Table(table_data, colWidths=[1.5*inch, 1.3*inch, 3.2*inch])
853
  table.setStyle(TableStyle([