Update app.py
Browse files
app.py
CHANGED
@@ -520,7 +520,6 @@ def calculate_similarity(text1, text2):
|
|
520 |
matcher = SequenceMatcher(None, clean1, clean2)
|
521 |
return matcher.ratio() * 100
|
522 |
|
523 |
-
# Add this route to your Flask app
|
524 |
@app.route("/evaluate", methods=["POST"])
|
525 |
def evaluate_pronunciation():
|
526 |
if asr_model is None or asr_processor is None:
|
@@ -603,6 +602,7 @@ def evaluate_pronunciation():
|
|
603 |
results = []
|
604 |
best_score = 0
|
605 |
best_reference = None
|
|
|
606 |
|
607 |
for ref_file in reference_files:
|
608 |
try:
|
@@ -635,6 +635,7 @@ def evaluate_pronunciation():
|
|
635 |
if similarity > best_score:
|
636 |
best_score = similarity
|
637 |
best_reference = os.path.basename(ref_file)
|
|
|
638 |
|
639 |
logger.debug(f"📊 Reference '{os.path.basename(ref_file)}': {similarity:.2f}%")
|
640 |
except Exception as e:
|
@@ -647,15 +648,30 @@ def evaluate_pronunciation():
|
|
647 |
except Exception as e:
|
648 |
logger.warning(f"⚠️ Failed to clean up temp files: {str(e)}")
|
649 |
|
650 |
-
#
|
651 |
is_correct = best_score >= 70.0
|
652 |
-
feedback = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
653 |
|
654 |
return jsonify({
|
655 |
"is_correct": is_correct,
|
656 |
"score": best_score,
|
657 |
"feedback": feedback,
|
658 |
-
"
|
|
|
659 |
"reference_locator": reference_locator,
|
660 |
"details": results
|
661 |
})
|
|
|
520 |
matcher = SequenceMatcher(None, clean1, clean2)
|
521 |
return matcher.ratio() * 100
|
522 |
|
|
|
523 |
@app.route("/evaluate", methods=["POST"])
|
524 |
def evaluate_pronunciation():
|
525 |
if asr_model is None or asr_processor is None:
|
|
|
602 |
results = []
|
603 |
best_score = 0
|
604 |
best_reference = None
|
605 |
+
best_transcription = None
|
606 |
|
607 |
for ref_file in reference_files:
|
608 |
try:
|
|
|
635 |
if similarity > best_score:
|
636 |
best_score = similarity
|
637 |
best_reference = os.path.basename(ref_file)
|
638 |
+
best_transcription = ref_transcription
|
639 |
|
640 |
logger.debug(f"📊 Reference '{os.path.basename(ref_file)}': {similarity:.2f}%")
|
641 |
except Exception as e:
|
|
|
648 |
except Exception as e:
|
649 |
logger.warning(f"⚠️ Failed to clean up temp files: {str(e)}")
|
650 |
|
651 |
+
# Enhanced feedback based on score range
|
652 |
is_correct = best_score >= 70.0
|
653 |
+
feedback = ""
|
654 |
+
|
655 |
+
if best_score >= 90.0:
|
656 |
+
feedback = "Perfect pronunciation! Excellent job!"
|
657 |
+
elif best_score >= 80.0:
|
658 |
+
feedback = "Great pronunciation! Your accent is very good."
|
659 |
+
elif best_score >= 70.0:
|
660 |
+
feedback = "Good pronunciation. Keep practicing!"
|
661 |
+
elif best_score >= 50.0:
|
662 |
+
feedback = "Fair attempt. Try focusing on the syllables that differ from the sample."
|
663 |
+
else:
|
664 |
+
feedback = "Try again. Listen carefully to the sample pronunciation."
|
665 |
+
|
666 |
+
# Sort results by score descending
|
667 |
+
results.sort(key=lambda x: x["similarity_score"], reverse=True)
|
668 |
|
669 |
return jsonify({
|
670 |
"is_correct": is_correct,
|
671 |
"score": best_score,
|
672 |
"feedback": feedback,
|
673 |
+
"user_transcription": user_transcription,
|
674 |
+
"best_reference_transcription": best_transcription,
|
675 |
"reference_locator": reference_locator,
|
676 |
"details": results
|
677 |
})
|