Spaces:
Runtime error
Runtime error
Commit
·
bb15fb2
1
Parent(s):
10dba2f
small fixes
Browse files
app.py
CHANGED
|
@@ -60,11 +60,7 @@ def process_uploaded_file(
|
|
| 60 |
in_filename: str,
|
| 61 |
):
|
| 62 |
if in_filename is None or in_filename == "":
|
| 63 |
-
return ""
|
| 64 |
-
"Please first upload a file and then click "
|
| 65 |
-
'the button "submit for recognition"',
|
| 66 |
-
"result_item_error",
|
| 67 |
-
)
|
| 68 |
|
| 69 |
logging.info(f"Processing uploaded file: {in_filename}")
|
| 70 |
try:
|
|
@@ -77,7 +73,7 @@ def process_uploaded_file(
|
|
| 77 |
)
|
| 78 |
except Exception as e:
|
| 79 |
logging.info(str(e))
|
| 80 |
-
return
|
| 81 |
|
| 82 |
|
| 83 |
def process_microphone(
|
|
@@ -88,11 +84,10 @@ def process_microphone(
|
|
| 88 |
in_filename: str,
|
| 89 |
):
|
| 90 |
if in_filename is None or in_filename == "":
|
| 91 |
-
return
|
| 92 |
"Please first click 'Record from microphone', speak, "
|
| 93 |
"click 'Stop recording', and then "
|
| 94 |
-
"click the button 'submit for recognition'"
|
| 95 |
-
"result_item_error",
|
| 96 |
)
|
| 97 |
|
| 98 |
logging.info(f"Processing microphone: {in_filename}")
|
|
@@ -106,7 +101,7 @@ def process_microphone(
|
|
| 106 |
)
|
| 107 |
except Exception as e:
|
| 108 |
logging.info(str(e))
|
| 109 |
-
return
|
| 110 |
|
| 111 |
|
| 112 |
@torch.no_grad()
|
|
@@ -153,16 +148,20 @@ def process(
|
|
| 153 |
logging.info(f"Finished at {date_time} s. Elapsed: {end - start: .3f} s")
|
| 154 |
|
| 155 |
info = f"""
|
| 156 |
-
Result: {text}
|
| 157 |
Wave duration : {duration: .3f} s <br/>
|
| 158 |
Processing time: {end - start: .3f} s <br/>
|
| 159 |
RTF: {end - start: .3f}/{duration: .3f} = {rtf:.3f} <br/>
|
| 160 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
logging.info(info)
|
| 163 |
logging.info(f"\nrepo_id: {repo_id}\nhyp: {text}")
|
| 164 |
|
| 165 |
-
return
|
| 166 |
|
| 167 |
|
| 168 |
title = "# Automatic Speech Recognition with Next-gen Kaldi"
|
|
@@ -246,7 +245,7 @@ with demo:
|
|
| 246 |
label="Upload from disk",
|
| 247 |
)
|
| 248 |
upload_button = gr.Button("Submit for recognition")
|
| 249 |
-
|
| 250 |
|
| 251 |
gr.Examples(
|
| 252 |
examples=examples,
|
|
@@ -257,7 +256,7 @@ with demo:
|
|
| 257 |
num_active_paths_slider,
|
| 258 |
uploaded_file,
|
| 259 |
],
|
| 260 |
-
outputs=[
|
| 261 |
fn=process_uploaded_file,
|
| 262 |
)
|
| 263 |
|
|
@@ -270,7 +269,7 @@ with demo:
|
|
| 270 |
)
|
| 271 |
|
| 272 |
record_button = gr.Button("Submit for recognition")
|
| 273 |
-
|
| 274 |
|
| 275 |
gr.Examples(
|
| 276 |
examples=examples,
|
|
@@ -281,7 +280,7 @@ with demo:
|
|
| 281 |
num_active_paths_slider,
|
| 282 |
microphone,
|
| 283 |
],
|
| 284 |
-
outputs=[
|
| 285 |
fn=process_microphone,
|
| 286 |
)
|
| 287 |
|
|
@@ -294,7 +293,7 @@ with demo:
|
|
| 294 |
num_active_paths_slider,
|
| 295 |
uploaded_file,
|
| 296 |
],
|
| 297 |
-
outputs=[
|
| 298 |
)
|
| 299 |
|
| 300 |
record_button.click(
|
|
@@ -306,7 +305,7 @@ with demo:
|
|
| 306 |
num_active_paths_slider,
|
| 307 |
microphone,
|
| 308 |
],
|
| 309 |
-
outputs=[
|
| 310 |
)
|
| 311 |
gr.Markdown(description)
|
| 312 |
|
|
|
|
| 60 |
in_filename: str,
|
| 61 |
):
|
| 62 |
if in_filename is None or in_filename == "":
|
| 63 |
+
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
logging.info(f"Processing uploaded file: {in_filename}")
|
| 66 |
try:
|
|
|
|
| 73 |
)
|
| 74 |
except Exception as e:
|
| 75 |
logging.info(str(e))
|
| 76 |
+
return str(e)
|
| 77 |
|
| 78 |
|
| 79 |
def process_microphone(
|
|
|
|
| 84 |
in_filename: str,
|
| 85 |
):
|
| 86 |
if in_filename is None or in_filename == "":
|
| 87 |
+
return (
|
| 88 |
"Please first click 'Record from microphone', speak, "
|
| 89 |
"click 'Stop recording', and then "
|
| 90 |
+
"click the button 'submit for recognition'"
|
|
|
|
| 91 |
)
|
| 92 |
|
| 93 |
logging.info(f"Processing microphone: {in_filename}")
|
|
|
|
| 101 |
)
|
| 102 |
except Exception as e:
|
| 103 |
logging.info(str(e))
|
| 104 |
+
return str(e)
|
| 105 |
|
| 106 |
|
| 107 |
@torch.no_grad()
|
|
|
|
| 148 |
logging.info(f"Finished at {date_time} s. Elapsed: {end - start: .3f} s")
|
| 149 |
|
| 150 |
info = f"""
|
|
|
|
| 151 |
Wave duration : {duration: .3f} s <br/>
|
| 152 |
Processing time: {end - start: .3f} s <br/>
|
| 153 |
RTF: {end - start: .3f}/{duration: .3f} = {rtf:.3f} <br/>
|
| 154 |
"""
|
| 155 |
+
if rtf > 1:
|
| 156 |
+
info += (
|
| 157 |
+
"<br/>We are loading the model for the first run. "
|
| 158 |
+
"Please run again to measure the real RTF.<br/>"
|
| 159 |
+
)
|
| 160 |
|
| 161 |
logging.info(info)
|
| 162 |
logging.info(f"\nrepo_id: {repo_id}\nhyp: {text}")
|
| 163 |
|
| 164 |
+
return text
|
| 165 |
|
| 166 |
|
| 167 |
title = "# Automatic Speech Recognition with Next-gen Kaldi"
|
|
|
|
| 245 |
label="Upload from disk",
|
| 246 |
)
|
| 247 |
upload_button = gr.Button("Submit for recognition")
|
| 248 |
+
uploaded_output = gr.Textbox(label="Recognized speech from uploaded file")
|
| 249 |
|
| 250 |
gr.Examples(
|
| 251 |
examples=examples,
|
|
|
|
| 256 |
num_active_paths_slider,
|
| 257 |
uploaded_file,
|
| 258 |
],
|
| 259 |
+
outputs=[uploaded_output],
|
| 260 |
fn=process_uploaded_file,
|
| 261 |
)
|
| 262 |
|
|
|
|
| 269 |
)
|
| 270 |
|
| 271 |
record_button = gr.Button("Submit for recognition")
|
| 272 |
+
recorded_output = gr.Textbox(label="Recognized speech from recordings")
|
| 273 |
|
| 274 |
gr.Examples(
|
| 275 |
examples=examples,
|
|
|
|
| 280 |
num_active_paths_slider,
|
| 281 |
microphone,
|
| 282 |
],
|
| 283 |
+
outputs=[recorded_output],
|
| 284 |
fn=process_microphone,
|
| 285 |
)
|
| 286 |
|
|
|
|
| 293 |
num_active_paths_slider,
|
| 294 |
uploaded_file,
|
| 295 |
],
|
| 296 |
+
outputs=[uploaded_output],
|
| 297 |
)
|
| 298 |
|
| 299 |
record_button.click(
|
|
|
|
| 305 |
num_active_paths_slider,
|
| 306 |
microphone,
|
| 307 |
],
|
| 308 |
+
outputs=[recorded_output],
|
| 309 |
)
|
| 310 |
gr.Markdown(description)
|
| 311 |
|