Spaces:
Running
Running
alessandro trinca tornidor
commited on
Commit
·
c0961d5
1
Parent(s):
333afb5
feat: limit the number of recognized words that can be selected
Browse files
app.py
CHANGED
@@ -127,10 +127,24 @@ with gr.Blocks(css=css, head=js.head_driver_tour) as gradio_app:
|
|
127 |
btn_recognize_speech_accuracy = gr.Button(value="Recognize speech accuracy", elem_id="btn-recognize-speech-accuracy-id-element")
|
128 |
with gr.Row():
|
129 |
with gr.Column(scale=1, min_width=50):
|
130 |
-
num_tot_recognized_words = gr.Number(label="Total recognized words", visible=True, minimum=0)
|
131 |
with gr.Column(scale=1, min_width=50):
|
132 |
-
num_selected_recognized_words = gr.Number(label="Recognized word index", visible=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
with gr.Column(scale=2, min_width=100):
|
|
|
134 |
audio_splitted_student_recording_stt = gr.Audio(
|
135 |
label="Splitted Speech-toText audio output",
|
136 |
type="filepath",
|
@@ -156,6 +170,7 @@ with gr.Blocks(css=css, head=js.head_driver_tour) as gradio_app:
|
|
156 |
|
157 |
def get_updated_score_by_language(text: str, audio_rec: str | Path, lang: str, score_de: float, score_en: float):
|
158 |
_transcribed_text, _letter_correctness, _pronunciation_accuracy, _recording_ipa, _ideal_ipa, _num_tot_recognized_words, _res = lambdaSpeechToScore.get_speech_to_score_tuple(text, audio_rec, lang, remove_random_file=False)
|
|
|
159 |
output = {
|
160 |
text_transcribed_hidden: _transcribed_text,
|
161 |
text_letter_correctness: _letter_correctness,
|
@@ -164,6 +179,7 @@ with gr.Blocks(css=css, head=js.head_driver_tour) as gradio_app:
|
|
164 |
text_ideal_ipa: _ideal_ipa,
|
165 |
text_raw_json_output_hidden: _res,
|
166 |
num_tot_recognized_words: _num_tot_recognized_words,
|
|
|
167 |
}
|
168 |
match lang:
|
169 |
case "de":
|
@@ -193,7 +209,8 @@ with gr.Blocks(css=css, head=js.head_driver_tour) as gradio_app:
|
|
193 |
text_raw_json_output_hidden,
|
194 |
number_score_de,
|
195 |
number_score_en,
|
196 |
-
num_tot_recognized_words
|
|
|
197 |
],
|
198 |
)
|
199 |
btn_run_tts.click(fn=None, inputs=[text_student_transcription, radio_language], outputs=audio_tts, js=js.js_play_audio)
|
|
|
127 |
btn_recognize_speech_accuracy = gr.Button(value="Recognize speech accuracy", elem_id="btn-recognize-speech-accuracy-id-element")
|
128 |
with gr.Row():
|
129 |
with gr.Column(scale=1, min_width=50):
|
130 |
+
num_tot_recognized_words = gr.Number(label="Total recognized words", visible=True, minimum=0, interactive=False)
|
131 |
with gr.Column(scale=1, min_width=50):
|
132 |
+
num_selected_recognized_words = gr.Number(label="Recognized word index", visible=True, minimum=0, value=0)
|
133 |
+
|
134 |
+
def change_max_selected_words(n):
|
135 |
+
app_logger.info(f"change_max_selected_words: {n} ...")
|
136 |
+
app_logger.info(f"num_selected_recognized_words.maximum, pre: {num_selected_recognized_words.maximum} ...")
|
137 |
+
new_num_selected_recognized_words = gr.Number(label=f"Recognized word index, max {n}!", visible=True, value=0, minimum=0, maximum=n)
|
138 |
+
app_logger.info(f"num_selected_recognized_words.maximum, post: {num_selected_recognized_words.maximum} ...")
|
139 |
+
return new_num_selected_recognized_words
|
140 |
+
|
141 |
+
num_tot_recognized_words.change(
|
142 |
+
change_max_selected_words,
|
143 |
+
inputs=[num_tot_recognized_words],
|
144 |
+
outputs=[num_selected_recognized_words],
|
145 |
+
)
|
146 |
with gr.Column(scale=2, min_width=100):
|
147 |
+
# todo: use https://www.gradio.app/docs/gradio/multimodaltextbox
|
148 |
audio_splitted_student_recording_stt = gr.Audio(
|
149 |
label="Splitted Speech-toText audio output",
|
150 |
type="filepath",
|
|
|
170 |
|
171 |
def get_updated_score_by_language(text: str, audio_rec: str | Path, lang: str, score_de: float, score_en: float):
|
172 |
_transcribed_text, _letter_correctness, _pronunciation_accuracy, _recording_ipa, _ideal_ipa, _num_tot_recognized_words, _res = lambdaSpeechToScore.get_speech_to_score_tuple(text, audio_rec, lang, remove_random_file=False)
|
173 |
+
new_num_selected_recognized_words = gr.Number(label="Recognized word index", visible=True, value=0)
|
174 |
output = {
|
175 |
text_transcribed_hidden: _transcribed_text,
|
176 |
text_letter_correctness: _letter_correctness,
|
|
|
179 |
text_ideal_ipa: _ideal_ipa,
|
180 |
text_raw_json_output_hidden: _res,
|
181 |
num_tot_recognized_words: _num_tot_recognized_words,
|
182 |
+
num_selected_recognized_words: new_num_selected_recognized_words
|
183 |
}
|
184 |
match lang:
|
185 |
case "de":
|
|
|
209 |
text_raw_json_output_hidden,
|
210 |
number_score_de,
|
211 |
number_score_en,
|
212 |
+
num_tot_recognized_words,
|
213 |
+
num_selected_recognized_words
|
214 |
],
|
215 |
)
|
216 |
btn_run_tts.click(fn=None, inputs=[text_student_transcription, radio_language], outputs=audio_tts, js=js.js_play_audio)
|