mr2along commited on
Commit
37a3491
·
verified ·
1 Parent(s): 40cb73b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -15
app.py CHANGED
@@ -87,8 +87,7 @@ def compare_texts(reference_text, transcribed_text):
87
  sm = difflib.SequenceMatcher(None, reference_text, transcribed_text)
88
  similarity_score = round(sm.ratio() * 100, 2)
89
 
90
- # Construct HTML output
91
- # html_output = f"<strong>Fidelity Class:</strong> # Tạo output HTML với các mức đánh giá chi tiết hơn
92
  html_output = f"<strong>Fidelity Class:</strong> "
93
  if similarity_score >= 85:
94
  html_output += f"<strong>GOOD (>=85%)</strong><br>"
@@ -98,18 +97,17 @@ def compare_texts(reference_text, transcribed_text):
98
  html_output += f"<strong>NEEDS IMPROVEMENT (50% - 70%)</strong><br>"
99
  else:
100
  html_output += f"<strong>POOR (<50%)</strong><br>"
101
-
102
  html_output += f"<strong>Quality Score:</strong> {similarity_score}%<br>"
103
  html_output += f"<strong>Transcribed Text:</strong> {transcribed_text}<br>"
104
  html_output += "<strong>Word Score List:</strong><br>"
105
 
106
-
107
  # Generate colored word score list
108
  for i, word in enumerate(reference_words):
109
  try:
110
  if word.lower() == transcribed_words[i].lower():
111
  html_output += f'<span style="color: green;">{word}</span> ' # Correct words in green
112
- elif difflib.get_close_matches(word, transcribed_words):
113
  html_output += f'<span style="color: yellow;">{word}</span> ' # Close matches in yellow
114
  else:
115
  # Incorrect words in red
@@ -117,21 +115,20 @@ def compare_texts(reference_text, transcribed_text):
117
  # Create pronunciation audio for the incorrect word
118
  audio_file_path = create_pronunciation_audio(word)
119
  incorrect_words_audios.append((word, audio_file_path))
120
- incorrect_words.append( audio_file_path)
121
  except IndexError:
122
- html_output += f'<span style="color: red;">{word}</span> ' # Words in reference that were not transcribed
 
123
 
124
  # Provide audio for incorrect words
125
  if incorrect_words_audios:
126
  html_output += "<br><strong>Pronunciation for Incorrect Words:</strong><br>"
127
- for word, audio in incorrect_words_audios:
128
- suggestion = difflib.get_close_matches(word, reference_words, n=1)
129
- suggestion_text = f" (Did you mean: <em>{suggestion[0]}</em>?)" if suggestion else ""
130
- html_output += f'{word}: '
131
- html_output += f'<audio controls><source src="{audio}" type="audio/wav">Your browser does not support the audio tag.</audio>{suggestion_text}<br>'
132
-
133
-
134
- return [html_output, incorrect_words]
135
 
136
  # Step 4: Text-to-Speech Function
137
  def text_to_speech(paragraph):
 
87
  sm = difflib.SequenceMatcher(None, reference_text, transcribed_text)
88
  similarity_score = round(sm.ratio() * 100, 2)
89
 
90
+ # Construct HTML output with detailed fidelity class
 
91
  html_output = f"<strong>Fidelity Class:</strong> "
92
  if similarity_score >= 85:
93
  html_output += f"<strong>GOOD (>=85%)</strong><br>"
 
97
  html_output += f"<strong>NEEDS IMPROVEMENT (50% - 70%)</strong><br>"
98
  else:
99
  html_output += f"<strong>POOR (<50%)</strong><br>"
100
+
101
  html_output += f"<strong>Quality Score:</strong> {similarity_score}%<br>"
102
  html_output += f"<strong>Transcribed Text:</strong> {transcribed_text}<br>"
103
  html_output += "<strong>Word Score List:</strong><br>"
104
 
 
105
  # Generate colored word score list
106
  for i, word in enumerate(reference_words):
107
  try:
108
  if word.lower() == transcribed_words[i].lower():
109
  html_output += f'<span style="color: green;">{word}</span> ' # Correct words in green
110
+ elif difflib.get_close_matches(word, [transcribed_words[i]]):
111
  html_output += f'<span style="color: yellow;">{word}</span> ' # Close matches in yellow
112
  else:
113
  # Incorrect words in red
 
115
  # Create pronunciation audio for the incorrect word
116
  audio_file_path = create_pronunciation_audio(word)
117
  incorrect_words_audios.append((word, audio_file_path))
 
118
  except IndexError:
119
+ # Word in reference that was not transcribed
120
+ html_output += f'<span style="color: red;">{word}</span> '
121
 
122
  # Provide audio for incorrect words
123
  if incorrect_words_audios:
124
  html_output += "<br><strong>Pronunciation for Incorrect Words:</strong><br>"
125
+ for word, audio in incorrect_words_audios:
126
+ suggestion = difflib.get_close_matches(word, reference_words, n=1)
127
+ suggestion_text = f" (Did you mean: <em>{suggestion[0]}</em>?)" if suggestion else ""
128
+ html_output += f'{word}: '
129
+ html_output += f'<audio controls><source src="{audio}" type="audio/wav">Your browser does not support the audio tag.</audio>{suggestion_text}<br>'
130
+
131
+ return [html_output, [audio for _, audio in incorrect_words_audios]]
 
132
 
133
  # Step 4: Text-to-Speech Function
134
  def text_to_speech(paragraph):