Commit
·
15cb938
1
Parent(s):
b41531e
support url
Browse files
app.py
CHANGED
|
@@ -133,6 +133,24 @@ def process_uploaded_audio_file(
|
|
| 133 |
return process(language, repo_id, add_punctuation, in_filename)
|
| 134 |
|
| 135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
def process(language: str, repo_id: str, add_punctuation: str, in_filename: str):
|
| 137 |
logging.info(f"add_punctuation: {add_punctuation}")
|
| 138 |
recognizer = get_pretrained_model(repo_id)
|
|
@@ -145,6 +163,7 @@ def process(language: str, repo_id: str, add_punctuation: str, in_filename: str)
|
|
| 145 |
or "korean" in repo_id
|
| 146 |
or "vosk-model" in repo_id
|
| 147 |
or "asr-gigaspeech2-th-zipformer" in repo_id
|
|
|
|
| 148 |
):
|
| 149 |
add_punctuation = "No"
|
| 150 |
|
|
@@ -245,6 +264,32 @@ with demo:
|
|
| 245 |
label="Recognized speech from uploaded audio file (all in one)"
|
| 246 |
)
|
| 247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
upload_video_button.click(
|
| 249 |
process_uploaded_video_file,
|
| 250 |
inputs=[
|
|
@@ -278,6 +323,22 @@ with demo:
|
|
| 278 |
],
|
| 279 |
)
|
| 280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
gr.Markdown(description)
|
| 282 |
|
| 283 |
if __name__ == "__main__":
|
|
|
|
| 133 |
return process(language, repo_id, add_punctuation, in_filename)
|
| 134 |
|
| 135 |
|
| 136 |
+
def process_url(
|
| 137 |
+
language: str,
|
| 138 |
+
repo_id: str,
|
| 139 |
+
add_punctuation: str,
|
| 140 |
+
url: str,
|
| 141 |
+
):
|
| 142 |
+
MyPrint(f"Processing URL: {url}")
|
| 143 |
+
with tempfile.NamedTemporaryFile() as f:
|
| 144 |
+
urllib.request.urlretrieve(url, f.name)
|
| 145 |
+
|
| 146 |
+
return process(
|
| 147 |
+
language,
|
| 148 |
+
repo_id,
|
| 149 |
+
add_punctuation,
|
| 150 |
+
in_filename,
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
def process(language: str, repo_id: str, add_punctuation: str, in_filename: str):
|
| 155 |
logging.info(f"add_punctuation: {add_punctuation}")
|
| 156 |
recognizer = get_pretrained_model(repo_id)
|
|
|
|
| 163 |
or "korean" in repo_id
|
| 164 |
or "vosk-model" in repo_id
|
| 165 |
or "asr-gigaspeech2-th-zipformer" in repo_id
|
| 166 |
+
or "parakeet-tdt-0.6b-v" in repo_id
|
| 167 |
):
|
| 168 |
add_punctuation = "No"
|
| 169 |
|
|
|
|
| 264 |
label="Recognized speech from uploaded audio file (all in one)"
|
| 265 |
)
|
| 266 |
|
| 267 |
+
with gr.TabItem("Audio from URL"):
|
| 268 |
+
url_textbox = gr.Textbox(
|
| 269 |
+
max_lines=1,
|
| 270 |
+
placeholder="URL to an audio file",
|
| 271 |
+
label="URL",
|
| 272 |
+
interactive=True,
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
+
url_button = gr.Button("Submit for recognition")
|
| 276 |
+
|
| 277 |
+
output_srt_file_audio_url = gr.File(
|
| 278 |
+
label="Generated subtitles", show_label=True
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
output_srt_file_audio_url = gr.File(
|
| 282 |
+
label="Generated subtitles", show_label=True
|
| 283 |
+
)
|
| 284 |
+
|
| 285 |
+
output_info_audio_url = gr.HTML(label="Info")
|
| 286 |
+
output_textbox_audio_url = gr.Textbox(
|
| 287 |
+
label="Recognized speech from audio URL (srt format)"
|
| 288 |
+
)
|
| 289 |
+
all_output_textbox_audio_url = gr.Textbox(
|
| 290 |
+
label="Recognized speech from audio URL (all in one)"
|
| 291 |
+
)
|
| 292 |
+
|
| 293 |
upload_video_button.click(
|
| 294 |
process_uploaded_video_file,
|
| 295 |
inputs=[
|
|
|
|
| 323 |
],
|
| 324 |
)
|
| 325 |
|
| 326 |
+
url_button.click(
|
| 327 |
+
process_url,
|
| 328 |
+
inputs=[
|
| 329 |
+
language_radio,
|
| 330 |
+
model_dropdown,
|
| 331 |
+
punct_radio,
|
| 332 |
+
url_textbox,
|
| 333 |
+
],
|
| 334 |
+
outputs=[
|
| 335 |
+
output_srt_file_audio_url,
|
| 336 |
+
output_info_audio_url,
|
| 337 |
+
output_textbox_audio_url,
|
| 338 |
+
all_output_textbox_audio_url,
|
| 339 |
+
],
|
| 340 |
+
)
|
| 341 |
+
|
| 342 |
gr.Markdown(description)
|
| 343 |
|
| 344 |
if __name__ == "__main__":
|