Vadym Myroshnyk commited on
Commit ·
e9e247c
1
Parent(s): 2e5d6b8
save
Browse files
listen_transcribe/listen_transcribe_ui.py
CHANGED
|
@@ -4,7 +4,7 @@ import gradio as gr
|
|
| 4 |
|
| 5 |
from listen_transcribe.audio_files import get_audio_structure
|
| 6 |
from listen_transcribe.dialogue import load_dialogue_lines
|
| 7 |
-
from utils.highlighter import
|
| 8 |
|
| 9 |
|
| 10 |
def transcribe_ui():
|
|
@@ -92,27 +92,6 @@ def transcribe_ui():
|
|
| 92 |
feedback_outputs.append(fb)
|
| 93 |
diff_outputs.append(diff)
|
| 94 |
|
| 95 |
-
def on_check(*user_inputs):
|
| 96 |
-
feedback = []
|
| 97 |
-
highlights = []
|
| 98 |
-
|
| 99 |
-
for user_input, (line_index, _, _) in zip(user_inputs, inputs):
|
| 100 |
-
expected = lines[line_index][1]
|
| 101 |
-
diff_html, score = highlight_fuzzy_diff(user_input, expected)
|
| 102 |
-
|
| 103 |
-
if score > 90:
|
| 104 |
-
emoji, msg, color = "✅", "Excellent!", "#2ecc71"
|
| 105 |
-
elif score > 70:
|
| 106 |
-
emoji, msg, color = "⚠️", "Some mistakes", "#f39c12"
|
| 107 |
-
else:
|
| 108 |
-
emoji, msg, color = "❌", "Try again", "#e74c3c"
|
| 109 |
-
|
| 110 |
-
fb_html = f"<div style='color:{color}; font-size: 14px;'>{emoji} <b>{score}%</b> — {msg}</div>"
|
| 111 |
-
highlights.append(diff_html)
|
| 112 |
-
feedback.append(fb_html)
|
| 113 |
-
|
| 114 |
-
return highlights + feedback
|
| 115 |
-
|
| 116 |
def go_next(*_):
|
| 117 |
return index + 1, []
|
| 118 |
|
|
|
|
| 4 |
|
| 5 |
from listen_transcribe.audio_files import get_audio_structure
|
| 6 |
from listen_transcribe.dialogue import load_dialogue_lines
|
| 7 |
+
from utils.highlighter import on_check
|
| 8 |
|
| 9 |
|
| 10 |
def transcribe_ui():
|
|
|
|
| 92 |
feedback_outputs.append(fb)
|
| 93 |
diff_outputs.append(diff)
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
def go_next(*_):
|
| 96 |
return index + 1, []
|
| 97 |
|
utils/highlighter.py
CHANGED
|
@@ -35,3 +35,25 @@ def highlight_fuzzy_diff(user_text, original_text, threshold=85):
|
|
| 35 |
|
| 36 |
score_percent = round((correct_count / len(original_words)) * 100) if original_words else 0
|
| 37 |
return " ".join(highlighted), score_percent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
score_percent = round((correct_count / len(original_words)) * 100) if original_words else 0
|
| 37 |
return " ".join(highlighted), score_percent
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def on_check(*user_inputs):
|
| 41 |
+
feedback = []
|
| 42 |
+
highlights = []
|
| 43 |
+
|
| 44 |
+
for user_input, (line_index, _, _) in zip(user_inputs, inputs):
|
| 45 |
+
expected = lines[line_index][1]
|
| 46 |
+
diff_html, score = highlight_fuzzy_diff(user_input, expected)
|
| 47 |
+
|
| 48 |
+
if score > 90:
|
| 49 |
+
emoji, msg, color = "✅", "Excellent!", "#2ecc71"
|
| 50 |
+
elif score > 70:
|
| 51 |
+
emoji, msg, color = "⚠️", "Some mistakes", "#f39c12"
|
| 52 |
+
else:
|
| 53 |
+
emoji, msg, color = "❌", "Try again", "#e74c3c"
|
| 54 |
+
|
| 55 |
+
fb_html = f"<div style='color:{color}; font-size: 14px;'>{emoji} <b>{score}%</b> — {msg}</div>"
|
| 56 |
+
highlights.append(diff_html)
|
| 57 |
+
feedback.append(fb_html)
|
| 58 |
+
|
| 59 |
+
return highlights + feedback
|