Spaces:
Sleeping
Sleeping
Update scoring.py
Browse files- scoring.py +89 -0
scoring.py
CHANGED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def compute_quality_score(issues):
|
| 2 |
+
"""
|
| 3 |
+
Compute the weighted quality score based on detected issues.
|
| 4 |
+
Logic is identical to your original implementation.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
# Count severities
|
| 8 |
+
critical = sum(1 for _, sev, _ in issues if sev == "CRITICAL")
|
| 9 |
+
high = sum(1 for _, sev, _ in issues if sev == "HIGH")
|
| 10 |
+
medium = sum(1 for _, sev, _ in issues if sev == "MEDIUM")
|
| 11 |
+
low = sum(1 for _, sev, _ in issues if sev == "LOW")
|
| 12 |
+
|
| 13 |
+
# ============================================
|
| 14 |
+
# Weighted scoring
|
| 15 |
+
# ============================================
|
| 16 |
+
|
| 17 |
+
score = 100
|
| 18 |
+
score -= critical * 35
|
| 19 |
+
score -= high * 20
|
| 20 |
+
score -= medium * 8
|
| 21 |
+
score -= low * 3
|
| 22 |
+
|
| 23 |
+
# Heavy processing penalties
|
| 24 |
+
if len(issues) >= 6:
|
| 25 |
+
score -= 10
|
| 26 |
+
|
| 27 |
+
if (critical + high) >= 3:
|
| 28 |
+
score -= 10
|
| 29 |
+
|
| 30 |
+
# Clean bonus
|
| 31 |
+
if len(issues) == 0:
|
| 32 |
+
score += 5
|
| 33 |
+
|
| 34 |
+
score = max(0, min(score, 100))
|
| 35 |
+
|
| 36 |
+
# ============================================
|
| 37 |
+
# Grade Mapping
|
| 38 |
+
# ============================================
|
| 39 |
+
|
| 40 |
+
if score >= 90:
|
| 41 |
+
grade = "A"
|
| 42 |
+
quality = "EXCELLENT"
|
| 43 |
+
color = "#00C853"
|
| 44 |
+
recommendation = "Excellent for TTS dataset"
|
| 45 |
+
|
| 46 |
+
elif score >= 75:
|
| 47 |
+
grade = "B"
|
| 48 |
+
quality = "GOOD"
|
| 49 |
+
color = "#64DD17"
|
| 50 |
+
recommendation = "Very good quality; suitable for TTS"
|
| 51 |
+
|
| 52 |
+
elif score >= 60:
|
| 53 |
+
grade = "C"
|
| 54 |
+
quality = "FAIR"
|
| 55 |
+
color = "#FFD600"
|
| 56 |
+
recommendation = "Usable but may contain processing artifacts"
|
| 57 |
+
|
| 58 |
+
elif score >= 40:
|
| 59 |
+
grade = "D"
|
| 60 |
+
quality = "POOR"
|
| 61 |
+
color = "#FF6D00"
|
| 62 |
+
recommendation = "Not recommended for TTS (heavy processing)"
|
| 63 |
+
|
| 64 |
+
else:
|
| 65 |
+
grade = "F"
|
| 66 |
+
quality = "CRITICAL"
|
| 67 |
+
color = "#D50000"
|
| 68 |
+
recommendation = "Severely degraded or processed; avoid for TTS"
|
| 69 |
+
|
| 70 |
+
# ============================================
|
| 71 |
+
# Cleanliness + Processing Index
|
| 72 |
+
# ============================================
|
| 73 |
+
|
| 74 |
+
cleanliness_score = max(0, 100 - (medium * 5 + low * 3))
|
| 75 |
+
processing_severity = (critical * 3) + (high * 2) + medium
|
| 76 |
+
|
| 77 |
+
return {
|
| 78 |
+
"score": score,
|
| 79 |
+
"grade": grade,
|
| 80 |
+
"quality": quality,
|
| 81 |
+
"color": color,
|
| 82 |
+
"recommendation": recommendation,
|
| 83 |
+
"cleanliness_score": cleanliness_score,
|
| 84 |
+
"processing_severity": processing_severity,
|
| 85 |
+
"critical": critical,
|
| 86 |
+
"high": high,
|
| 87 |
+
"medium": medium,
|
| 88 |
+
"low": low
|
| 89 |
+
}
|