Irpan
commited on
Commit
·
c03de5c
1
Parent(s):
53ffaad
app
Browse files- app.py +1 -1
- requirements.txt +1 -1
- 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.
|
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==
|
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
|
90 |
-
|
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 |
-
|
97 |
-
elif opcode
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
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."""
|