Irpan commited on
Commit
c03de5c
·
1 Parent(s): 53ffaad
Files changed (3) hide show
  1. app.py +1 -1
  2. requirements.txt +1 -1
  3. util.py +9 -11
app.py CHANGED
@@ -67,7 +67,7 @@ with gr.Blocks() as app:
67
 
68
  with gr.Group():
69
  with gr.Row():
70
- match_box = gr.html(
71
  label="Phonetic Match",
72
  )
73
  with gr.Row():
 
67
 
68
  with gr.Group():
69
  with gr.Row():
70
+ match_box = gr.Markdown(
71
  label="Phonetic Match",
72
  )
73
  with gr.Row():
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- gradio==5.8.0
2
  torch
3
  torchaudio
4
  transformers
 
1
+ gradio==2.9.1
2
  torch
3
  torchaudio
4
  transformers
util.py CHANGED
@@ -86,22 +86,20 @@ def calculate_pronunciation_accuracy(reference_text, output_text, language_code=
86
  # Convert to percentage
87
  pronunciation_accuracy = match_ratio * 100
88
 
89
- # Generate HTML for comparison
90
- comparison_html = ""
91
  for opcode, i1, i2, j1, j2 in matcher.get_opcodes():
92
  ref_segment = reference_ipa[i1:i2]
93
  out_segment = output_ipa[j1:j2]
94
 
95
  if opcode == 'equal': # Matching characters
96
- comparison_html += f'<span style="color: green">{ref_segment}</span>'
97
- elif opcode == 'replace': # Mismatched characters
98
- comparison_html += f'<span style="color: red">{ref_segment}</span>'
99
- elif opcode == 'delete': # Characters in reference but not in output
100
- comparison_html += f'<span style="color: red">{ref_segment}</span>'
101
- elif opcode == 'insert': # Characters in output but not in reference
102
- comparison_html += f'<span style="color: red">{out_segment}</span>'
103
-
104
- return reference_ipa, output_ipa, comparison_html, pronunciation_accuracy
105
 
106
  def remove_punctuation(text):
107
  """Helper function to remove punctuation from text."""
 
86
  # Convert to percentage
87
  pronunciation_accuracy = match_ratio * 100
88
 
89
+ # Generate Markdown-compatible styled text
90
+ comparison_md = ""
91
  for opcode, i1, i2, j1, j2 in matcher.get_opcodes():
92
  ref_segment = reference_ipa[i1:i2]
93
  out_segment = output_ipa[j1:j2]
94
 
95
  if opcode == 'equal': # Matching characters
96
+ comparison_md += f'<span style="color: green;">{ref_segment}</span>'
97
+ elif opcode in ['replace', 'delete', 'insert']: # Mismatched or missing
98
+ comparison_md += f'<span style="color: red;">{ref_segment}</span>'
99
+
100
+ comparison_md = f"<div>{comparison_md}</div>"
101
+
102
+ return reference_ipa, output_ipa, comparison_md, pronunciation_accuracy
 
 
103
 
104
  def remove_punctuation(text):
105
  """Helper function to remove punctuation from text."""