Spaces:
Sleeping
Sleeping
Working prototype
Browse files
app.py
CHANGED
@@ -14,27 +14,26 @@ def highlight_errors(ground_truth, hypothesis):
|
|
14 |
gt_index = 0
|
15 |
hyp_index = 0
|
16 |
|
17 |
-
# Process each
|
18 |
-
for
|
19 |
-
for
|
20 |
-
|
|
|
21 |
# Add equal words without highlighting
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
elif alignment.type == 'insert':
|
27 |
# Highlight inserted words in green
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
highlighted_hyp.append(f'<span style="color:
|
34 |
-
highlighted_hyp.append(f'<span style="color:red; text-decoration:line-through;">{gt_words[gt_index]}</span>')
|
35 |
gt_index += 1
|
36 |
hyp_index += 1
|
37 |
-
elif
|
38 |
# Highlight deleted words in red with strikethrough
|
39 |
highlighted_hyp.append(f'<span style="color:red; text-decoration:line-through;">{gt_words[gt_index]}</span>')
|
40 |
gt_index += 1
|
@@ -73,13 +72,13 @@ interface = gr.Interface(
|
|
73 |
fn=highlight_errors,
|
74 |
inputs=["text", "text"],
|
75 |
outputs=[
|
76 |
-
gr.
|
77 |
gr.Number(label="Word Error Rate"),
|
78 |
gr.Number(label="Substitutions"),
|
79 |
gr.Number(label="Insertions"),
|
80 |
gr.Number(label="Deletions")
|
81 |
],
|
82 |
-
title="WER
|
83 |
)
|
84 |
|
85 |
interface.launch()
|
|
|
14 |
gt_index = 0
|
15 |
hyp_index = 0
|
16 |
|
17 |
+
# Process each alignment operation in measures
|
18 |
+
for alignment in measures['ops']:
|
19 |
+
for chunk in alignment:
|
20 |
+
print(chunk)
|
21 |
+
if chunk.type == 'equal':
|
22 |
# Add equal words without highlighting
|
23 |
+
highlighted_hyp.extend(gt_words[chunk.ref_start_idx:chunk.ref_end_idx])
|
24 |
+
gt_index = chunk.ref_end_idx
|
25 |
+
hyp_index = chunk.hyp_end_idx
|
26 |
+
elif chunk.type == 'insert':
|
|
|
27 |
# Highlight inserted words in green
|
28 |
+
highlighted_hyp.append(f'<span style="color:green;">{hyp_words[hyp_index]}</span>')
|
29 |
+
hyp_index += 1
|
30 |
+
elif chunk.type == 'substitute':
|
31 |
+
# Highlight substitutions: hypothesis in purple, ground truth in red
|
32 |
+
highlighted_hyp.append(f'<span style="color:purple;">{hyp_words[hyp_index]}</span>') # Hypothesis word
|
33 |
+
highlighted_hyp.append(f'<span style="color:red; text-decoration:line-through;">{gt_words[gt_index]}</span>') # Ground truth word
|
|
|
34 |
gt_index += 1
|
35 |
hyp_index += 1
|
36 |
+
elif chunk.type == 'delete':
|
37 |
# Highlight deleted words in red with strikethrough
|
38 |
highlighted_hyp.append(f'<span style="color:red; text-decoration:line-through;">{gt_words[gt_index]}</span>')
|
39 |
gt_index += 1
|
|
|
72 |
fn=highlight_errors,
|
73 |
inputs=["text", "text"],
|
74 |
outputs=[
|
75 |
+
gr.HTML(label="Highlighted Transcript with Legend"),
|
76 |
gr.Number(label="Word Error Rate"),
|
77 |
gr.Number(label="Substitutions"),
|
78 |
gr.Number(label="Insertions"),
|
79 |
gr.Number(label="Deletions")
|
80 |
],
|
81 |
+
title="WER Calculator with Error Highlighting and Legend"
|
82 |
)
|
83 |
|
84 |
interface.launch()
|