Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,34 @@
|
|
1 |
-
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
import numpy as np
|
4 |
-
|
5 |
-
asr_model = "distil-whisper/distil-medium.en"
|
6 |
-
|
7 |
-
asr_pipe = pipeline("automatic-speech-recognition", model=asr_model)
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
stream = np.concatenate([stream, y])
|
16 |
-
else:
|
17 |
-
stream = y
|
18 |
-
return stream, asr_pipe({"sampling_rate": sr, "raw": stream})["text"]
|
19 |
|
20 |
demo = gr.Blocks()
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
"state", gr.Audio(sources=["microphone"], streaming=True)],
|
27 |
-
outputs = ["state", "text"],
|
28 |
-
theme="huggingface",
|
29 |
-
title="Whisper & BERT demo - Intent Classification",
|
30 |
-
description=(
|
31 |
-
"Transcribe audio inputs with Whisper ASR model and detect intention from the text. Use BERT NLP model to classify the intention as one of the commands to command a light."
|
32 |
-
),
|
33 |
-
live=True,
|
34 |
)
|
35 |
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
model_id = "sanchit-gandhi/whisper-small-dv" # update with your model id
|
4 |
+
pipe = pipeline("automatic-speech-recognition", model=model_id)
|
5 |
+
|
6 |
+
def transcribe_speech(filepath):
|
7 |
+
output = pipe(
|
8 |
+
filepath,
|
9 |
+
max_new_tokens=256,
|
10 |
+
generate_kwargs={
|
11 |
+
"task": "transcribe",
|
12 |
+
"language": "sinhalese",
|
13 |
+
}, # update with the language you've fine-tuned on
|
14 |
+
chunk_length_s=30,
|
15 |
+
batch_size=8,
|
16 |
+
)
|
17 |
+
return output["text"]
|
18 |
|
19 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
20 |
|
21 |
demo = gr.Blocks()
|
22 |
|
23 |
+
mic_transcribe = gr.Interface(
|
24 |
+
fn=transcribe_speech,
|
25 |
+
inputs=gr.Audio(sources="microphone", type="filepath"),
|
26 |
+
outputs=gr.outputs.Textbox(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
)
|
28 |
|
29 |
+
with demo:
|
30 |
+
gr.TabbedInterface(
|
31 |
+
[mic_transcribe],
|
32 |
+
["Transcribe Microphone"],
|
33 |
+
|
34 |
+
demo.launch(debug=True)
|