Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -32,32 +32,25 @@ def compare_texts(reference_text, transcribed_text):
|
|
32 |
sm = difflib.SequenceMatcher(None, reference_text, transcribed_text)
|
33 |
similarity_score = round(sm.ratio() * 100, 2)
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
for i, word in enumerate(reference_words):
|
36 |
try:
|
37 |
if word.lower() == transcribed_words[i].lower():
|
38 |
-
|
|
|
|
|
39 |
else:
|
40 |
-
|
41 |
except IndexError:
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
output = {
|
47 |
-
"quota_remaining": -1,
|
48 |
-
"reference_text_from_application": reference_text,
|
49 |
-
"status": "success",
|
50 |
-
"text_score": {
|
51 |
-
"fidelity_class": fidelity_class,
|
52 |
-
"quality_score": similarity_score,
|
53 |
-
"text": reference_text,
|
54 |
-
"transcribedText": transcribed_text,
|
55 |
-
"word_score_list": word_scores
|
56 |
-
},
|
57 |
-
"version": "1.1"
|
58 |
-
}
|
59 |
-
|
60 |
-
return output
|
61 |
|
62 |
# Step 3: Text-to-Speech Function
|
63 |
def text_to_speech(paragraph):
|
@@ -83,7 +76,7 @@ interface = gr.Interface(
|
|
83 |
gr.Textbox(lines=5, label="Input Paragraph"),
|
84 |
gr.Audio(type="filepath", label="Record Audio")
|
85 |
],
|
86 |
-
outputs="
|
87 |
title="Speech Recognition Comparison",
|
88 |
description="Input a paragraph, record your audio, and compare the transcription to the original text."
|
89 |
)
|
|
|
32 |
sm = difflib.SequenceMatcher(None, reference_text, transcribed_text)
|
33 |
similarity_score = round(sm.ratio() * 100, 2)
|
34 |
|
35 |
+
# Construct HTML output
|
36 |
+
html_output = f"<strong>Fidelity Class:</strong> {'CORRECT' if similarity_score > 50 else 'INCORRECT'}<br>"
|
37 |
+
html_output += f"<strong>Quality Score:</strong> {similarity_score}<br>"
|
38 |
+
html_output += f"<strong>Transcribed Text:</strong> {transcribed_text}<br>"
|
39 |
+
html_output += "<strong>Word Score List:</strong><br>"
|
40 |
+
|
41 |
+
# Generate colored word score list
|
42 |
for i, word in enumerate(reference_words):
|
43 |
try:
|
44 |
if word.lower() == transcribed_words[i].lower():
|
45 |
+
html_output += f'<span style="color: green;">{word}</span> ' # Correct words in green
|
46 |
+
elif difflib.get_close_matches(word, transcribed_words):
|
47 |
+
html_output += f'<span style="color: yellow;">{word}</span> ' # Close matches in yellow
|
48 |
else:
|
49 |
+
html_output += f'<span style="color: red;">{word}</span> ' # Incorrect words in red
|
50 |
except IndexError:
|
51 |
+
html_output += f'<span style="color: red;">{word}</span> ' # Words in reference that were not transcribed
|
52 |
+
|
53 |
+
return html_output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
# Step 3: Text-to-Speech Function
|
56 |
def text_to_speech(paragraph):
|
|
|
76 |
gr.Textbox(lines=5, label="Input Paragraph"),
|
77 |
gr.Audio(type="filepath", label="Record Audio")
|
78 |
],
|
79 |
+
outputs="html",
|
80 |
title="Speech Recognition Comparison",
|
81 |
description="Input a paragraph, record your audio, and compare the transcription to the original text."
|
82 |
)
|