Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ def assess_pronunciation(audio_filepath, target_text):
|
|
| 12 |
if not audio_filepath or not target_text:
|
| 13 |
return {"error": "Missing input"}
|
| 14 |
|
|
|
|
| 15 |
try:
|
| 16 |
# 1. Transcribe the audio
|
| 17 |
result = asr_pipe(audio_filepath)
|
|
@@ -19,14 +20,12 @@ def assess_pronunciation(audio_filepath, target_text):
|
|
| 19 |
target_clean = target_text.lower().strip()
|
| 20 |
|
| 21 |
# 2. Calculate Accuracy (String similarity)
|
| 22 |
-
# This acts as a 'Goodness of Pronunciation' proxy
|
| 23 |
accuracy = SequenceMatcher(None, target_clean, student_said).ratio() * 100
|
| 24 |
|
| 25 |
# 3. Calculate Fluency (Words per second)
|
| 26 |
audio, sr = librosa.load(audio_filepath)
|
| 27 |
duration = librosa.get_duration(y=audio, sr=sr)
|
| 28 |
words_count = len(student_said.split())
|
| 29 |
-
# Heuristic: 120 WPM is native fluency
|
| 30 |
fluency = min(100, (words_count / max(duration, 1)) * 40)
|
| 31 |
|
| 32 |
return {
|
|
@@ -38,7 +37,7 @@ def assess_pronunciation(audio_filepath, target_text):
|
|
| 38 |
except Exception as e:
|
| 39 |
return {"error": str(e)}
|
| 40 |
|
| 41 |
-
#
|
| 42 |
interface = gr.Interface(
|
| 43 |
fn=assess_pronunciation,
|
| 44 |
inputs=[gr.Audio(source="upload", type="filepath"), gr.Textbox(label="Target Text")],
|
|
|
|
| 12 |
if not audio_filepath or not target_text:
|
| 13 |
return {"error": "Missing input"}
|
| 14 |
|
| 15 |
+
# --- MAKE SURE THIS 'TRY' IS NOT INDENTED INSIDE THE 'IF' ABOVE ---
|
| 16 |
try:
|
| 17 |
# 1. Transcribe the audio
|
| 18 |
result = asr_pipe(audio_filepath)
|
|
|
|
| 20 |
target_clean = target_text.lower().strip()
|
| 21 |
|
| 22 |
# 2. Calculate Accuracy (String similarity)
|
|
|
|
| 23 |
accuracy = SequenceMatcher(None, target_clean, student_said).ratio() * 100
|
| 24 |
|
| 25 |
# 3. Calculate Fluency (Words per second)
|
| 26 |
audio, sr = librosa.load(audio_filepath)
|
| 27 |
duration = librosa.get_duration(y=audio, sr=sr)
|
| 28 |
words_count = len(student_said.split())
|
|
|
|
| 29 |
fluency = min(100, (words_count / max(duration, 1)) * 40)
|
| 30 |
|
| 31 |
return {
|
|
|
|
| 37 |
except Exception as e:
|
| 38 |
return {"error": str(e)}
|
| 39 |
|
| 40 |
+
# Gradio 3 Interface
|
| 41 |
interface = gr.Interface(
|
| 42 |
fn=assess_pronunciation,
|
| 43 |
inputs=[gr.Audio(source="upload", type="filepath"), gr.Textbox(label="Target Text")],
|