RasmusToivanen
commited on
Commit
•
28b63dc
1
Parent(s):
3dd368d
add option for microphone input
Browse files
app.py
CHANGED
@@ -24,13 +24,17 @@ pipe_1b = pipeline(model="Finnish-NLP/wav2vec2-xlsr-1b-finnish-lm-v2",chunk_leng
|
|
24 |
|
25 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
26 |
model_checkpoint = 'Finnish-NLP/t5x-small-nl24-finnish'
|
27 |
-
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint, use_auth_token=
|
28 |
-
model = AutoModelForSeq2SeqLM.from_pretrained('Finnish-NLP/case_correction_model', from_flax=False, torch_dtype=torch.float32, use_auth_token=
|
29 |
|
30 |
|
31 |
# define speech-to-text function
|
32 |
-
def asr_transcript(audio, model_params):
|
33 |
|
|
|
|
|
|
|
|
|
34 |
text = ""
|
35 |
|
36 |
if audio:
|
@@ -50,11 +54,8 @@ gradio_ui = gr.Interface(
|
|
50 |
fn=asr_transcript,
|
51 |
title="Finnish Automatic Speech-Recognition",
|
52 |
description="Upload an audio clip, and let AI do the hard work of transcribing",
|
53 |
-
inputs=[gr.inputs.Audio(label="Upload Audio File", type="file"), gr.inputs.Dropdown(choices=["300 million", "1 billion"], type="value", default="1 billion", label="Select speech recognition model parameter amount", optional=False)],
|
54 |
outputs=[gr.outputs.Textbox(label="Recognized speech"),gr.outputs.Textbox(label="Recognized speech with case correction and punctuation")]
|
55 |
)
|
56 |
|
57 |
-
gradio_ui.launch()
|
58 |
-
|
59 |
-
|
60 |
-
os.environ.get('hf_token')
|
|
|
24 |
|
25 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
26 |
model_checkpoint = 'Finnish-NLP/t5x-small-nl24-finnish'
|
27 |
+
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint, use_auth_token=True)
|
28 |
+
model = AutoModelForSeq2SeqLM.from_pretrained('Finnish-NLP/case_correction_model', from_flax=False, torch_dtype=torch.float32, use_auth_token=True).to(device)
|
29 |
|
30 |
|
31 |
# define speech-to-text function
|
32 |
+
def asr_transcript(audio, audio_microphone, model_params):
|
33 |
|
34 |
+
audio = audio_microphone if audio_microphone else audio
|
35 |
+
|
36 |
+
if audio == None and audio_microphone == None:
|
37 |
+
return "Please provide audio by uploading file or by recording audio with microphone by pressing Record (And allow usage of microphone)", "Please provide audio by uploading file or by recording audio with microphone by pressing Record (And allow usage of microphone)"
|
38 |
text = ""
|
39 |
|
40 |
if audio:
|
|
|
54 |
fn=asr_transcript,
|
55 |
title="Finnish Automatic Speech-Recognition",
|
56 |
description="Upload an audio clip, and let AI do the hard work of transcribing",
|
57 |
+
inputs=[gr.inputs.Audio(label="Upload Audio File", type="file", optional=True), gr.inputs.Audio(source="microphone", type="file", optional=True, label="Record"), gr.inputs.Dropdown(choices=["300 million", "1 billion"], type="value", default="1 billion", label="Select speech recognition model parameter amount", optional=False)],
|
58 |
outputs=[gr.outputs.Textbox(label="Recognized speech"),gr.outputs.Textbox(label="Recognized speech with case correction and punctuation")]
|
59 |
)
|
60 |
|
61 |
+
gradio_ui.launch()
|
|
|
|
|
|