Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,27 +14,30 @@ def highlight_errors(ground_truth, hypothesis):
|
|
14 |
gt_index = 0
|
15 |
hyp_index = 0
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
20 |
# Add equal words without highlighting
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
25 |
# Highlight inserted words in green
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
30 |
highlighted_hyp.append(f'<span style="color:purple;">{hyp_words[hyp_index]}</span>')
|
31 |
-
highlighted_hyp.append(f'<span style="color:red; text-decoration:line-through;">{gt_words[gt_index]}</span>')
|
32 |
-
gt_index += 1
|
33 |
-
hyp_index += 1
|
34 |
-
elif
|
35 |
# Highlight deleted words in red with strikethrough
|
36 |
highlighted_hyp.append(f'<span style="color:red; text-decoration:line-through;">{gt_words[gt_index]}</span>')
|
37 |
-
gt_index += 1
|
38 |
|
39 |
# Handle any remaining words in hypothesis as insertions
|
40 |
while hyp_index < len(hyp_words):
|
@@ -70,13 +73,13 @@ interface = gr.Interface(
|
|
70 |
fn=highlight_errors,
|
71 |
inputs=["text", "text"],
|
72 |
outputs=[
|
73 |
-
gr.Markdown(label="Highlighted Transcript
|
74 |
gr.Number(label="Word Error Rate"),
|
75 |
gr.Number(label="Substitutions"),
|
76 |
gr.Number(label="Insertions"),
|
77 |
gr.Number(label="Deletions")
|
78 |
],
|
79 |
-
title="WER
|
80 |
)
|
81 |
|
82 |
interface.launch()
|
|
|
14 |
gt_index = 0
|
15 |
hyp_index = 0
|
16 |
|
17 |
+
# Process each chunk of alignment (e.g., equal, insert, substitute, delete)
|
18 |
+
for chunk in measures['ops']:
|
19 |
+
for alignment in chunk:
|
20 |
+
if alignment.type == 'equal':
|
21 |
# Add equal words without highlighting
|
22 |
+
for i in range(alignment.ref_start_idx, alignment.ref_end_idx):
|
23 |
+
highlighted_hyp.append(gt_words[i]) # Add ground truth word as is
|
24 |
+
gt_index = alignment.ref_end_idx
|
25 |
+
hyp_index = alignment.hyp_end_idx
|
26 |
+
elif alignment.type == 'insert':
|
27 |
# Highlight inserted words in green
|
28 |
+
for i in range(alignment.hyp_start_idx, alignment.hyp_end_idx):
|
29 |
+
highlighted_hyp.append(f'<span style="color:green;">{hyp_words[i]}</span>')
|
30 |
+
hyp_index = alignment.hyp_end_idx
|
31 |
+
elif alignment.type == 'sub':
|
32 |
+
# Highlight substituted words in purple and strikethrough for ground truth in red
|
33 |
highlighted_hyp.append(f'<span style="color:purple;">{hyp_words[hyp_index]}</span>')
|
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 alignment.type == 'delete':
|
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
|
41 |
|
42 |
# Handle any remaining words in hypothesis as insertions
|
43 |
while hyp_index < len(hyp_words):
|
|
|
73 |
fn=highlight_errors,
|
74 |
inputs=["text", "text"],
|
75 |
outputs=[
|
76 |
+
gr.Markdown(label="Highlighted Transcript"),
|
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 Analysis"
|
83 |
)
|
84 |
|
85 |
interface.launch()
|