sparshmehta commited on
Commit
ea95820
·
verified ·
1 Parent(s): 94f01e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -1
app.py CHANGED
@@ -202,10 +202,33 @@ class AudioFeatureExtractor:
202
  # Calculate monotone score (0-1, higher means more monotone)
203
  monotone_score = 0.0
204
  if pitch_mean > 0:
 
205
  variation_factor = min(1.0, max(0.0, (15 - pitch_variation_coeff) / 15))
206
  range_factor = min(1.0, max(0.0, (30 - (pitch_range / pitch_mean * 100)) / 30))
207
  changes_factor = min(1.0, max(0.0, (100 - changes_per_minute) / 100))
208
- monotone_score = (variation_factor + range_factor + changes_factor) / 3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
 
210
  # Improved pause detection
211
  S = np.abs(librosa.stft(audio))
@@ -425,6 +448,55 @@ class ContentAnalyzer:
425
  logger.error(f"Missing Score or Citations in {category}.{subcategory}")
426
  raise ValueError(f"Missing Score or Citations in {category}.{subcategory}")
427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428
  return result
429
 
430
  except json.JSONDecodeError as json_error:
 
202
  # Calculate monotone score (0-1, higher means more monotone)
203
  monotone_score = 0.0
204
  if pitch_mean > 0:
205
+ # Normalize each factor to 0-1 range where higher values indicate more monotone speech
206
  variation_factor = min(1.0, max(0.0, (15 - pitch_variation_coeff) / 15))
207
  range_factor = min(1.0, max(0.0, (30 - (pitch_range / pitch_mean * 100)) / 30))
208
  changes_factor = min(1.0, max(0.0, (100 - changes_per_minute) / 100))
209
+
210
+ # Weight the factors (can adjust weights if needed)
211
+ variation_weight = 0.4
212
+ range_weight = 0.3
213
+ changes_weight = 0.3
214
+
215
+ # Calculate weighted average
216
+ monotone_score = (
217
+ variation_factor * variation_weight +
218
+ range_factor * range_weight +
219
+ changes_factor * changes_weight
220
+ )
221
+
222
+ # Add debug logging
223
+ logger.info(f"""Monotone score calculation:
224
+ Pitch variation coeff: {pitch_variation_coeff:.2f}
225
+ Pitch range ratio: {(pitch_range / pitch_mean * 100):.2f}%
226
+ Changes per minute: {changes_per_minute:.2f}
227
+ Variation factor: {variation_factor:.2f}
228
+ Range factor: {range_factor:.2f}
229
+ Changes factor: {changes_factor:.2f}
230
+ Final score: {monotone_score:.2f}
231
+ """)
232
 
233
  # Improved pause detection
234
  S = np.abs(librosa.stft(audio))
 
448
  logger.error(f"Missing Score or Citations in {category}.{subcategory}")
449
  raise ValueError(f"Missing Score or Citations in {category}.{subcategory}")
450
 
451
+ # Add validation for citations
452
+ def validate_citations(citations: List[str]) -> bool:
453
+ if not citations:
454
+ return False
455
+
456
+ for citation in citations:
457
+ # Check for timestamp format [MM:SS]
458
+ if not re.search(r'\[\d{2}:\d{2}\]', citation):
459
+ return False
460
+ # Check for meaningful content (at least 10 words)
461
+ content = re.sub(r'\[\d{2}:\d{2}\]', '', citation).strip()
462
+ if len(content.split()) < 10:
463
+ return False
464
+ return True
465
+
466
+ # Add validation for each category score
467
+ result = json.loads(result_text)
468
+ for category in ["Concept Assessment", "Code Assessment"]:
469
+ if category in result:
470
+ for subcategory, details in result[category].items():
471
+ # Validate citations first
472
+ if not validate_citations(details.get("Citations", [])):
473
+ details["Score"] = 0 # Force score to 0 if citations are invalid
474
+ details["Citations"].append("[00:00] Invalid or insufficient citation format. Requires specific examples with timestamps.")
475
+
476
+ # Additional validation based on subcategory
477
+ if subcategory == "Examples and Business Context":
478
+ # Count actual examples in citations
479
+ example_count = sum(1 for citation in details.get("Citations", [])
480
+ if "example" in citation.lower() or "case" in citation.lower())
481
+ if example_count < 2:
482
+ details["Score"] = 0
483
+ details["Citations"].append("[00:00] Insufficient number of concrete examples. At least 2 required.")
484
+
485
+ elif subcategory == "Engagement and Interaction":
486
+ # Count engagement points
487
+ engagement_count = sum(1 for citation in details.get("Citations", [])
488
+ if any(word in citation.lower() for word in ["question", "ask", "interact", "engage"]))
489
+ if engagement_count < 3:
490
+ details["Score"] = 0
491
+ details["Citations"].append("[00:00] Insufficient engagement points. At least 3 required.")
492
+
493
+ # Validate professional tone
494
+ elif subcategory == "Professional Tone":
495
+ unprofessional_indicators = ["um", "uh", "like", "you know", "stuff", "things"]
496
+ if any(indicator in ' '.join(details.get("Citations", [])).lower() for indicator in unprofessional_indicators):
497
+ details["Score"] = 0
498
+ details["Citations"].append("[00:00] Unprofessional language detected. Maintain formal teaching tone.")
499
+
500
  return result
501
 
502
  except json.JSONDecodeError as json_error: