Spaces:
Sleeping
Sleeping
| def compute_quality_score(issues): | |
| """ | |
| Compute the weighted quality score based on detected issues. | |
| Logic is identical to your original implementation. | |
| """ | |
| # Count severities | |
| critical = sum(1 for _, sev, _ in issues if sev == "CRITICAL") | |
| high = sum(1 for _, sev, _ in issues if sev == "HIGH") | |
| medium = sum(1 for _, sev, _ in issues if sev == "MEDIUM") | |
| low = sum(1 for _, sev, _ in issues if sev == "LOW") | |
| # ============================================ | |
| # Weighted scoring | |
| # ============================================ | |
| score = 100 | |
| score -= critical * 35 | |
| score -= high * 20 | |
| score -= medium * 8 | |
| score -= low * 3 | |
| # Heavy processing penalties | |
| if len(issues) >= 6: | |
| score -= 10 | |
| if (critical + high) >= 3: | |
| score -= 10 | |
| # Clean bonus | |
| if len(issues) == 0: | |
| score += 5 | |
| score = max(0, min(score, 100)) | |
| # ============================================ | |
| # Grade Mapping | |
| # ============================================ | |
| if score >= 90: | |
| grade = "A" | |
| quality = "EXCELLENT" | |
| color = "#00C853" | |
| recommendation = "Excellent for TTS dataset" | |
| elif score >= 75: | |
| grade = "B" | |
| quality = "GOOD" | |
| color = "#64DD17" | |
| recommendation = "Very good quality; suitable for TTS" | |
| elif score >= 60: | |
| grade = "C" | |
| quality = "FAIR" | |
| color = "#FFD600" | |
| recommendation = "Usable but may contain processing artifacts" | |
| elif score >= 40: | |
| grade = "D" | |
| quality = "POOR" | |
| color = "#FF6D00" | |
| recommendation = "Not recommended for TTS (heavy processing)" | |
| else: | |
| grade = "F" | |
| quality = "CRITICAL" | |
| color = "#D50000" | |
| recommendation = "Severely degraded or processed; avoid for TTS" | |
| # ============================================ | |
| # Cleanliness + Processing Index | |
| # ============================================ | |
| cleanliness_score = max(0, 100 - (medium * 5 + low * 3)) | |
| processing_severity = (critical * 3) + (high * 2) + medium | |
| return { | |
| "score": score, | |
| "grade": grade, | |
| "quality": quality, | |
| "color": color, | |
| "recommendation": recommendation, | |
| "cleanliness_score": cleanliness_score, | |
| "processing_severity": processing_severity, | |
| "critical": critical, | |
| "high": high, | |
| "medium": medium, | |
| "low": low | |
| } | |