Spaces:
Sleeping
Sleeping
Delete test_all_samples.py
Browse files- test_all_samples.py +0 -139
test_all_samples.py
DELETED
|
@@ -1,139 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Test all samples with the enhanced Kopparapu scoring
|
| 3 |
-
"""
|
| 4 |
-
import os
|
| 5 |
-
import sys
|
| 6 |
-
from pipeline import AuthenticityDetectionPipeline
|
| 7 |
-
|
| 8 |
-
def test_all_samples():
|
| 9 |
-
print("=" * 70)
|
| 10 |
-
print("TESTING ALL SAMPLES WITH ENHANCED KOPPARAPU SCORING")
|
| 11 |
-
print("=" * 70)
|
| 12 |
-
|
| 13 |
-
# Initialize pipeline
|
| 14 |
-
pipeline = AuthenticityDetectionPipeline(whisper_model_size="base")
|
| 15 |
-
|
| 16 |
-
# Sample directories
|
| 17 |
-
samples_dir = "/Users/ranamhamoud/Downloads/apis/samples_wav"
|
| 18 |
-
|
| 19 |
-
# Collect results
|
| 20 |
-
results = {
|
| 21 |
-
'read': [],
|
| 22 |
-
'spontaneous': []
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
# Test read samples
|
| 26 |
-
print("\n" + "=" * 70)
|
| 27 |
-
print("READ SPEECH SAMPLES")
|
| 28 |
-
print("=" * 70)
|
| 29 |
-
|
| 30 |
-
for i in range(1, 11):
|
| 31 |
-
filepath = os.path.join(samples_dir, f"read{i}.wav")
|
| 32 |
-
if os.path.exists(filepath):
|
| 33 |
-
print(f"\n--- Testing read{i}.wav ---")
|
| 34 |
-
try:
|
| 35 |
-
result = pipeline.analyze_audio(filepath)
|
| 36 |
-
score = result['final_assessment']['composite_authenticity_score']
|
| 37 |
-
verdict = result['final_assessment']['verdict']
|
| 38 |
-
kop_score = result['speech_recognition']['kopparapu_score']
|
| 39 |
-
kop_class = result['speech_recognition']['kopparapu_classification']
|
| 40 |
-
|
| 41 |
-
results['read'].append({
|
| 42 |
-
'name': f'R{i}',
|
| 43 |
-
'composite': score,
|
| 44 |
-
'kopparapu': kop_score,
|
| 45 |
-
'verdict': verdict
|
| 46 |
-
})
|
| 47 |
-
|
| 48 |
-
print(f" Composite Score: {score:.3f}")
|
| 49 |
-
print(f" Kopparapu Score: {kop_score:.3f} ({kop_class})")
|
| 50 |
-
print(f" Verdict: {verdict}")
|
| 51 |
-
except Exception as e:
|
| 52 |
-
print(f" ERROR: {e}")
|
| 53 |
-
|
| 54 |
-
# Test spontaneous samples
|
| 55 |
-
print("\n" + "=" * 70)
|
| 56 |
-
print("SPONTANEOUS SPEECH SAMPLES")
|
| 57 |
-
print("=" * 70)
|
| 58 |
-
|
| 59 |
-
for i in range(1, 11):
|
| 60 |
-
filepath = os.path.join(samples_dir, f"spontaneous{i}.wav")
|
| 61 |
-
if os.path.exists(filepath):
|
| 62 |
-
print(f"\n--- Testing spontaneous{i}.wav ---")
|
| 63 |
-
try:
|
| 64 |
-
result = pipeline.analyze_audio(filepath)
|
| 65 |
-
score = result['final_assessment']['composite_authenticity_score']
|
| 66 |
-
verdict = result['final_assessment']['verdict']
|
| 67 |
-
kop_score = result['speech_recognition']['kopparapu_score']
|
| 68 |
-
kop_class = result['speech_recognition']['kopparapu_classification']
|
| 69 |
-
|
| 70 |
-
results['spontaneous'].append({
|
| 71 |
-
'name': f'S{i}',
|
| 72 |
-
'composite': score,
|
| 73 |
-
'kopparapu': kop_score,
|
| 74 |
-
'verdict': verdict
|
| 75 |
-
})
|
| 76 |
-
|
| 77 |
-
print(f" Composite Score: {score:.3f}")
|
| 78 |
-
print(f" Kopparapu Score: {kop_score:.3f} ({kop_class})")
|
| 79 |
-
print(f" Verdict: {verdict}")
|
| 80 |
-
except Exception as e:
|
| 81 |
-
print(f" ERROR: {e}")
|
| 82 |
-
|
| 83 |
-
# Summary
|
| 84 |
-
print("\n" + "=" * 70)
|
| 85 |
-
print("SUMMARY")
|
| 86 |
-
print("=" * 70)
|
| 87 |
-
|
| 88 |
-
print("\n### READ SAMPLES (should be detected as inauthentic, score < 0.3)")
|
| 89 |
-
print("-" * 50)
|
| 90 |
-
print(f"{'Sample':<8} {'Composite':<12} {'Kopparapu':<12} {'Verdict':<20}")
|
| 91 |
-
print("-" * 50)
|
| 92 |
-
|
| 93 |
-
read_correct = 0
|
| 94 |
-
for r in results['read']:
|
| 95 |
-
correct = "✓" if r['composite'] < 0.3 else "✗"
|
| 96 |
-
if r['composite'] < 0.3:
|
| 97 |
-
read_correct += 1
|
| 98 |
-
print(f"{r['name']:<8} {r['composite']:<12.3f} {r['kopparapu']:<12.3f} {r['verdict']:<20} {correct}")
|
| 99 |
-
|
| 100 |
-
print("\n### SPONTANEOUS SAMPLES (should be detected as authentic, score >= 0.3)")
|
| 101 |
-
print("-" * 50)
|
| 102 |
-
print(f"{'Sample':<8} {'Composite':<12} {'Kopparapu':<12} {'Verdict':<20}")
|
| 103 |
-
print("-" * 50)
|
| 104 |
-
|
| 105 |
-
spont_correct = 0
|
| 106 |
-
for r in results['spontaneous']:
|
| 107 |
-
correct = "✓" if r['composite'] >= 0.3 else "✗"
|
| 108 |
-
if r['composite'] >= 0.3:
|
| 109 |
-
spont_correct += 1
|
| 110 |
-
print(f"{r['name']:<8} {r['composite']:<12.3f} {r['kopparapu']:<12.3f} {r['verdict']:<20} {correct}")
|
| 111 |
-
|
| 112 |
-
# Accuracy metrics
|
| 113 |
-
print("\n" + "=" * 70)
|
| 114 |
-
print("ACCURACY METRICS")
|
| 115 |
-
print("=" * 70)
|
| 116 |
-
|
| 117 |
-
total_read = len(results['read'])
|
| 118 |
-
total_spont = len(results['spontaneous'])
|
| 119 |
-
|
| 120 |
-
read_acc = (read_correct / total_read * 100) if total_read > 0 else 0
|
| 121 |
-
spont_acc = (spont_correct / total_spont * 100) if total_spont > 0 else 0
|
| 122 |
-
overall_acc = ((read_correct + spont_correct) / (total_read + total_spont) * 100) if (total_read + total_spont) > 0 else 0
|
| 123 |
-
|
| 124 |
-
print(f"\nRead Detection: {read_correct}/{total_read} = {read_acc:.1f}%")
|
| 125 |
-
print(f"Spontaneous Detection: {spont_correct}/{total_spont} = {spont_acc:.1f}%")
|
| 126 |
-
print(f"Overall Accuracy: {read_correct + spont_correct}/{total_read + total_spont} = {overall_acc:.1f}%")
|
| 127 |
-
|
| 128 |
-
# Kopparapu-specific accuracy
|
| 129 |
-
print("\n### Kopparapu Score Analysis")
|
| 130 |
-
read_kop_correct = sum(1 for r in results['read'] if r['kopparapu'] >= 0.5)
|
| 131 |
-
spont_kop_correct = sum(1 for r in results['spontaneous'] if r['kopparapu'] < 0.5)
|
| 132 |
-
|
| 133 |
-
print(f"Read (Kopparapu >= 0.5): {read_kop_correct}/{total_read}")
|
| 134 |
-
print(f"Spontaneous (Kopparapu < 0.5): {spont_kop_correct}/{total_spont}")
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
if __name__ == "__main__":
|
| 138 |
-
test_all_samples()
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|