janaab commited on
Commit
d1aae39
·
verified ·
1 Parent(s): 0b203ab

Working prototype

Browse files
Files changed (1) hide show
  1. app.py +18 -19
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 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
@@ -73,13 +72,13 @@ interface = gr.Interface(
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()
 
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()